-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
567 additions
and
40 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
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,81 @@ | ||
<script lang="ts"> | ||
import { listTags } from '$lib/dlool/tags/list'; | ||
import { createEventDispatcher } from 'svelte'; | ||
import Modal from '../modal/Modal.svelte'; | ||
import NewTag from './NewTag.svelte'; | ||
import TagButton from './TagButton.svelte'; | ||
import type { Tag } from './types'; | ||
import Store from '../utils/Store.svelte'; | ||
import { i } from '$lib/i18n/store'; | ||
export let className: string; | ||
export let schoolName: string; | ||
export let selected: Tag[] = []; | ||
let isOpen = false; | ||
const dispatch = createEventDispatcher<{ | ||
change: Tag; | ||
}>(); | ||
</script> | ||
|
||
<div class="flex items-center justify-between gap-2"> | ||
<span><Store store={i('tags.choose')} /></span> | ||
|
||
<div class="flex flex-wrap gap-1"> | ||
{#each selected as tag (tag.tag)} | ||
<TagButton | ||
{tag} | ||
removable | ||
on:click={() => (isOpen = !isOpen)} | ||
on:remove={({ detail }) => { | ||
selected = selected.filter(({ tag: t }) => t !== detail.tag); | ||
}} | ||
/> | ||
{/each} | ||
<button | ||
class="rounded-full bg-zinc-200 px-2 py-0.5 outline outline-1 outline-zinc-400 dark:bg-zinc-700 dark:outline-zinc-600" | ||
on:click={() => { | ||
isOpen = !isOpen; | ||
}} | ||
> | ||
<Store store={i('tags.choose.choose')} /> | ||
</button> | ||
</div> | ||
</div> | ||
|
||
<Modal bind:isOpen> | ||
<div slot="title"> | ||
<Store store={i('tags.choose')} /> | ||
</div> | ||
|
||
<div slot="body"> | ||
<div class="flex flex-col"> | ||
<NewTag | ||
{className} | ||
on:create={({ detail }) => { | ||
dispatch('change', detail); | ||
selected = [...selected, { ...detail }]; | ||
isOpen = false; | ||
}} | ||
/> | ||
|
||
<!-- TODO: reload the list when it gets opened again --> | ||
{#await listTags({ school: schoolName, class: className }) then data} | ||
<div class="flex flex-wrap gap-1 py-2"> | ||
{#each data as tag (tag.id)} | ||
<TagButton | ||
{tag} | ||
disabled={selected.some(({ tag: t }) => t === tag.tag)} | ||
on:click={({ detail }) => { | ||
dispatch('change', detail); | ||
selected = [...selected, { ...detail }]; | ||
isOpen = false; | ||
}} | ||
/> | ||
{/each} | ||
</div> | ||
{/await} | ||
</div> | ||
</div> | ||
</Modal> |
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,70 @@ | ||
<script lang="ts"> | ||
import TextInput from '$lib/components/input/Text.svelte'; | ||
import ColorPreview from '../settings/color/ColorPreview.svelte'; | ||
import SettingsButton from '../buttons/SettingsButton.svelte'; | ||
import { createTag } from '$lib/dlool/tags/create'; | ||
import { sendDefaultErrorToast, sendToast } from '../layout/toasts'; | ||
import { createEventDispatcher } from 'svelte'; | ||
import { DEFAULT_SUBJECT_COLOR } from '$lib/constants/settings'; | ||
import { i } from '$lib/i18n/store'; | ||
import Store from '../utils/Store.svelte'; | ||
export let className: string; | ||
let name = ''; | ||
let color = DEFAULT_SUBJECT_COLOR; | ||
let disabled = false; | ||
const dispatch = createEventDispatcher<{ | ||
create: { | ||
tag: string; | ||
color: string; | ||
}; | ||
}>(); | ||
</script> | ||
|
||
<div class="flex flex-col gap-2"> | ||
<div class="flex items-center gap-2"> | ||
<TextInput placeholder={i('tags.new.placeholder')} bind:value={name} /> | ||
<ColorPreview subject={name} bind:hexColor={color} /> | ||
</div> | ||
|
||
<div class="flex w-full"> | ||
<SettingsButton | ||
{disabled} | ||
on:click={async () => { | ||
disabled = true; | ||
await createTag({ | ||
tag: name, | ||
class: className, | ||
color: color.toLowerCase() | ||
}) | ||
.then((e) => { | ||
if (e.status === 'error') { | ||
return sendToast({ | ||
type: 'error', | ||
content: i('tags.new.error.alreadyTaken'), | ||
timeout: 5_000 | ||
}); | ||
} | ||
|
||
sendToast({ | ||
type: 'success', | ||
content: i('tags.new.success', { tag: name }), | ||
timeout: 5_000 | ||
}); | ||
dispatch('create', { | ||
tag: name, | ||
color: color.toLowerCase() | ||
}); | ||
}) | ||
.catch(sendDefaultErrorToast); | ||
|
||
disabled = false; | ||
}} | ||
> | ||
<Store store={i('tags.new.create')} /> | ||
</SettingsButton> | ||
</div> | ||
</div> |
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,31 @@ | ||
<script context="module" lang="ts"> | ||
interface Tag { | ||
tag: string; | ||
color: string; | ||
} | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { createEventDispatcher } from 'svelte'; | ||
import TagLabel from './TagLabel.svelte'; | ||
export let tag: Tag; | ||
export let removable = false; | ||
export let disabled = false; | ||
const dispatch = createEventDispatcher<{ | ||
click: Tag; | ||
}>(); | ||
</script> | ||
|
||
<button | ||
{disabled} | ||
class="disabled:opacity-50" | ||
on:click={() => { | ||
dispatch('click', { tag: tag.tag, color: tag.color }); | ||
}} | ||
> | ||
<TagLabel {tag} {removable} on:remove /> | ||
</button> |
Oops, something went wrong.