|
1 | 1 | <script lang="ts"> |
2 | 2 | import { tagAssets } from '$lib/utils/asset-utils'; |
3 | 3 | import { getAllTags, upsertTags, type TagResponseDto } from '@immich/sdk'; |
4 | | - import { Button, HStack, Icon, Modal, ModalBody, ModalFooter } from '@immich/ui'; |
| 4 | + import { FormModal, Icon } from '@immich/ui'; |
5 | 5 | import { mdiClose, mdiTag } from '@mdi/js'; |
6 | 6 | import { onMount } from 'svelte'; |
7 | 7 | import { t } from 'svelte-i18n'; |
|
25 | 25 | allTags = await getAllTags(); |
26 | 26 | }); |
27 | 27 |
|
28 | | - const handleSubmit = async () => { |
| 28 | + const onSubmit = async () => { |
| 29 | + if (selectedIds.size === 0) { |
| 30 | + return; |
| 31 | + } |
| 32 | +
|
29 | 33 | await tagAssets({ tagIds: [...selectedIds], assetIds, showNotification: false }); |
30 | 34 | onClose(true); |
31 | 35 | }; |
|
47 | 51 | const handleRemove = (tag: string) => { |
48 | 52 | selectedIds.delete(tag); |
49 | 53 | }; |
50 | | -
|
51 | | - const onsubmit = async (event: Event) => { |
52 | | - event.preventDefault(); |
53 | | - await handleSubmit(); |
54 | | - }; |
55 | 54 | </script> |
56 | 55 |
|
57 | | -<Modal size="small" title={$t('tag_assets')} icon={mdiTag} {onClose}> |
58 | | - <ModalBody> |
59 | | - <form {onsubmit} autocomplete="off" id="create-tag-form"> |
60 | | - <div class="my-4 flex flex-col gap-2"> |
61 | | - <Combobox |
62 | | - onSelect={handleSelect} |
63 | | - label={$t('tag')} |
64 | | - {allowCreate} |
65 | | - defaultFirstOption |
66 | | - options={allTags.map((tag) => ({ id: tag.id, label: tag.value, value: tag.id }))} |
67 | | - placeholder={$t('search_tags')} |
68 | | - forceFocus |
69 | | - /> |
70 | | - </div> |
71 | | - </form> |
72 | | - |
73 | | - <section class="flex flex-wrap pt-2 gap-1"> |
74 | | - {#each selectedIds as tagId (tagId)} |
75 | | - {@const tag = tagMap[tagId]} |
76 | | - {#if tag} |
77 | | - <div class="flex group transition-all"> |
78 | | - <span |
79 | | - class="inline-block h-min whitespace-nowrap ps-3 pe-1 group-hover:ps-3 py-1 text-center align-baseline leading-none text-gray-100 dark:text-immich-dark-gray bg-primary roudned-s-full hover:bg-immich-primary/80 dark:hover:bg-immich-dark-primary/80 transition-all" |
80 | | - > |
81 | | - <p class="text-sm"> |
82 | | - {tag.value} |
83 | | - </p> |
84 | | - </span> |
| 56 | +<FormModal |
| 57 | + size="small" |
| 58 | + title={$t('tag_assets')} |
| 59 | + icon={mdiTag} |
| 60 | + {onClose} |
| 61 | + {onSubmit} |
| 62 | + submitText={$t('tag_assets')} |
| 63 | + {disabled} |
| 64 | +> |
| 65 | + <div class="my-4 flex flex-col gap-2"> |
| 66 | + <Combobox |
| 67 | + onSelect={handleSelect} |
| 68 | + label={$t('tag')} |
| 69 | + {allowCreate} |
| 70 | + defaultFirstOption |
| 71 | + options={allTags.map((tag) => ({ id: tag.id, label: tag.value, value: tag.id }))} |
| 72 | + placeholder={$t('search_tags')} |
| 73 | + forceFocus |
| 74 | + /> |
| 75 | + </div> |
85 | 76 |
|
86 | | - <button |
87 | | - type="button" |
88 | | - class="text-gray-100 dark:text-immich-dark-gray bg-immich-primary/95 dark:bg-immich-dark-primary/95 rounded-e-full place-items-center place-content-center pe-2 ps-1 py-1 hover:bg-immich-primary/80 dark:hover:bg-immich-dark-primary/80 transition-all" |
89 | | - title={$t('remove_tag')} |
90 | | - onclick={() => handleRemove(tagId)} |
91 | | - > |
92 | | - <Icon icon={mdiClose} /> |
93 | | - </button> |
94 | | - </div> |
95 | | - {/if} |
96 | | - {/each} |
97 | | - </section> |
98 | | - </ModalBody> |
| 77 | + <section class="flex flex-wrap pt-2 gap-1"> |
| 78 | + {#each selectedIds as tagId (tagId)} |
| 79 | + {@const tag = tagMap[tagId]} |
| 80 | + {#if tag} |
| 81 | + <div class="flex group transition-all"> |
| 82 | + <span |
| 83 | + class="inline-block h-min whitespace-nowrap ps-3 pe-1 group-hover:ps-3 py-1 text-center align-baseline leading-none text-gray-100 dark:text-immich-dark-gray bg-primary roudned-s-full hover:bg-immich-primary/80 dark:hover:bg-immich-dark-primary/80 transition-all" |
| 84 | + > |
| 85 | + <p class="text-sm"> |
| 86 | + {tag.value} |
| 87 | + </p> |
| 88 | + </span> |
99 | 89 |
|
100 | | - <ModalFooter> |
101 | | - <HStack fullWidth> |
102 | | - <Button shape="round" fullWidth color="secondary" onclick={() => onClose()}>{$t('cancel')}</Button> |
103 | | - <Button type="submit" shape="round" fullWidth form="create-tag-form" {disabled}>{$t('tag_assets')}</Button> |
104 | | - </HStack> |
105 | | - </ModalFooter> |
106 | | -</Modal> |
| 90 | + <button |
| 91 | + type="button" |
| 92 | + class="text-gray-100 dark:text-immich-dark-gray bg-immich-primary/95 dark:bg-immich-dark-primary/95 rounded-e-full place-items-center place-content-center pe-2 ps-1 py-1 hover:bg-immich-primary/80 dark:hover:bg-immich-dark-primary/80 transition-all" |
| 93 | + title={$t('remove_tag')} |
| 94 | + onclick={() => handleRemove(tagId)} |
| 95 | + > |
| 96 | + <Icon icon={mdiClose} /> |
| 97 | + </button> |
| 98 | + </div> |
| 99 | + {/if} |
| 100 | + {/each} |
| 101 | + </section> |
| 102 | +</FormModal> |
0 commit comments