Add actor types to the profiles and clean up the UI

This commit is contained in:
Paul Frazee 2022-11-05 11:58:48 -05:00
parent 3f730f1173
commit 60b1c53d85
4 changed files with 217 additions and 140 deletions

View file

@ -3,19 +3,21 @@ import {RootStoreModel} from './root-store'
import {ProfileViewModel} from './profile-view'
import {FeedModel} from './feed-view'
export const SECTION_IDS = {
POSTS: 0,
BADGES: 1,
export enum Sections {
Posts = 'Posts',
Scenes = 'Scenes',
Trending = 'Trending',
Members = 'Members',
}
const USER_SELECTOR_ITEMS = [Sections.Posts, Sections.Scenes]
const SCENE_SELECTOR_ITEMS = [Sections.Trending, Sections.Members]
export interface ProfileUiParams {
user: string
}
export class ProfileUiModel {
// constants
static SELECTOR_ITEMS = ['Posts', 'Scenes']
// data
profile: ProfileViewModel
feed: FeedModel
@ -43,7 +45,10 @@ export class ProfileUiModel {
}
get currentView(): FeedModel {
if (this.selectedViewIndex === SECTION_IDS.POSTS) {
if (
this.selectedView === Sections.Posts ||
this.selectedView === Sections.Trending
) {
return this.feed
}
throw new Error(`Invalid selector value: ${this.selectedViewIndex}`)
@ -58,6 +63,28 @@ export class ProfileUiModel {
return this.profile.isRefreshing || this.currentView.isRefreshing
}
get isUser() {
return this.profile.isUser
}
get isScene() {
return this.profile.isScene
}
get selectorItems() {
if (this.isUser) {
return USER_SELECTOR_ITEMS
} else if (this.isScene) {
return SCENE_SELECTOR_ITEMS
} else {
return USER_SELECTOR_ITEMS
}
}
get selectedView() {
return this.selectorItems[this.selectedViewIndex]
}
// public api
// =

View file

@ -4,6 +4,9 @@ import * as Profile from '../../third-party/api/src/client/types/app/bsky/actor/
import {RootStoreModel} from './root-store'
import * as apilib from '../lib/api'
export const ACTOR_TYPE_USER = 'app.bsky.system.actorUser'
export const ACTOR_TYPE_SCENE = 'app.bsky.system.actorScene'
export class ProfileViewMyStateModel {
follow?: string
@ -23,6 +26,7 @@ export class ProfileViewModel {
// data
did: string = ''
handle: string = ''
actorType = ACTOR_TYPE_USER
displayName?: string
description?: string
followersCount: number = 0
@ -57,6 +61,14 @@ export class ProfileViewModel {
return this.hasLoaded && !this.hasContent
}
get isUser() {
return this.actorType === ACTOR_TYPE_USER
}
get isScene() {
return this.actorType === ACTOR_TYPE_SCENE
}
// public api
// =