Skip to content

Commit

Permalink
Go back to content-driven slice keys in feeds (#2190)
Browse files Browse the repository at this point in the history
* Go back to deterministic react keys

* Quick fix to cases when custom feeds serve empty responses
  • Loading branch information
pfrazee authored Dec 12, 2023
1 parent 90647fe commit 870505c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/lib/api/feed-manip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ export type FeedTunerFn = (
) => FeedViewPostsSlice[]

export class FeedViewPostsSlice {
_reactKey: string
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() {
if (this.isFlattenedReply) {
Expand Down Expand Up @@ -120,9 +126,7 @@ export class NoopFeedTuner {
feed: FeedViewPost[],
_opts?: {dryRun: boolean; maintainOrder: boolean},
): FeedViewPostsSlice[] {
return feed.map(
item => new FeedViewPostsSlice([item], `slice-${this.keyCounter++}`),
)
return feed.map(item => new FeedViewPostsSlice([item]))
}
}

Expand Down Expand Up @@ -160,9 +164,7 @@ export class FeedTuner {
})

if (maintainOrder) {
slices = feed.map(
item => new FeedViewPostsSlice([item], `slice-${this.keyCounter++}`),
)
slices = feed.map(item => new FeedViewPostsSlice([item]))
} else {
// arrange the posts into thread slices
for (let i = feed.length - 1; i >= 0; i--) {
Expand All @@ -178,9 +180,7 @@ export class FeedTuner {
continue
}
}
slices.unshift(
new FeedViewPostsSlice([item], `slice-${this.keyCounter++}`),
)
slices.unshift(new FeedViewPostsSlice([item]))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/feed/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class CustomFeedAPI implements FeedAPI {
res.data.feed = res.data.feed.slice(0, limit)
}
return {
cursor: res.data.cursor,
cursor: res.data.feed.length ? res.data.cursor : undefined,
feed: res.data.feed,
}
}
Expand Down

0 comments on commit 870505c

Please sign in to comment.