fix: incorrect logic in useStatusActions (#295)
This commit is contained in:
parent
2a84bbb3d6
commit
43224fa9d3
|
@ -25,22 +25,20 @@ export function useStatusActions(props: StatusActionsProps) {
|
||||||
translation: false,
|
translation: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
async function toggleStatusAction(action: Action, newStatus: () => Promise<Status>, countField?: CountField) {
|
async function toggleStatusAction(action: Action, fetchNewStatus: () => Promise<Status>, countField?: CountField) {
|
||||||
// check login
|
// check login
|
||||||
if (!checkLogin())
|
if (!checkLogin())
|
||||||
return
|
return
|
||||||
|
isLoading[action] = true
|
||||||
|
fetchNewStatus().then((newStatus) => {
|
||||||
|
Object.assign(status, newStatus)
|
||||||
|
}).finally(() => {
|
||||||
|
isLoading[action] = false
|
||||||
|
})
|
||||||
// Optimistic update
|
// Optimistic update
|
||||||
status[action] = !status[action]
|
status[action] = !status[action]
|
||||||
if (countField)
|
if (countField)
|
||||||
status[countField] += status[action] ? 1 : -1
|
status[countField] += status[action] ? 1 : -1
|
||||||
|
|
||||||
try {
|
|
||||||
isLoading[action] = true
|
|
||||||
Object.assign(status, await newStatus())
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
isLoading[action] = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const toggleReblog = () => toggleStatusAction(
|
const toggleReblog = () => toggleStatusAction(
|
||||||
'reblogged',
|
'reblogged',
|
||||||
|
|
Loading…
Reference in a new issue