Updated stores
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { availableSheets, selectedSheet, currentStep } from '$lib/stores';
|
||||
import { selectedSheet, currentStep } from '$lib/stores';
|
||||
import type { SheetInfoType } from '$lib/stores';
|
||||
import { searchSheets } from '$lib/google';
|
||||
import { onMount } from 'svelte';
|
||||
import Navigator from './subcomponents/Navigator.svelte';
|
||||
@@ -25,19 +26,11 @@
|
||||
|
||||
try {
|
||||
searchResults = await searchSheets(searchQuery);
|
||||
availableSheets.set(
|
||||
searchResults.map((sheet) => ({
|
||||
spreadsheetId: sheet.spreadsheetId || sheet.id,
|
||||
name: sheet.name,
|
||||
url: sheet.webViewLink
|
||||
}))
|
||||
);
|
||||
hasSearched = true;
|
||||
} catch (err) {
|
||||
console.error('Error searching sheets:', err);
|
||||
error = 'Failed to search sheets. Please check your connection and try again.';
|
||||
searchResults = [];
|
||||
availableSheets.set([]);
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
@@ -57,11 +50,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
function saveRecentSheet(sheet) {
|
||||
// Remove duplicates
|
||||
recentSheets = recentSheets.filter(s => s.id !== sheet.id);
|
||||
recentSheets.unshift(sheet);
|
||||
|
||||
// Limit to 5 recent sheets
|
||||
if (recentSheets.length > 5) {
|
||||
recentSheets.pop();
|
||||
}
|
||||
|
||||
localStorage.setItem(RECENT_SHEETS_KEY, JSON.stringify(recentSheets));
|
||||
}
|
||||
|
||||
function handleSelectSheet(sheet) {
|
||||
const sheetData = {
|
||||
spreadsheetId: sheet.spreadsheetId || sheet.id,
|
||||
const sheetData: SheetInfoType = {
|
||||
id: sheet.id,
|
||||
name: sheet.name,
|
||||
url: sheet.webViewLink || sheet.url
|
||||
webViewLink: sheet.webViewLink
|
||||
};
|
||||
selectedSheet.set(sheetData);
|
||||
}
|
||||
@@ -264,5 +270,6 @@
|
||||
textBack="Back to Auth"
|
||||
textForwardDisabled="Select a sheet"
|
||||
textForwardEnabled="Continue"
|
||||
onForward={() => saveRecentSheet($selectedSheet)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,45 +1,42 @@
|
||||
import { writable, derived } from 'svelte/store';
|
||||
|
||||
|
||||
// This file is holy and shall not be edited by Copilot!
|
||||
|
||||
|
||||
// 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[][]>([]);
|
||||
// Data structure column mapping
|
||||
export interface ColumnMappingType {
|
||||
name: number;
|
||||
surname: number;
|
||||
nationality: number;
|
||||
birthday: number;
|
||||
pictureUrl: number;
|
||||
alreadyPrinted: number;
|
||||
sheetName: 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
|
||||
// Data structure for a row in the sheet
|
||||
export interface RowData {
|
||||
id: string;
|
||||
id: string; // Unique identifier
|
||||
name: string;
|
||||
surname: string;
|
||||
nationality: string;
|
||||
birthday: string;
|
||||
pictureUrl: string;
|
||||
valid: boolean;
|
||||
included: boolean;
|
||||
age?: number;
|
||||
validationErrors: string[];
|
||||
alreadyPrinted: boolean;
|
||||
_rowIndex: number;
|
||||
_checked: boolean;
|
||||
_valid: boolean;
|
||||
}
|
||||
|
||||
export const sheetData = writable<RowData[]>([]);
|
||||
|
||||
// Picture storage and metadata
|
||||
export interface PictureBlobInfo {
|
||||
export interface PictureBlobInfoType {
|
||||
id: string;
|
||||
blob: Blob;
|
||||
url: string;
|
||||
@@ -48,17 +45,55 @@ export interface PictureBlobInfo {
|
||||
faceCount: number;
|
||||
}
|
||||
|
||||
export const pictures = writable<Record<string, PictureBlobInfo>>({});
|
||||
|
||||
// Crop rectangles for each photo
|
||||
export interface Crop {
|
||||
// CropType rectangles for each photo
|
||||
export interface CropType {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export const cropRects = writable<Record<string, Crop>>({});
|
||||
// Google Sheets list for search
|
||||
export interface SheetInfoType {
|
||||
id: string;
|
||||
name: string;
|
||||
webViewLink: string;
|
||||
}
|
||||
|
||||
// Card details type
|
||||
export interface CardDetailsType {
|
||||
homeSection: string;
|
||||
validityStart: string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Column mapping configuration
|
||||
export const columnMapping = writable<ColumnMappingType>(
|
||||
{
|
||||
name: -1,
|
||||
surname: -1,
|
||||
nationality: -1,
|
||||
birthday: -1,
|
||||
pictureUrl: -1,
|
||||
alreadyPrinted: -1,
|
||||
sheetName: ''
|
||||
});
|
||||
|
||||
// Store to hold the processed sheet data
|
||||
export const sheetData = writable<RowData[]>([]);
|
||||
|
||||
// Store and hold the processed picture data
|
||||
export const pictures = writable<Record<string, PictureBlobInfoType>>({});
|
||||
|
||||
// Store and hold the crop rectangles from face detection
|
||||
export const CropRects = writable<Record<string, CropType>>({});
|
||||
|
||||
// Store and hold the selected sheet
|
||||
export const selectedSheet = writable<SheetInfoType | null>(null);
|
||||
|
||||
// Card details for generation
|
||||
export const cardDetails = writable<CardDetailsType | null>(null);
|
||||
|
||||
// Wizard state management
|
||||
export const currentStep = writable<number>(0);
|
||||
@@ -94,62 +129,3 @@ export const progress = writable<ProgressState>({
|
||||
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
|
||||
});
|
||||
|
||||
// Card details for generation
|
||||
export const cardDetails = writable<{
|
||||
homeSection: string;
|
||||
validityStart: string;
|
||||
}>({
|
||||
homeSection: '',
|
||||
validityStart: ''
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user