fix: align task due dates to the right
This commit is contained in:
@@ -141,6 +141,28 @@ export function nextTotalAfterLocalTaskAdd(total: number) {
|
||||
return Math.max(0, Number(total) || 0) + 1
|
||||
}
|
||||
|
||||
export function nextTotalAfterLocalTaskRemoval(total: number, removed = 1) {
|
||||
return Math.max(0, (Number(total) || 0) - Math.max(0, removed))
|
||||
}
|
||||
|
||||
export type TrashMutationResult =
|
||||
| { mutated: false; refreshed: false; error: unknown }
|
||||
| { mutated: true; refreshed: boolean }
|
||||
|
||||
export async function performTrashMutation(
|
||||
mutate: () => Promise<unknown>,
|
||||
reconcileLocal: () => void,
|
||||
refresh: () => Promise<boolean>,
|
||||
): Promise<TrashMutationResult> {
|
||||
try {
|
||||
await mutate()
|
||||
} catch (error) {
|
||||
return { mutated: false, refreshed: false, error }
|
||||
}
|
||||
reconcileLocal()
|
||||
return { mutated: true, refreshed: await refresh() }
|
||||
}
|
||||
|
||||
export function clampFabPosition(x: number, y: number, viewportWidth: number, viewportHeight: number, size = 52, margin = 14, bottomReserved = 74) {
|
||||
return {
|
||||
x: Math.min(Math.max(x, margin), Math.max(margin, viewportWidth - size - margin)),
|
||||
@@ -190,14 +212,19 @@ export async function runLatestRequest<T>(
|
||||
},
|
||||
) {
|
||||
const generation = beginLatestRequest(key)
|
||||
let committed = false
|
||||
try {
|
||||
const value = await request()
|
||||
if (isLatestRequest(key, generation)) callbacks.success(value)
|
||||
if (isLatestRequest(key, generation)) {
|
||||
callbacks.success(value)
|
||||
committed = true
|
||||
}
|
||||
} catch (reason) {
|
||||
if (isLatestRequest(key, generation)) callbacks.error(reason)
|
||||
} finally {
|
||||
if (isLatestRequest(key, generation)) callbacks.finally()
|
||||
}
|
||||
return committed
|
||||
}
|
||||
|
||||
export type MutationReconciler<TContext> = {
|
||||
|
||||
Reference in New Issue
Block a user