WIP kill me
This commit is contained in:
@@ -41,11 +41,12 @@ export function usePostThread({
|
||||
const query = useQuery({
|
||||
enabled,
|
||||
queryKey,
|
||||
gcTime: 0,
|
||||
async queryFn() {
|
||||
const {data} = await agent.app.bsky.unspecced.getPostThreadV2({
|
||||
anchor: uri!,
|
||||
branchingFactor: params.view === 'linear' ? 1 : 100,
|
||||
below: 10,
|
||||
branchingFactor: params.view === 'linear' ? 1 : 3, // 100 TODO
|
||||
below: 3,
|
||||
sorting: mapSortOptionsToSortID(params.sort),
|
||||
})
|
||||
return data
|
||||
@@ -95,6 +96,7 @@ export function usePostThread({
|
||||
return {
|
||||
...query,
|
||||
data: {
|
||||
anchorIndex: items.findIndex(i => Boolean(i.ui?.isAnchor)),
|
||||
items,
|
||||
threadgate: query.data?.threadgate,
|
||||
},
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import {
|
||||
APP_BSKY_UNSPECCED,
|
||||
AtUri,
|
||||
AppBskyUnspeccedGetPostThreadV2,
|
||||
type ModerationDecision,
|
||||
type ModerationOpts,
|
||||
@@ -21,6 +23,54 @@ export function flatten(
|
||||
) {
|
||||
const flattened: Slice[] = sorted.items
|
||||
|
||||
const unhydratedReplyIntervals = []
|
||||
|
||||
for (let i = 0; i < flattened.length; i++) {
|
||||
const item = flattened[i]
|
||||
|
||||
if (item.type === 'threadPost') {
|
||||
// TODO should not insert if not found post etc
|
||||
if (item.ui.isAnchor && hasSession && !item.value.post.viewer?.replyDisabled) {
|
||||
flattened.splice(i + 1, 0, {
|
||||
type: 'replyComposer',
|
||||
key: 'replyComposer',
|
||||
})
|
||||
}
|
||||
|
||||
const prev = unhydratedReplyIntervals[unhydratedReplyIntervals.length - 1]
|
||||
|
||||
if (item.annotations.has(APP_BSKY_UNSPECCED.GetPostThreadV2HasMoreReplies)) {
|
||||
unhydratedReplyIntervals.push({
|
||||
item,
|
||||
replyCount: item.value.post.replyCount || 0,
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
* If direct child of previous item with `hasMoreReplies`, subtract
|
||||
*/
|
||||
if (prev && item.depth === prev.item.depth + 1) {
|
||||
prev.replyCount = Math.max(0, prev.replyCount - 1)
|
||||
}
|
||||
|
||||
if (prev && item.depth <= prev.item.depth) {
|
||||
flattened.splice(i, 0, {
|
||||
type: 'readMore',
|
||||
key: `readMore:${prev.item.uri}`,
|
||||
indent: prev.item.depth + (item.depth < prev.item.depth ? -1 : 0),
|
||||
replyCount: prev.replyCount,
|
||||
nextAnchor: prev.item,
|
||||
nextAnchorUri: new AtUri(prev.item.uri),
|
||||
})
|
||||
unhydratedReplyIntervals.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert hidden items and buttons to show them
|
||||
*/
|
||||
|
||||
if (sorted.hidden.length) {
|
||||
if (showHidden) {
|
||||
flattened.push(...sorted.hidden)
|
||||
@@ -55,30 +105,6 @@ export function flatten(
|
||||
}
|
||||
}
|
||||
|
||||
if (hasSession) {
|
||||
for (let i = 0; i < flattened.length; i++) {
|
||||
const item = flattened[i]
|
||||
|
||||
// TODO should not insert if not found post etc
|
||||
if (item.type === 'threadPost') {
|
||||
if (item.ui.isAnchor) {
|
||||
flattened.splice(i + 1, 0, {
|
||||
type: 'replyComposer',
|
||||
key: 'replyComposer',
|
||||
})
|
||||
}
|
||||
|
||||
if (
|
||||
item.value.post.replyCount &&
|
||||
item.value.post.replyCount > 0 &&
|
||||
!item.ui.showChildReplyLine
|
||||
) {
|
||||
console.log('insert more link')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flattened
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
type APP_BSKY_UNSPECCED,
|
||||
type AtUri,
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedPost,
|
||||
type AppBskyUnspeccedGetPostThreadV2,
|
||||
@@ -89,7 +90,10 @@ export type Slice =
|
||||
kind: HiddenReplyKind
|
||||
}
|
||||
| {
|
||||
type: 'threadPostNoOp'
|
||||
type: 'readMore'
|
||||
key: string
|
||||
comment: string
|
||||
indent: number
|
||||
replyCount: number
|
||||
nextAnchor: Extract<Slice, {type: 'threadPost'}>
|
||||
nextAnchorUri: AtUri
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user