diff --git a/components/PhotoDeleteDialog.vue b/components/PhotoDeleteDialog.vue new file mode 100644 index 0000000..d1f7d04 --- /dev/null +++ b/components/PhotoDeleteDialog.vue @@ -0,0 +1,93 @@ + + + diff --git a/components/PhotoTile.vue b/components/PhotoTile.vue new file mode 100644 index 0000000..c50fd9d --- /dev/null +++ b/components/PhotoTile.vue @@ -0,0 +1,103 @@ + + + diff --git a/components/PhotoUploader.vue b/components/PhotoUploader.vue new file mode 100644 index 0000000..50cf81e --- /dev/null +++ b/components/PhotoUploader.vue @@ -0,0 +1,178 @@ + + + diff --git a/components/SpaceHint.vue b/components/SpaceHint.vue index c3f7ee2..9197ccb 100644 --- a/components/SpaceHint.vue +++ b/components/SpaceHint.vue @@ -1,7 +1,7 @@ diff --git a/stores/photoUpload.ts b/stores/photoUpload.ts new file mode 100644 index 0000000..3834ff4 --- /dev/null +++ b/stores/photoUpload.ts @@ -0,0 +1,61 @@ +export type UploadStep = 'preparing' | 'reserving' | 'uploading' | 'confirming' + +export interface UploadJob { + // The person who chose the photo. + owner: string + // The prepared JPEG. + file: Blob + // The place reserved in storage, once there is one. + reservation?: { uploadId: string, path: string, token: string, reservedAt: number } + // True once the file was sent: it may be in storage. + sent: boolean +} + +// The upload in progress. It lives here, so that leaving the page neither stops it nor +// loses the chance to try again. The steps are in composables/usePhotoUpload.ts. +export const usePhotoUploadStore = defineStore('photoUpload', () => { + const session = useSessionStore() + + const job = ref() + // Set while a step is running. + const step = ref() + // The step that failed, with a message key. + const failure = ref<{ step: UploadStep, messageKey: string }>() + // Why a chosen file was not accepted. + const selectionError = ref() + // Counts finished uploads, so that the gallery can load again. + const completed = ref(0) + + function clear() { + job.value = undefined + step.value = undefined + failure.value = undefined + selectionError.value = undefined + } + + // The next person on this device must never continue somebody else's upload. + watch(() => session.user?.id, (_id, previous) => { + // Nothing to forget when the session is read for the first time. + if (previous !== undefined) { + clear() + } + }, { flush: 'sync' }) + + // Closing or reloading the tab would lose an unfinished upload, so the browser asks first. + function askBeforeClosing(event: BeforeUnloadEvent) { + event.preventDefault() + } + + watch(() => Boolean(step.value || job.value), (unfinished) => { + if (unfinished) { + window.addEventListener('beforeunload', askBeforeClosing) + } + else { + window.removeEventListener('beforeunload', askBeforeClosing) + } + }, { flush: 'sync' }) + + onScopeDispose(() => window.removeEventListener('beforeunload', askBeforeClosing)) + + return { job, step, failure, selectionError, completed, clear } +})