Skip to content

Commit

Permalink
fix: improve mapping validation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
davidemarcoli committed Nov 22, 2024
1 parent af4b2fb commit 3df8f76
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/lib/components/media-file-selector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
...extractSeasonEpisode(containerFile.filename)
};
});
validateMappings();
step = 4;
}
function extractSeasonEpisode(filename: string): { season?: number; episode?: number } {
Expand All @@ -166,16 +167,24 @@
return {};
}
let isValidMapping = false;
function validateMappings(): boolean {
if (mediaType === 'movie') return true;
if (mediaType === 'movie') {
isValidMapping = true;
return true;
}
return selectedFilesMappings.every(
const isValid = selectedFilesMappings.every(
(file) =>
typeof file.season === 'number' &&
typeof file.episode === 'number' &&
file.season > 0 &&
file.episode > 0
);
isValidMapping = isValid;
return isValid;
}
async function updateAttributes() {
Expand Down Expand Up @@ -484,14 +493,15 @@
<Card.Root class="w-full min-w-0">
<Card.Content class="p-4">
<div class="grid gap-4">
<div class="flex items-center gap-2">
<div class="flex items-center gap-2 overflow-auto">
<FileIcon class="h-4 w-4 flex-shrink-0" />
<span class="flex-1 truncate">{file.filename}</span>
<button
on:click={() => {
selectedFilesMappings = selectedFilesMappings.filter(
(f) => f.id !== file.id
);
validateMappings();
}}
>
<CircleX
Expand Down Expand Up @@ -530,7 +540,7 @@

<Button
on:click={updateAttributes}
disabled={loading || !validateMappings()}
disabled={loading || !isValidMapping}
class="mt-4 w-full"
>
{#if loading}
Expand Down

0 comments on commit 3df8f76

Please sign in to comment.