- Connect Firestore for journal entries and visited countries (real-time onSnapshot) - Connect Firebase Storage for photo uploads - Add NewEntryForm: 3-step flow (trip details → photos → reflection questions) - Expand country list to full world-atlas dataset (~240 countries) matching the map - Filter city suggestions by selected country in both NewEntryForm and EditForm - Redesign StatsPanel as floating horizontal card with donut chart and progress bar - Center timeline layout with responsive side margins - Replace "entry" language with "trip" throughout (Add trip, Save trip, Delete trip) - Remove footer from Layout Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
import { writable } from 'svelte/store';
|
|
import { db } from '../firebase.js';
|
|
import {
|
|
collection, onSnapshot, addDoc, updateDoc, deleteDoc, doc, serverTimestamp
|
|
} from 'firebase/firestore';
|
|
|
|
/**
|
|
* @typedef {{
|
|
* id: string,
|
|
* title: string,
|
|
* date: string,
|
|
* location: { country: string, cities: string[] },
|
|
* photos: string[],
|
|
* transport: 'flight' | 'train' | 'bus' | 'car' | 'ship' | 'walk',
|
|
* tripType: 'solo' | 'friends' | 'family',
|
|
* days: number,
|
|
* memo: string
|
|
* }} JournalEntry
|
|
*/
|
|
|
|
export const journals = writable(/** @type {JournalEntry[]} */([]));
|
|
export const journalsLoading = writable(true);
|
|
|
|
const entriesRef = collection(db, 'entries');
|
|
|
|
onSnapshot(entriesRef, (snap) => {
|
|
journals.set(snap.docs.map(d => ({ id: d.id, ...d.data() })));
|
|
journalsLoading.set(false);
|
|
});
|
|
|
|
/** @param {Omit<JournalEntry, 'id'>} entry */
|
|
export async function addJournal(entry) {
|
|
await addDoc(entriesRef, { ...entry, createdAt: serverTimestamp() });
|
|
}
|
|
|
|
/** @param {string} id */
|
|
export async function removeJournal(id) {
|
|
await deleteDoc(doc(db, 'entries', id));
|
|
}
|
|
|
|
/** @param {JournalEntry} updated */
|
|
export async function updateJournal(updated) {
|
|
const { id, ...data } = updated;
|
|
await updateDoc(doc(db, 'entries', id), data);
|
|
}
|