diff --git a/src/routes/admin/panel/clubs/+page.svelte b/src/routes/admin/panel/clubs/+page.svelte index 85203715..b28d06ba 100644 --- a/src/routes/admin/panel/clubs/+page.svelte +++ b/src/routes/admin/panel/clubs/+page.svelte @@ -22,12 +22,28 @@ } from 'flowbite-svelte-icons'; import ExternalLink from '$components/ExternalLink.svelte'; import EditableClubForm from './EditableClubForm.svelte'; + import type { IClub } from '$api/page_data/clubs/types'; + import type { WithoutID } from '$lib/types/basicTypes'; interface Props { data: PageData; } let { data }: Props = $props(); + function handleImport( + importedClubs: WithoutID[], + currentItems: any[], + updateAll: (items: WithoutID[]) => void + ) { + const existingClubs = currentItems.map((wrapper) => wrapper.item); + const merged = [ + ...existingClubs, + ...importedClubs.filter( + (imp) => !existingClubs.some((ex) => ex.name.toLowerCase() === imp.name.toLowerCase()) + ), + ]; + updateAll(merged); + }
@@ -51,9 +67,17 @@ {#snippet renderItems({ items, openCreateForm, updateAll })}
- + { + if (overwrite) { + updateAll(importedClubs); + } else { + const existing = items.map((i) => i.item); + updateAll([...existing, ...importedClubs]); + } + }} + />
- Name diff --git a/src/routes/admin/panel/clubs/AutoImportClubsButton.svelte b/src/routes/admin/panel/clubs/AutoImportClubsButton.svelte index 710788d9..72989043 100644 --- a/src/routes/admin/panel/clubs/AutoImportClubsButton.svelte +++ b/src/routes/admin/panel/clubs/AutoImportClubsButton.svelte @@ -2,7 +2,7 @@ import ValidatedInput from '$components/form/ValidatedInput.svelte'; import ValidatedTextarea from '$components/form/ValidatedTextarea.svelte'; import ExternalLink from '$components/ExternalLink.svelte'; - import { GradientButton, Helper, Modal, Tooltip } from 'flowbite-svelte'; + import { GradientButton, Helper, Modal, Tooltip, Checkbox } from 'flowbite-svelte'; import { InfoCircleOutline } from 'flowbite-svelte-icons'; import { string } from 'yup'; import Papa from 'papaparse'; @@ -15,7 +15,7 @@ https://lhs.cx/old-clubs */ interface Props { - onSubmit: (clubs: WithoutID[]) => void; + onSubmit: (clubs: WithoutID[], overwrite: boolean) => void; } let { onSubmit: submit }: Props = $props(); @@ -23,7 +23,7 @@ https://lhs.cx/old-clubs const notificationContext = getNotificationContext(); let modalOpen = $state(false); - + let overwriteCheckbox = $state(false); let startInput: ValidatedInput | undefined = $state(); let endInput: ValidatedInput | undefined = $state(); let csvInput: ValidatedTextarea | undefined = $state(); @@ -84,7 +84,7 @@ https://lhs.cx/old-clubs }, complete() { notificationContext.show('Imported ' + records.length + ' clubs', 'success'); - submit(records); + submit(records, overwriteCheckbox); modalOpen = false; }, }); @@ -143,6 +143,9 @@ https://lhs.cx/old-clubs /> + + Overwrite existing clubs +
- Note: This will overwrite everything already in the table. Import