update cache of ancestors on comment and upvote
This commit is contained in:
parent
f65f6c1b28
commit
04d7e9c0ee
|
@ -186,7 +186,7 @@ export default function Comment ({
|
||||||
<div className={`${styles.children}`}>
|
<div className={`${styles.children}`}>
|
||||||
{!noReply &&
|
{!noReply &&
|
||||||
<Reply
|
<Reply
|
||||||
depth={depth + 1} parentId={item.id} replyOpen={replyOpen}
|
depth={depth + 1} item={item} replyOpen={replyOpen}
|
||||||
/>}
|
/>}
|
||||||
{children}
|
{children}
|
||||||
<div className={`${styles.comments} ml-sm-1 ml-md-3`}>
|
<div className={`${styles.comments} ml-sm-1 ml-md-3`}>
|
||||||
|
|
|
@ -31,7 +31,7 @@ function BioItem ({ item, handleClick }) {
|
||||||
>edit bio
|
>edit bio
|
||||||
</Button>
|
</Button>
|
||||||
</div>}
|
</div>}
|
||||||
<Reply parentId={item.id} />
|
<Reply item={item} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ function TopLevelItem ({ item, noReply, ...props }) {
|
||||||
{item.text && <ItemText item={item} />}
|
{item.text && <ItemText item={item} />}
|
||||||
{item.url && <ItemEmbed item={item} />}
|
{item.url && <ItemEmbed item={item} />}
|
||||||
{item.poll && <Poll item={item} />}
|
{item.poll && <Poll item={item} />}
|
||||||
{!noReply && <Reply parentId={item.id} replyOpen />}
|
{!noReply && <Reply item={item} replyOpen />}
|
||||||
</ItemComponent>
|
</ItemComponent>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,11 @@ export function ReplyOnAnotherPage ({ parentId }) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Reply ({ parentId, onSuccess, replyOpen }) {
|
export default function Reply ({ item, onSuccess, replyOpen }) {
|
||||||
const [reply, setReply] = useState(replyOpen)
|
const [reply, setReply] = useState(replyOpen)
|
||||||
const me = useMe()
|
const me = useMe()
|
||||||
const [hasImgLink, setHasImgLink] = useState()
|
const [hasImgLink, setHasImgLink] = useState()
|
||||||
|
const parentId = item.id
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setReply(replyOpen || !!localStorage.getItem('reply-' + parentId + '-' + 'text'))
|
setReply(replyOpen || !!localStorage.getItem('reply-' + parentId + '-' + 'text'))
|
||||||
|
@ -52,12 +53,21 @@ export default function Reply ({ parentId, onSuccess, replyOpen }) {
|
||||||
fragmentName: 'CommentsRecursive'
|
fragmentName: 'CommentsRecursive'
|
||||||
})
|
})
|
||||||
return [newCommentRef, ...existingCommentRefs]
|
return [newCommentRef, ...existingCommentRefs]
|
||||||
},
|
|
||||||
ncomments (existingNComments = 0) {
|
|
||||||
return existingNComments + 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// update all ancestors
|
||||||
|
item.path.split('.').forEach(id => {
|
||||||
|
cache.modify({
|
||||||
|
id: `Item:${id}`,
|
||||||
|
fields: {
|
||||||
|
ncomments (existingNComments = 0) {
|
||||||
|
return existingNComments + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -135,6 +135,19 @@ export default function UpVote ({ item, className }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// update all ancestors
|
||||||
|
item.path.split('.').forEach(id => {
|
||||||
|
if (Number(id) === Number(item.id)) return
|
||||||
|
cache.modify({
|
||||||
|
id: `Item:${id}`,
|
||||||
|
fields: {
|
||||||
|
commentSats (existingCommentSats = 0) {
|
||||||
|
return existingCommentSats + sats
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue