mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-17 05:40:42 -07:00
32 lines
815 B
TypeScript
32 lines
815 B
TypeScript
import { create } from 'zustand';
|
|
import type { ServerLogEntry } from '@/platform/types';
|
|
|
|
const MAX_LOG_ENTRIES = 2000;
|
|
|
|
let nextLogEntryId = 0;
|
|
|
|
export interface LogEntry extends ServerLogEntry {
|
|
id: number;
|
|
timestamp: number;
|
|
}
|
|
|
|
interface LogStore {
|
|
entries: LogEntry[];
|
|
addEntry: (entry: ServerLogEntry) => void;
|
|
clear: () => void;
|
|
}
|
|
|
|
export const useLogStore = create<LogStore>((set) => ({
|
|
entries: [],
|
|
addEntry: (entry) =>
|
|
set((state) => {
|
|
const newEntry: LogEntry = { ...entry, id: nextLogEntryId++, timestamp: Date.now() };
|
|
const entries = [...state.entries, newEntry];
|
|
if (entries.length > MAX_LOG_ENTRIES) {
|
|
return { entries: entries.slice(entries.length - MAX_LOG_ENTRIES) };
|
|
}
|
|
return { entries };
|
|
}),
|
|
clear: () => set({ entries: [] }),
|
|
}));
|