| import type { CultureDecode } from '../types/culture'; |
| import { getScanInsight } from './localLens'; |
|
|
| const JOURNAL_KEY = 'local-in-30s-journal'; |
|
|
| export type JournalRecord = CultureDecode & { |
| savedAt: string; |
| localMove: string; |
| }; |
|
|
| export function loadJournalRecords(): JournalRecord[] { |
| if (typeof window === 'undefined') return []; |
|
|
| try { |
| const raw = window.localStorage.getItem(JOURNAL_KEY); |
| if (!raw) return []; |
|
|
| const parsed = JSON.parse(raw); |
| return Array.isArray(parsed) |
| ? parsed.map((record) => ({ |
| ...record, |
| localMove: record.localMove || getScanInsight(record).localMove, |
| })) |
| : []; |
| } catch { |
| return []; |
| } |
| } |
|
|
| export function saveJournalRecord(decode: CultureDecode): JournalRecord[] { |
| if (typeof window === 'undefined') return []; |
|
|
| const current = loadJournalRecords(); |
| const insight = getScanInsight(decode); |
| const nextRecord: JournalRecord = { |
| ...decode, |
| savedAt: new Date().toISOString(), |
| localMove: insight.localMove, |
| }; |
|
|
| const next = [nextRecord, ...current.filter((record) => record.id !== decode.id)].slice(0, 12); |
| window.localStorage.setItem(JOURNAL_KEY, JSON.stringify(next)); |
| return next; |
| } |
|
|