diff --git a/src/lib/components/QuickCapture.svelte b/src/lib/components/QuickCapture.svelte index a0c17a8..8dfd388 100644 --- a/src/lib/components/QuickCapture.svelte +++ b/src/lib/components/QuickCapture.svelte @@ -6,26 +6,84 @@ let content = $state(''); let type = $state<'task' | 'thought'>('thought'); + // Pending image state + let pendingImage: File | null = $state(null); + let pendingPreviewUrl: string | null = $state(null); + let isUploading = $state(false); + let fileInput: HTMLInputElement; + // Initialize from preferences (client-side only) $effect(() => { if (typeof window !== 'undefined') { type = $preferences.lastEntryType; } }); + + function handleImageSelect(e: Event) { + const input = e.target as HTMLInputElement; + const file = input.files?.[0]; + if (file && file.type.startsWith('image/')) { + // Revoke previous preview if exists + if (pendingPreviewUrl) { + URL.revokeObjectURL(pendingPreviewUrl); + } + pendingImage = file; + pendingPreviewUrl = URL.createObjectURL(file); + } + // Reset input so same file can be selected again + input.value = ''; + } + + function clearPendingImage() { + if (pendingPreviewUrl) { + URL.revokeObjectURL(pendingPreviewUrl); + } + pendingImage = null; + pendingPreviewUrl = null; + } + + async function uploadImageForEntry(entryId: string, file: File) { + const formData = new FormData(); + formData.append('image', file); + formData.append('entryId', entryId); + + const response = await fetch('?/uploadImage', { + method: 'POST', + body: formData + }); + + const result = await response.json(); + if (result.type === 'failure') { + console.error('Image upload failed:', result.data?.error); + } + }