Go back to content-driven slice keys in feeds (#2190)

* Go back to deterministic react keys

* Quick fix to cases when custom feeds serve empty responses
zio/stable
Paul Frazee 2023-12-12 13:07:09 -08:00 committed by GitHub
parent 90647fe7cf
commit 870505cbe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -14,9 +14,15 @@ export type FeedTunerFn = (
) => FeedViewPostsSlice[] ) => FeedViewPostsSlice[]
export class FeedViewPostsSlice { export class FeedViewPostsSlice {
_reactKey: string
isFlattenedReply = false isFlattenedReply = false
constructor(public items: FeedViewPost[], public _reactKey: string) {} constructor(public items: FeedViewPost[]) {
const item = items[0]
this._reactKey = `slice-${item.post.uri}-${
item.reason?.indexedAt || item.post.indexedAt
}`
}
get uri() { get uri() {
if (this.isFlattenedReply) { if (this.isFlattenedReply) {
@ -120,9 +126,7 @@ export class NoopFeedTuner {
feed: FeedViewPost[], feed: FeedViewPost[],
_opts?: {dryRun: boolean; maintainOrder: boolean}, _opts?: {dryRun: boolean; maintainOrder: boolean},
): FeedViewPostsSlice[] { ): FeedViewPostsSlice[] {
return feed.map( return feed.map(item => new FeedViewPostsSlice([item]))
item => new FeedViewPostsSlice([item], `slice-${this.keyCounter++}`),
)
} }
} }
@ -160,9 +164,7 @@ export class FeedTuner {
}) })
if (maintainOrder) { if (maintainOrder) {
slices = feed.map( slices = feed.map(item => new FeedViewPostsSlice([item]))
item => new FeedViewPostsSlice([item], `slice-${this.keyCounter++}`),
)
} else { } else {
// arrange the posts into thread slices // arrange the posts into thread slices
for (let i = feed.length - 1; i >= 0; i--) { for (let i = feed.length - 1; i >= 0; i--) {
@ -178,9 +180,7 @@ export class FeedTuner {
continue continue
} }
} }
slices.unshift( slices.unshift(new FeedViewPostsSlice([item]))
new FeedViewPostsSlice([item], `slice-${this.keyCounter++}`),
)
} }
} }

View File

@ -37,7 +37,7 @@ export class CustomFeedAPI implements FeedAPI {
res.data.feed = res.data.feed.slice(0, limit) res.data.feed = res.data.feed.slice(0, limit)
} }
return { return {
cursor: res.data.cursor, cursor: res.data.feed.length ? res.data.cursor : undefined,
feed: res.data.feed, feed: res.data.feed,
} }
} }