import type { Component } from 'solid-js'; import { createSignal, Show, For, createEffect } from 'solid-js'; import { Portal } from 'solid-js/web'; import { X } from 'lucide-solid'; import { pb, COLLECTIONS } from '../utils/db'; import { appStore } from '../store/appStore'; interface CloudLoadModalProps { show: boolean; onClose: () => void; } const CloudLoadModal: Component = (props) => { const [cloudEstimates, setCloudEstimates] = createSignal([]); const [isCloudLoading, setIsCloudLoading] = createSignal(false); createEffect(() => { if (props.show) { loadCloudEstimatesList(); } }); const loadCloudEstimatesList = async () => { setIsCloudLoading(true); try { const records = await pb.collection(COLLECTIONS.ESTIMATES).getFullList({ sort: '-created' }); setCloudEstimates(records); } catch (err) { console.error(err); alert('Failed to list estimates.'); } finally { setIsCloudLoading(false); } }; const loadFromCloud = (record: any) => { const data = record.items; // items holds the full JSON blob if (!data) return; if (data.scopes) appStore.setScopes(data.scopes); if (data.subScopes) appStore.setSubScopes(data.subScopes); if (data.items) appStore.setEstimateItems(data.items); if (data.clientInfo) appStore.setClientInfo(data.clientInfo); if (data.jobInfo) appStore.setJobInfo(data.jobInfo); if (data.generalEstimateNotes !== undefined) appStore.setGeneralEstimateNotes(data.generalEstimateNotes); if (data.generalPreNotes !== undefined) appStore.setGeneralPreNotes(data.generalPreNotes); appStore.setEstimateName(record.name); appStore.setEstimateId(record.id); appStore.setHistory(record.history || []); appStore.setLatestSnapshot(record.items); appStore.setIsLatestVersion(true); // Also clear out the extracted CSV items so we don't accidentally switch back to the upload screen or cause conflicts appStore.setItems([]); props.onClose(); }; return (

Load from Cloud

Loading estimates...
} >
{(record) => (

{record.name}

{new Date(record.created).toLocaleDateString()}

)}
No saved estimates found.
); }; export default CloudLoadModal;