Keep selections across pages; download all selected
Browse files- src/routes/index.tsx +16 -9
src/routes/index.tsx
CHANGED
|
@@ -57,7 +57,7 @@ function Grabber() {
|
|
| 57 |
console.log("[hardCap] set to", v);
|
| 58 |
};
|
| 59 |
const [page, setPage] = useState(1);
|
| 60 |
-
const [selected, setSelected] = useState<
|
| 61 |
const [addOpen, setAddOpen] = useState(false);
|
| 62 |
const [lightbox, setLightbox] = useState<NormalizedPost | null>(null);
|
| 63 |
const [downloading, setDownloading] = useState(false);
|
|
@@ -261,26 +261,32 @@ function Grabber() {
|
|
| 261 |
|
| 262 |
const runSearch = (p: number) => {
|
| 263 |
setPage(p);
|
| 264 |
-
|
| 265 |
searchMut.mutate({ page: p });
|
| 266 |
};
|
| 267 |
|
| 268 |
const toggle = (id: string) => {
|
| 269 |
setSelected((prev) => {
|
| 270 |
-
const n = new
|
|
|
|
| 271 |
if (n.has(id)) n.delete(id);
|
| 272 |
-
else n.
|
| 273 |
return n;
|
| 274 |
});
|
| 275 |
};
|
| 276 |
|
| 277 |
const selectAll = () => {
|
| 278 |
-
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
};
|
| 281 |
|
| 282 |
const downloadZip = async () => {
|
| 283 |
-
const chosen =
|
| 284 |
if (!chosen.length) return;
|
| 285 |
setDownloading(true);
|
| 286 |
try {
|
|
@@ -329,7 +335,7 @@ function Grabber() {
|
|
| 329 |
};
|
| 330 |
|
| 331 |
const uploadToDataset = async () => {
|
| 332 |
-
const chosen =
|
| 333 |
if (!chosen.length) {
|
| 334 |
alert("Please select some images to upload.");
|
| 335 |
return;
|
|
@@ -500,9 +506,10 @@ function Grabber() {
|
|
| 500 |
</Button>
|
| 501 |
</div>
|
| 502 |
<Button variant="outline" size="sm" onClick={selectAll} disabled={!posts.length}>
|
| 503 |
-
{
|
| 504 |
</Button>
|
| 505 |
<span className="text-sm text-muted-foreground">selected: {selected.size}</span>
|
|
|
|
| 506 |
<Select value={downloadType} onValueChange={(val: "original" | "sample") => setDownloadType(val)}>
|
| 507 |
<SelectTrigger className="w-36">
|
| 508 |
<SelectValue />
|
|
|
|
| 57 |
console.log("[hardCap] set to", v);
|
| 58 |
};
|
| 59 |
const [page, setPage] = useState(1);
|
| 60 |
+
const [selected, setSelected] = useState<Map<string, NormalizedPost>>(new Map());
|
| 61 |
const [addOpen, setAddOpen] = useState(false);
|
| 62 |
const [lightbox, setLightbox] = useState<NormalizedPost | null>(null);
|
| 63 |
const [downloading, setDownloading] = useState(false);
|
|
|
|
| 261 |
|
| 262 |
const runSearch = (p: number) => {
|
| 263 |
setPage(p);
|
| 264 |
+
// keep selections across pages
|
| 265 |
searchMut.mutate({ page: p });
|
| 266 |
};
|
| 267 |
|
| 268 |
const toggle = (id: string) => {
|
| 269 |
setSelected((prev) => {
|
| 270 |
+
const n = new Map(prev);
|
| 271 |
+
const post = posts.find((x) => x.id === id);
|
| 272 |
if (n.has(id)) n.delete(id);
|
| 273 |
+
else if (post) n.set(id, post);
|
| 274 |
return n;
|
| 275 |
});
|
| 276 |
};
|
| 277 |
|
| 278 |
const selectAll = () => {
|
| 279 |
+
const allOnPage = posts.length > 0 && posts.every((p) => selected.has(p.id));
|
| 280 |
+
setSelected((prev) => {
|
| 281 |
+
const n = new Map(prev);
|
| 282 |
+
if (allOnPage) posts.forEach((p) => n.delete(p.id));
|
| 283 |
+
else posts.forEach((p) => n.set(p.id, p));
|
| 284 |
+
return n;
|
| 285 |
+
});
|
| 286 |
};
|
| 287 |
|
| 288 |
const downloadZip = async () => {
|
| 289 |
+
const chosen = Array.from(selected.values());
|
| 290 |
if (!chosen.length) return;
|
| 291 |
setDownloading(true);
|
| 292 |
try {
|
|
|
|
| 335 |
};
|
| 336 |
|
| 337 |
const uploadToDataset = async () => {
|
| 338 |
+
const chosen = Array.from(selected.values());
|
| 339 |
if (!chosen.length) {
|
| 340 |
alert("Please select some images to upload.");
|
| 341 |
return;
|
|
|
|
| 506 |
</Button>
|
| 507 |
</div>
|
| 508 |
<Button variant="outline" size="sm" onClick={selectAll} disabled={!posts.length}>
|
| 509 |
+
{posts.length > 0 && posts.every((p) => selected.has(p.id)) ? "Deselect page" : "Select page"}
|
| 510 |
</Button>
|
| 511 |
<span className="text-sm text-muted-foreground">selected: {selected.size}</span>
|
| 512 |
+
{selected.size > 0 && (<Button variant="ghost" size="sm" onClick={() => setSelected(new Map())}>Clear selection</Button>)}
|
| 513 |
<Select value={downloadType} onValueChange={(val: "original" | "sample") => setDownloadType(val)}>
|
| 514 |
<SelectTrigger className="w-36">
|
| 515 |
<SelectValue />
|