From b592452557a3043547049de67c145e5f340585ce Mon Sep 17 00:00:00 2001 From: Nick Doiron Date: Sun, 2 Feb 2025 21:41:27 -0600 Subject: [PATCH] allow multiple uploads, show links in sidebar --- app/src/app/uploader/page.tsx | 123 ++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 57 deletions(-) diff --git a/app/src/app/uploader/page.tsx b/app/src/app/uploader/page.tsx index 691901cd..1ace2ad7 100644 --- a/app/src/app/uploader/page.tsx +++ b/app/src/app/uploader/page.tsx @@ -6,10 +6,15 @@ import {GerryDBViewSelector} from '../components/sidebar/GerryDBViewSelector'; import {useMapStore} from '@/app/store/mapStore'; import {Assignment, createMapDocument, patchUpdateAssignments} from '@/app/utils/api/apiHandlers'; +type MapLink = { + document_id: string; + name: string; +}; + export default function Uploader() { - const [progress, setProgress] = useState(0); - const [totalRows, setTotalRows] = useState(0); - const [mapLink, setMapLink] = useState(''); + const [progress, setProgress] = useState(0); + const [totalRows, setTotalRows] = useState(0); + const [mapLinks, setMapLinks] = useState([]); const ROWS_PER_BATCH = 2000; @@ -48,7 +53,7 @@ export default function Uploader() { setProgress(rowCursor + assignments.length); rowCursor += ROWS_PER_BATCH; if (rowCursor > results.data.length) { - setMapLink(document_id); + setMapLinks([...mapLinks, {document_id, name: file.name}]); } else { setTimeout(partialUploadStep, 10); } @@ -76,63 +81,67 @@ export default function Uploader() { return (
-
- +
+
+ - {totalRows ? ( -
-
- {progress === 0 ? 'Initializing map...' : null} - {mapLink !== '' ? ( - - Uploaded to {mapLink} - - ) : null} -
-
- - {progress}/{totalRows} rows - - {Math.round((progress / totalRows) * 100)}% + {totalRows ? ( +
+
{progress === 0 ? 'Initializing map...' : null}
+
+ + {progress}/{totalRows} rows + + {Math.round((progress / totalRows) * 100)}% +
+
+
+
-
-
-
-
- ) : null} + ) : null} -

Upload CSV

- -
- +

Upload CSV

+ +
+ +
+ + +

Or drag and drop a file here

- - -

Or drag and drop a file here

+ {mapLinks.length > 0 ? ( +
+

Uploads

+ {mapLinks.map(map => ( + + {map.name} + + ))} +
+ ) : null}
);