Handle unhiding with reply cache
This commit is contained in:
@@ -2,6 +2,7 @@ import React from 'react'
|
||||
|
||||
type StateContext = {
|
||||
uris: string[]
|
||||
recentlyUnhiddenUris: string[]
|
||||
}
|
||||
type ApiContext = {
|
||||
addHiddenReplyUri: (uri: string) => void
|
||||
@@ -10,6 +11,7 @@ type ApiContext = {
|
||||
|
||||
const StateContext = React.createContext<StateContext>({
|
||||
uris: [],
|
||||
recentlyUnhiddenUris: [],
|
||||
})
|
||||
|
||||
const ApiContext = React.createContext<ApiContext>({
|
||||
@@ -19,21 +21,27 @@ const ApiContext = React.createContext<ApiContext>({
|
||||
|
||||
export function Provider({children}: {children: React.ReactNode}) {
|
||||
const [uris, setHiddenReplyUris] = React.useState<string[]>([])
|
||||
const [recentlyUnhiddenUris, setRecentlyUnhiddenUris] = React.useState<
|
||||
string[]
|
||||
>([])
|
||||
|
||||
const stateCtx = React.useMemo(
|
||||
() => ({
|
||||
uris,
|
||||
recentlyUnhiddenUris,
|
||||
}),
|
||||
[uris],
|
||||
[uris, recentlyUnhiddenUris],
|
||||
)
|
||||
|
||||
const apiCtx = React.useMemo(
|
||||
() => ({
|
||||
addHiddenReplyUri(uri: string) {
|
||||
setHiddenReplyUris(prev => Array.from(new Set([...prev, uri])))
|
||||
setRecentlyUnhiddenUris(prev => prev.filter(u => u !== uri))
|
||||
},
|
||||
removeHiddenReplyUri(uri: string) {
|
||||
setHiddenReplyUris(prev => prev.filter(u => u !== uri))
|
||||
setRecentlyUnhiddenUris(prev => Array.from(new Set([...prev, uri])))
|
||||
},
|
||||
}),
|
||||
[setHiddenReplyUris],
|
||||
|
||||
@@ -416,10 +416,12 @@ let PostContent = ({
|
||||
const [limitLines, setLimitLines] = useState(
|
||||
() => countLines(richText.text) >= MAX_POST_LINES,
|
||||
)
|
||||
const {uris: hiddenReplyUris} = useThreadgateHiddenReplyUris()
|
||||
const {uris: hiddenReplyUris, recentlyUnhiddenUris} =
|
||||
useThreadgateHiddenReplyUris()
|
||||
const additionalPostAlerts: AppModerationCause[] = React.useMemo(() => {
|
||||
const isPostHiddenByHiddenReplyCache = hiddenReplyUris.includes(post.uri)
|
||||
const isPostHiddenByThreadgate =
|
||||
!recentlyUnhiddenUris.includes(post.uri) &&
|
||||
!!threadgateRecord?.hiddenReplies?.includes(post.uri)
|
||||
const isHidden = isPostHiddenByHiddenReplyCache || isPostHiddenByThreadgate
|
||||
const alertSource =
|
||||
@@ -437,7 +439,13 @@ let PostContent = ({
|
||||
},
|
||||
]
|
||||
: []
|
||||
}, [post, hiddenReplyUris, threadgateRecord, currentAccount?.did])
|
||||
}, [
|
||||
post,
|
||||
hiddenReplyUris,
|
||||
recentlyUnhiddenUris,
|
||||
threadgateRecord,
|
||||
currentAccount?.did,
|
||||
])
|
||||
|
||||
const onPressShowMore = React.useCallback(() => {
|
||||
setLimitLines(false)
|
||||
|
||||
@@ -123,7 +123,8 @@ let PostDropdownBtn = ({
|
||||
const quotePostDetachConfirmControl = useDialogControl()
|
||||
const {mutateAsync: toggleReplyVisibility} =
|
||||
useToggleReplyVisibilityMutation()
|
||||
const {uris: hiddenReplies} = useThreadgateHiddenReplyUris()
|
||||
const {uris: hiddenReplies, recentlyUnhiddenUris} =
|
||||
useThreadgateHiddenReplyUris()
|
||||
|
||||
const postUri = post.uri
|
||||
const postCid = post.cid
|
||||
@@ -147,7 +148,8 @@ let PostDropdownBtn = ({
|
||||
const isRootPostAuthor = new AtUri(rootUri).host === currentAccount?.did
|
||||
const isReplyHiddenByThreadgate =
|
||||
hiddenReplies.includes(postUri) ||
|
||||
threadgateRecord?.hiddenReplies?.includes(postUri)
|
||||
(!recentlyUnhiddenUris.includes(postUri) &&
|
||||
threadgateRecord?.hiddenReplies?.includes(postUri))
|
||||
|
||||
const {mutateAsync: toggleQuoteDetachment, isPending} =
|
||||
useToggleQuoteDetachmentMutation()
|
||||
|
||||
Reference in New Issue
Block a user