Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/routes/admin/panel/clubs/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is never used

importedClubs: WithoutID<IClub>[],
currentItems: any[],
updateAll: (items: WithoutID<IClub>[]) => 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);
}
</script>

<div class="flex flex-col items-center p-4">
Expand All @@ -51,9 +67,17 @@
{#snippet renderItems({ items, openCreateForm, updateAll })}
<div class="mb-8 flex justify-center gap-8">
<Button color="alternative" on:click={openCreateForm}>Add Club</Button>
<AutoImportClubsButton onSubmit={updateAll} />
<AutoImportClubsButton
onSubmit={(importedClubs, overwrite) => {
if (overwrite) {
updateAll(importedClubs);
} else {
const existing = items.map((i) => i.item);
updateAll([...existing, ...importedClubs]);
}
}}
/>
</div>

<Table striped shadow class="min-w-[1024px] table-fixed">
<TableHead>
<TableHeadCell>Name</TableHeadCell>
Expand Down
12 changes: 7 additions & 5 deletions src/routes/admin/panel/clubs/AutoImportClubsButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -15,15 +15,15 @@ https://lhs.cx/old-clubs
*/

interface Props {
onSubmit: (clubs: WithoutID<IClub>[]) => void;
onSubmit: (clubs: WithoutID<IClub>[], overwrite: boolean) => void;
}

let { onSubmit: submit }: Props = $props();

const notificationContext = getNotificationContext();

let modalOpen = $state(false);

let overwriteCheckbox = $state(false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overwriteCheckbox sounds like you are over writing a checkbox overwriteClubs would be better

let startInput: ValidatedInput | undefined = $state();
let endInput: ValidatedInput | undefined = $state();
let csvInput: ValidatedTextarea | undefined = $state();
Expand Down Expand Up @@ -84,7 +84,7 @@ https://lhs.cx/old-clubs
},
complete() {
notificationContext.show('Imported ' + records.length + ' clubs', 'success');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer accurate to the amount of clubs that are actually imported

submit(records);
submit(records, overwriteCheckbox);
modalOpen = false;
},
});
Expand Down Expand Up @@ -143,6 +143,9 @@ https://lhs.cx/old-clubs
/>
</div>
</div>
<Checkbox bind:checked={overwriteCheckbox} id="overwrite">
<span class="text-amber-500 dark:text-amber-600">Overwrite existing clubs</span>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amber looks good on light mode but it looks bad on darkmode. maybe a lighter color would work better for darkmode.

</Checkbox>
<div class="w-full">
<ValidatedTextarea
bind:this={csvInput}
Expand All @@ -160,7 +163,6 @@ https://lhs.cx/old-clubs
}}
/>
</div>
<Helper>Note: This will overwrite everything already in the table.</Helper>
<GradientButton type="submit" color="purpleToPink">Import</GradientButton>
</form>
</Modal>
Loading