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