1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-04 16:09:59 +00:00

fix: incorrect logic in useStatusActions (#295)

This commit is contained in:
Alex 2022-12-03 00:55:52 +08:00 committed by GitHub
parent 2a84bbb3d6
commit 43224fa9d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,22 +25,20 @@ export function useStatusActions(props: StatusActionsProps) {
translation: false,
})
async function toggleStatusAction(action: Action, newStatus: () => Promise<Status>, countField?: CountField) {
async function toggleStatusAction(action: Action, fetchNewStatus: () => Promise<Status>, countField?: CountField) {
// check login
if (!checkLogin())
return
isLoading[action] = true
fetchNewStatus().then((newStatus) => {
Object.assign(status, newStatus)
}).finally(() => {
isLoading[action] = false
})
// Optimistic update
status[action] = !status[action]
if (countField)
status[countField] += status[action] ? 1 : -1
try {
isLoading[action] = true
Object.assign(status, await newStatus())
}
finally {
isLoading[action] = false
}
}
const toggleReblog = () => toggleStatusAction(
'reblogged',