-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added the ability to import and export exercise splits
- Loading branch information
1 parent
5e554ec
commit e4d1a40
Showing
4 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<script lang="ts"> | ||
import { Button } from '$lib/components/ui/button'; | ||
import { Input } from '$lib/components/ui/input'; | ||
import { Label } from '$lib/components/ui/label'; | ||
import H2 from '$lib/components/ui/typography/H2.svelte'; | ||
import H3 from '$lib/components/ui/typography/H3.svelte'; | ||
import { | ||
ExerciseSplitCreateWithoutUserInputSchema, | ||
ExerciseSplitDayCreateWithoutExerciseSplitInputSchema, | ||
ExerciseTemplateCreateWithoutExerciseSplitDayInputSchema | ||
} from '$lib/zodSchemas'; | ||
import { toast } from 'svelte-sonner'; | ||
import { exerciseSplitRunes } from '../manage/exerciseSplitRunes.svelte'; | ||
import { goto } from '$app/navigation'; | ||
let splitFile = $state<File>(); | ||
async function validateAndImportSplit() { | ||
if (!splitFile) return; | ||
try { | ||
const splitData = JSON.parse(await splitFile.text()); | ||
const { exerciseSplitDays, ...split } = splitData; | ||
ExerciseSplitCreateWithoutUserInputSchema.parse(split); | ||
exerciseSplitDays.forEach((data: { [x: string]: unknown; exercises: unknown[] }) => { | ||
const { exercises, ...splitDay } = data; | ||
ExerciseSplitDayCreateWithoutExerciseSplitInputSchema.parse(splitDay); | ||
exercises.forEach((data) => { | ||
ExerciseTemplateCreateWithoutExerciseSplitDayInputSchema.parse(data); | ||
}); | ||
}); | ||
exerciseSplitRunes.loadExerciseSplit(splitData); | ||
goto('/exercise-splits/manage/structure'); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
toast.error(error.message); | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<H2>Exercise splits</H2> | ||
<H3>Import</H3> | ||
|
||
<div class="grid w-full items-center gap-1.5"> | ||
<Label for="picture">Exercise split JSON file</Label> | ||
<Input | ||
id="picture" | ||
type="file" | ||
accept=".json" | ||
onchange={(e) => { | ||
const file = e.currentTarget.files?.item(0); | ||
if (file) splitFile = file; | ||
}} | ||
/> | ||
</div> | ||
|
||
<Button class="mt-auto" onclick={validateAndImportSplit}>Import</Button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters