91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
import { CalendarEvent, UserRole, AppSettings } from '../types';
|
|
|
|
const EVENTS_KEY = 'ourtime_events_v1';
|
|
const SETTINGS_KEY = 'ourtime_settings_v1';
|
|
|
|
export const getStoredEvents = (): CalendarEvent[] => {
|
|
try {
|
|
const stored = localStorage.getItem(EVENTS_KEY);
|
|
return stored ? JSON.parse(stored) : [];
|
|
} catch (e) {
|
|
console.error("Failed to load events", e);
|
|
return [];
|
|
}
|
|
};
|
|
|
|
export const saveEvent = (event: CalendarEvent): CalendarEvent[] => {
|
|
const events = getStoredEvents();
|
|
// Check if update or new
|
|
const index = events.findIndex(e => e.id === event.id);
|
|
let newEvents;
|
|
if (index >= 0) {
|
|
newEvents = [...events];
|
|
newEvents[index] = event;
|
|
} else {
|
|
newEvents = [...events, event];
|
|
}
|
|
|
|
localStorage.setItem(EVENTS_KEY, JSON.stringify(newEvents));
|
|
return newEvents;
|
|
};
|
|
|
|
export const deleteEvent = (eventId: string): CalendarEvent[] => {
|
|
const events = getStoredEvents();
|
|
const newEvents = events.filter(e => e.id !== eventId);
|
|
localStorage.setItem(EVENTS_KEY, JSON.stringify(newEvents));
|
|
return newEvents;
|
|
};
|
|
|
|
export const getSettings = (): AppSettings => {
|
|
try {
|
|
const stored = localStorage.getItem(SETTINGS_KEY);
|
|
if (stored) return JSON.parse(stored);
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
return {
|
|
momColor: '#F472B6',
|
|
dadColor: '#60A5FA',
|
|
mcpServerUrl: 'http://192.168.1.100:8000/stream',
|
|
enableMcp: false,
|
|
aiProvider: 'gemini', // Default to Gemini for reliability, user can switch to Ollama
|
|
ollamaUrl: 'http://localhost:11434',
|
|
ollamaModel: 'llama3',
|
|
momZodiac: 'Unknown',
|
|
dadZodiac: 'Unknown',
|
|
familiar: 'None'
|
|
};
|
|
};
|
|
|
|
export const saveSettings = (settings: AppSettings) => {
|
|
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
|
|
};
|
|
|
|
// Seed some initial data if empty for demo purposes
|
|
export const seedInitialData = () => {
|
|
if (!localStorage.getItem(EVENTS_KEY)) {
|
|
const today = new Date();
|
|
const initialEvents: CalendarEvent[] = [
|
|
{
|
|
id: '1',
|
|
title: 'Date Night ❤️',
|
|
startTime: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 2, 19, 0).toISOString(),
|
|
endTime: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 2, 21, 0).toISOString(),
|
|
createdBy: 'dad',
|
|
category: 'date',
|
|
description: 'Dinner at the Italian place',
|
|
},
|
|
{
|
|
id: '2',
|
|
title: 'Grocery Run',
|
|
startTime: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 10, 0).toISOString(),
|
|
endTime: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 11, 0).toISOString(),
|
|
createdBy: 'mom',
|
|
category: 'chore',
|
|
description: 'Milk, Eggs, Bread',
|
|
}
|
|
];
|
|
localStorage.setItem(EVENTS_KEY, JSON.stringify(initialEvents));
|
|
}
|
|
};
|