aboutsummaryrefslogtreecommitdiff
path: root/static/app.js
diff options
context:
space:
mode:
authorJason McCormick <jason@mfamily.org>2026-10-16 17:43:03 -0400
committerJason McCormick <jason@mfamily.org>2026-10-16 17:43:03 -0400
commit67383e6863fcff8b49e680b5b861b3154f8cb518 (patch)
treed5c09bf85857783eb7a50dfff6cb47e80bd88118 /static/app.js
parent7edb33c87cb1d3ad3421a6fb33247dc871828d7a (diff)
prod 1
Diffstat (limited to 'static/app.js')
-rw-r--r--static/app.js34
1 files changed, 30 insertions, 4 deletions
diff --git a/static/app.js b/static/app.js
index bb09c86..6a93a95 100644
--- a/static/app.js
+++ b/static/app.js
@@ -2,6 +2,12 @@ const MAX_BYTES = 10 * 1024 * 1024;
const ALLOWED_EXTENSIONS = /\.(jpe?g|png|heic)$/i;
const form = document.querySelector('#upload-form');
+const pageTitle = document.querySelector('#page-title');
+const notice = document.querySelector('.notice');
+const requirements = document.querySelector('.requirements');
+const metadataFields = document.querySelector('#metadata-fields');
+const description = document.querySelector('#description');
+const characterCount = document.querySelector('#character-count');
const input = document.querySelector('#image-input');
const dropZone = document.querySelector('#drop-zone');
const fileRow = document.querySelector('#file-row');
@@ -28,6 +34,27 @@ function clearSelection() {
preview.removeAttribute('src');
}
+function showCompletion(message, receipt) {
+ input.value = '';
+ input.disabled = true;
+ fileRow.hidden = true;
+ dropZone.hidden = true;
+ submitButton.hidden = true;
+ removeButton.disabled = true;
+ if (previewUrl) URL.revokeObjectURL(previewUrl);
+ previewUrl = null;
+ preview.removeAttribute('src');
+ pageTitle.textContent = 'Upload complete';
+ notice.textContent = 'Your image was submitted for private review.';
+ requirements.hidden = true;
+ metadataFields.hidden = true;
+ setStatus(`${message} Receipt: ${receipt}`, 'success');
+}
+
+description.addEventListener('input', () => {
+ characterCount.textContent = `${description.value.length} / 1000 characters`;
+});
+
function validate(file) {
if (!file) return 'Choose an image to continue.';
if (!ALLOWED_EXTENSIONS.test(file.name)) return 'Choose a JPG, PNG, or HEIC image.';
@@ -86,19 +113,18 @@ form.addEventListener('submit', async (event) => {
const file = input.files[0];
const error = validate(file);
if (error) { setStatus(error, 'error'); return; }
+ if (!form.reportValidity()) return;
submitButton.disabled = true;
submitButton.querySelector('span').textContent = 'Submitting…';
setStatus('Securely sending your image…');
- const body = new FormData();
- body.append('image', file);
+ const body = new FormData(form);
try {
const response = await fetch(window.location.pathname, { method: 'POST', body });
const result = await response.json();
if (!response.ok) throw new Error(result.message || 'Upload failed.');
- clearSelection();
- setStatus(`${result.message} Receipt: ${result.receipt}`, 'success');
+ showCompletion(result.message, result.receipt);
} catch (error) {
submitButton.disabled = false;
setStatus(error.message || 'Upload failed. Please try again.', 'error');