This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Dennis Trümper <[email protected]>
- Loading branch information
1 parent
f9da45f
commit 5d73020
Showing
7 changed files
with
138 additions
and
5 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,95 @@ | ||
<script lang="ts"> | ||
import { afterNavigate, goto } from '$app/navigation'; | ||
import { base } from '$app/paths'; | ||
import toast from 'svelte-french-toast'; | ||
import ActionBar from '../../../../components/actionBar.svelte'; | ||
import FadeIn from '../../../../components/animation/fadeIn.svelte'; | ||
import ActionBarBackButton from '../../../../components/buttons/actionBarBackButton.svelte'; | ||
import ActionBarButton from '../../../../components/buttons/actionBarButton.svelte'; | ||
import MultilineTextInput from '../../../../components/form/multilineTextInput.svelte'; | ||
import TextInput from '../../../../components/form/textInput.svelte'; | ||
import { appStore } from '../../../../stores/appStore'; | ||
import { titleStore } from '../../../../stores/titleStore'; | ||
import { textColor } from '../../../../theme'; | ||
import { Routes } from '../../../routes'; | ||
let previousPage: string = base; | ||
afterNavigate((input) => { | ||
previousPage = input.from?.url.pathname ?? base; | ||
}); | ||
export let data; | ||
const isInvalidItem = | ||
data.itemId === undefined || | ||
!$appStore.current.items.map((item) => item.id).includes(data.itemId ?? ''); | ||
if (isInvalidItem) { | ||
toast.error(`Item not found`, { | ||
position: 'bottom-center' | ||
}); | ||
goto(Routes.items); | ||
} | ||
titleStore.set({ title: 'Edit Item', listChooseMode: false }); | ||
let itemRaw = $appStore.current.items.find((item) => item.id === data.itemId); | ||
let itemName = itemRaw?.name; | ||
let description = itemRaw?.description; | ||
function validateForm(name: string | undefined): boolean { | ||
if (name !== undefined && name?.length > 0) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
</script> | ||
|
||
<FadeIn> | ||
<form> | ||
<div class="space-y-4 sm:space-y-8 {textColor}"> | ||
<TextInput | ||
placeholder="Name of your new item" | ||
caption="Name" | ||
name="name" | ||
bind:value={itemName} | ||
/> | ||
<MultilineTextInput | ||
bind:value={description} | ||
name="description" | ||
rows={3} | ||
caption="Description" | ||
/> | ||
</div> | ||
</form> | ||
</FadeIn> | ||
|
||
<ActionBar> | ||
<div class="w-full h-full flex items-center justify-between px-16"> | ||
<ActionBarBackButton /> | ||
<ActionBarButton | ||
onClick={() => { | ||
if (validateForm(itemName)) { | ||
appStore.dispatch({ | ||
type: 'edit_item', | ||
itemId: data.itemId ?? '', | ||
name: itemName ?? '', | ||
description: description | ||
}); | ||
toast.success(`Item updated: ${itemName}`, { | ||
position: 'bottom-center' | ||
}); | ||
itemName = undefined; | ||
description = undefined; | ||
goto(previousPage); | ||
} else { | ||
toast.error(`Please enter a name`, { | ||
position: 'bottom-center' | ||
}); | ||
} | ||
}} | ||
> | ||
Save | ||
</ActionBarButton> | ||
</div> | ||
</ActionBar> |
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,6 @@ | ||
import type { LoadEvent } from '@sveltejs/kit'; | ||
export const load = (input: LoadEvent) => { | ||
return { | ||
itemId: input.params.itemId | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export const load = ({ params }) => { | ||
import type { LoadEvent } from '@sveltejs/kit'; | ||
export const load = (input: LoadEvent) => { | ||
return { | ||
listId: params.listId | ||
listId: input.params.listId | ||
}; | ||
}; |
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