Skip to content

Commit

Permalink
add toggled state for editing problems
Browse files Browse the repository at this point in the history
  • Loading branch information
kjubik committed Aug 10, 2023
1 parent fae455c commit dd62fea
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions odyseja-ui/src/routes/panel/problem/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { saveProblems } from '../apiService';
import type { Problems } from '../types';
import {init} from "svelte/internal";
export let data: Problems;
Expand All @@ -11,20 +12,41 @@
function save() {
saveProblems(data);
initialData = JSON.parse(JSON.stringify(data));
toggleEdit();
}
let editToggled = false
function toggleEdit() {
editToggled = !editToggled;
editToggled = editToggled;
}
function cancelChanges() {
toggleEdit();
data = JSON.parse(JSON.stringify(initialData));
}
</script>

<section class="p-4">
<div class="flex justify-between items-center max-w-2xl">
<h2 class="mb-6">Problemy</h2>
<button type="button" on:click={toggleEdit} class="btn btn-md variant-filled-primary"
disabled='{editToggled}'>Edytuj</button>
</div>
{#each data.problems as problem}
<label class="label m-4">
<span>Problem nr. {problem.id}</span>
<input class="input" type="text" placeholder="Input" bind:value={problem.name}/>
<label class="label py-3 flex items-center max-w-2xl">
<span class="text-2xl font-semibold pr-4">{problem.id}</span>
<input class="input text-xl" type="text" placeholder="Input" bind:value={problem.name} disabled="{!editToggled}"/>
</label>
{/each}
</section>

<footer class="pl-8">
<button type="button" on:click={save} disabled='{!isChanged}' class="btn btn-md variant-filled-primary">
<button type="button" on:click={save} disabled='{!isChanged}' class="btn btn-md variant-filled-secondary">
Zapisz
</button>
<button type="button" on:click={cancelChanges} disabled='{!editToggled}' class="btn btn-md variant-ringed-surface">
Anuluj
</button>
</footer>

0 comments on commit dd62fea

Please sign in to comment.