feat: refine archived habit management
This commit is contained in:
@@ -269,6 +269,25 @@ export function writeHabitGridCache<T>(week: string, habits: T[]) {
|
||||
habitGridCache = { week, habits }
|
||||
}
|
||||
|
||||
export function invalidateHabitGridCache() {
|
||||
habitGridCache = null
|
||||
}
|
||||
|
||||
export async function performHabitRestore(actions: {
|
||||
restore: () => Promise<unknown>
|
||||
commitRestore: () => void
|
||||
refreshGrid: () => Promise<boolean | unknown>
|
||||
}) {
|
||||
await actions.restore()
|
||||
actions.commitRestore()
|
||||
try {
|
||||
const refreshed = await actions.refreshGrid()
|
||||
return { restored: true as const, refreshed: refreshed !== false }
|
||||
} catch {
|
||||
return { restored: true as const, refreshed: false }
|
||||
}
|
||||
}
|
||||
|
||||
export function readCountdownCache<T>() {
|
||||
if (!countdownCache) return null
|
||||
return { items: countdownCache.items as T[], archived: countdownCache.archived as T[] }
|
||||
@@ -369,6 +388,22 @@ export function habitActionState(cell?: { scheduled?: boolean; paused?: boolean
|
||||
return { writable: true, reason: '' }
|
||||
}
|
||||
|
||||
export type ArchivePanelState = 'idle' | 'loading' | 'success' | 'error'
|
||||
|
||||
export function archivePanelFlags(state: ArchivePanelState, count: number) {
|
||||
return {
|
||||
loading: state === 'loading',
|
||||
error: state === 'error',
|
||||
empty: state === 'success' && count === 0,
|
||||
list: state === 'success' && count > 0,
|
||||
}
|
||||
}
|
||||
|
||||
export function formatArchivedAt(value?: string | null, options: { timeZone?: string } = {}) {
|
||||
const formatted = formatLocalShortDateTime(value, options)
|
||||
return formatted === '未知时间' ? '归档时间未知' : `归档于 ${formatted}`
|
||||
}
|
||||
|
||||
export function formatUserAgent(userAgent?: string | null): string {
|
||||
const ua = userAgent?.trim() ?? ''
|
||||
let device = '未知设备'
|
||||
|
||||
Reference in New Issue
Block a user