Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/hooks/useProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export function useProjects() {
async (ids: string[], category: string, destOrderedIds: string[]) => {
if (ids.length === 0) return
const moving = new Set(ids)
const snapshot = Array.isArray(projects) ? [...projects] : null
setData((prev) => {
if (!Array.isArray(prev)) return prev
const rank = new Map(destOrderedIds.map((pid, i) => [pid, i]))
Expand All @@ -116,12 +117,18 @@ export function useProjects() {
return p
})
})
for (const id of ids) {
await api.updateProject(id, { category })
try {
for (const id of ids) {
await api.updateProject(id, { category })
}
await api.reorderProjects(destOrderedIds)
} catch (e) {
if (snapshot) setData(snapshot)
await refresh()
throw e
}
await api.reorderProjects(destOrderedIds)
},
[setData],
[projects, refresh, setData],
)

const reorder = useCallback(async (orderedIds: string[]) => {
Expand Down
Loading