dify/web/app/components/goto-anything/actions/recent-store.ts
Crazywoola 175290fa04
feat(goto-anything): recent items, /go navigation command, deep app sub-sections (#35078)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 03:45:58 +00:00

31 lines
757 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 {}
}