feat: refine archived habit management
ci / gitleaks (push) Successful in 7s
ci / docker (push) Successful in 3m28s

This commit is contained in:
2026-09-10 14:39:06 +08:00
parent bf61e69776
commit 3e80f2ecbb
8 changed files with 515 additions and 34 deletions
+35
View File
@@ -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 = '未知设备'