mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-26 00:16:51 +00:00
Add "new" badge and store seen state
This commit is contained in:
@@ -21,6 +21,7 @@ export namespace Store {
|
||||
export const ID_TREE_VIEW_MODE = 'misode_tree_view_mode'
|
||||
export const ID_COLORMAP = 'misode_colormap'
|
||||
export const ID_GENERATOR_HISTORY = 'misode_generator_history'
|
||||
export const ID_WHATS_NEW_SEEN = 'misode_whats_new_seen'
|
||||
|
||||
export function getLanguage() {
|
||||
return localStorage.getItem(ID_LANGUAGE) ?? 'en'
|
||||
@@ -186,4 +187,22 @@ export namespace Store {
|
||||
history.push(id)
|
||||
localStorage.setItem(ID_GENERATOR_HISTORY, JSON.stringify(history.slice(-50)))
|
||||
}
|
||||
|
||||
export function getWhatsNewSeen(): { id: string, time: string }[] {
|
||||
return JSON.parse(localStorage.getItem(ID_WHATS_NEW_SEEN) ?? '[]')
|
||||
}
|
||||
|
||||
export function seeWhatsNew(ids: string[]) {
|
||||
const now = new Date().toISOString()
|
||||
const items = getWhatsNewSeen()
|
||||
for (const id of ids) {
|
||||
const old = items.find(i => i.id === id)
|
||||
if (old) {
|
||||
old.time = now
|
||||
} else {
|
||||
items.push({ id, time: now })
|
||||
}
|
||||
}
|
||||
localStorage.setItem(ID_WHATS_NEW_SEEN, JSON.stringify(items))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user