dify/web/app/components/goto-anything/actions/recent-store.ts
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

28 lines
749 B
TypeScript

const RECENT_ITEMS_KEY = 'goto-anything:recent'
const MAX_RECENT_ITEMS = 8
export function getRecentItems() {
try {
const stored = localStorage.getItem(RECENT_ITEMS_KEY)
if (!stored) return []
return JSON.parse(stored) as Array<{
id: string
title: string
description?: string
path: string
originalType: 'app' | 'knowledge'
}>
} catch {
return []
}
}
export function addRecentItem(item: ReturnType<typeof getRecentItems>[number]): void {
try {
const recent = getRecentItems()
const filtered = recent.filter((r) => r.id !== item.id)
const updated = [item, ...filtered].slice(0, MAX_RECENT_ITEMS)
localStorage.setItem(RECENT_ITEMS_KEY, JSON.stringify(updated))
} catch {}
}