147 lines
2.9 KiB
TypeScript
147 lines
2.9 KiB
TypeScript
import { writable, derived } from 'svelte/store';
|
|
|
|
// User session and authentication
|
|
export const session = writable<{
|
|
token?: string;
|
|
user?: { name: string; email: string };
|
|
}>({});
|
|
|
|
// Raw sheet data after import
|
|
export const rawSheetData = writable<string[][]>([]);
|
|
|
|
// Filtered sheet data after row selection
|
|
export const filteredSheetData = writable<any[]>([]);
|
|
|
|
// Column mapping configuration
|
|
export const columnMapping = writable<{
|
|
name?: number;
|
|
surname?: number;
|
|
nationality?: number;
|
|
birthday?: number;
|
|
pictureUrl?: number;
|
|
alreadyPrinted?: number;
|
|
}>({});
|
|
|
|
// Processed row data after mapping and validation
|
|
export interface RowData {
|
|
id: string;
|
|
name: string;
|
|
surname: string;
|
|
nationality: string;
|
|
birthday: string;
|
|
pictureUrl: string;
|
|
valid: boolean;
|
|
included: boolean;
|
|
age?: number;
|
|
validationErrors: string[];
|
|
}
|
|
|
|
export const sheetData = writable<RowData[]>([]);
|
|
|
|
// Picture storage and metadata
|
|
export interface PictureBlobInfo {
|
|
id: string;
|
|
blob: Blob;
|
|
url: string;
|
|
downloaded: boolean;
|
|
faceDetected: boolean;
|
|
faceCount: number;
|
|
}
|
|
|
|
export const pictures = writable<Record<string, PictureBlobInfo>>({});
|
|
|
|
// Crop rectangles for each photo
|
|
export interface Crop {
|
|
x: number;
|
|
y: number;
|
|
width: number;
|
|
height: number;
|
|
}
|
|
|
|
export const cropRects = writable<Record<string, Crop>>({});
|
|
|
|
// Wizard state management
|
|
export const currentStep = writable<number>(0);
|
|
|
|
export const steps = [
|
|
'splash',
|
|
'auth',
|
|
'search',
|
|
'mapping',
|
|
'validation',
|
|
'gallery',
|
|
'generate'
|
|
] as const;
|
|
|
|
export type WizardStep = typeof steps[number];
|
|
|
|
export const currentStepName = derived(
|
|
currentStep,
|
|
($currentStep) => steps[$currentStep]
|
|
);
|
|
|
|
// Progress tracking
|
|
export interface ProgressState {
|
|
stage: string;
|
|
current: number;
|
|
total: number;
|
|
message: string;
|
|
}
|
|
|
|
export const progress = writable<ProgressState>({
|
|
stage: '',
|
|
current: 0,
|
|
total: 0,
|
|
message: ''
|
|
});
|
|
|
|
// Google Sheets list for search
|
|
export interface SheetInfo {
|
|
spreadsheetId: string;
|
|
name: string;
|
|
url: string;
|
|
}
|
|
|
|
export const availableSheets = writable<SheetInfo[]>([]);
|
|
|
|
// Selected sheet
|
|
export const selectedSheet = writable<SheetInfo | null>(null);
|
|
|
|
// Validation derived stores
|
|
export const validRowCount = derived(
|
|
sheetData,
|
|
($sheetData) => $sheetData.filter(row => row.valid && row.included).length
|
|
);
|
|
|
|
export const invalidRowCount = derived(
|
|
sheetData,
|
|
($sheetData) => $sheetData.filter(row => !row.valid).length
|
|
);
|
|
|
|
export const totalRowCount = derived(
|
|
sheetData,
|
|
($sheetData) => $sheetData.length
|
|
);
|
|
|
|
// Face detection status
|
|
export const faceDetectionProgress = writable<{
|
|
completed: number;
|
|
total: number;
|
|
currentImage: string;
|
|
}>({
|
|
completed: 0,
|
|
total: 0,
|
|
currentImage: ''
|
|
});
|
|
|
|
// PDF generation status
|
|
export const pdfGenerationStatus = writable<{
|
|
generating: boolean;
|
|
stage: 'preparing' | 'text-pdf' | 'photo-pdf' | 'complete';
|
|
progress: number;
|
|
}>({
|
|
generating: false,
|
|
stage: 'preparing',
|
|
progress: 0
|
|
});
|