diff options
author | Ansh <anshnanda10@gmail.com> | 2023-06-27 08:11:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-27 10:11:05 -0500 |
commit | a8bbaa06c7266c73f6a71b5e9223c11c96995947 (patch) | |
tree | bae43bbbd724ceb513aa29339273418623b8d7f4 /src/state/models/feeds/posts-slice.ts | |
parent | bfaa6d73f37f251259c521befa9e9ee8ea877560 (diff) | |
download | voidsky-a8bbaa06c7266c73f6a71b5e9223c11c96995947.tar.zst |
[APP-705] Metrics revamp pt2 (#896)
* export track function from analytics.tsx * fix create account tracking * fix tracking sign in * add custom feed events * fix type errors * refactor create post event * add profile follow & unfollow events * refactor PostsFeedSliceModel into its own file * refactor PostThreadItemModel into its own file * reorganize code a lil bit * refactor post-thread-item to use post-feed-item model under the hood * add post events * add post reply tracking * track custom feed load more * track list subscribe and unsubscribe
Diffstat (limited to 'src/state/models/feeds/posts-slice.ts')
-rw-r--r-- | src/state/models/feeds/posts-slice.ts | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/state/models/feeds/posts-slice.ts b/src/state/models/feeds/posts-slice.ts new file mode 100644 index 000000000..239bc5b6a --- /dev/null +++ b/src/state/models/feeds/posts-slice.ts @@ -0,0 +1,78 @@ +import {makeAutoObservable} from 'mobx' +import {RootStoreModel} from '../root-store' +import {FeedViewPostsSlice} from 'lib/api/feed-manip' +import {mergePostModerations} from 'lib/labeling/helpers' +import {PostsFeedItemModel} from './post' + +let _idCounter = 0 + +export class PostsFeedSliceModel { + // ui state + _reactKey: string = '' + + // data + items: PostsFeedItemModel[] = [] + + constructor( + public rootStore: RootStoreModel, + reactKey: string, + slice: FeedViewPostsSlice, + ) { + this._reactKey = reactKey + for (const item of slice.items) { + this.items.push( + new PostsFeedItemModel(rootStore, `slice-${_idCounter++}`, item), + ) + } + makeAutoObservable(this, {rootStore: false}) + } + + get uri() { + if (this.isReply) { + return this.items[1].post.uri + } + return this.items[0].post.uri + } + + get isThread() { + return ( + this.items.length > 1 && + this.items.every( + item => item.post.author.did === this.items[0].post.author.did, + ) + ) + } + + get isReply() { + return this.items.length > 1 && !this.isThread + } + + get rootItem() { + if (this.isReply) { + return this.items[1] + } + return this.items[0] + } + + get moderation() { + return mergePostModerations(this.items.map(item => item.moderation)) + } + + containsUri(uri: string) { + return !!this.items.find(item => item.post.uri === uri) + } + + isThreadParentAt(i: number) { + if (this.items.length === 1) { + return false + } + return i < this.items.length - 1 + } + + isThreadChildAt(i: number) { + if (this.items.length === 1) { + return false + } + return i > 0 + } +} |