fix: enter now submits the date modals (#25053)

* fix: enter now submits the date modals

* use FormModal

* apply prettier

* fix unit test
This commit is contained in:
fabb 2026-01-06 16:08:54 +01:00 committed by GitHub
parent c411151560
commit 4cb56edebf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 111 additions and 114 deletions

View file

@ -5,7 +5,7 @@
import { getPreferredTimeZone, getTimezones, toIsoDate } from '$lib/modals/timezone-utils'; import { getPreferredTimeZone, getTimezones, toIsoDate } from '$lib/modals/timezone-utils';
import { handleError } from '$lib/utils/handle-error'; import { handleError } from '$lib/utils/handle-error';
import { updateAsset } from '@immich/sdk'; import { updateAsset } from '@immich/sdk';
import { Button, HStack, Label, Modal, ModalBody, ModalFooter } from '@immich/ui'; import { FormModal, Label } from '@immich/ui';
import { mdiCalendarEdit } from '@mdi/js'; import { mdiCalendarEdit } from '@mdi/js';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import { t } from 'svelte-i18n'; import { t } from 'svelte-i18n';
@ -28,7 +28,7 @@
// the offsets (and validity) for time zones may change if the date is changed, which is why we recompute the list // the offsets (and validity) for time zones may change if the date is changed, which is why we recompute the list
let selectedOption = $derived(getPreferredTimeZone(initialDate, initialTimeZone, timezones, lastSelectedTimezone)); let selectedOption = $derived(getPreferredTimeZone(initialDate, initialTimeZone, timezones, lastSelectedTimezone));
const handleClose = async () => { const onSubmit = async () => {
if (!date.isValid || !selectedOption) { if (!date.isValid || !selectedOption) {
onClose(false); onClose(false);
return; return;
@ -49,8 +49,15 @@
const date = $derived(DateTime.fromISO(selectedDate, { zone: selectedOption?.value, setZone: true })); const date = $derived(DateTime.fromISO(selectedDate, { zone: selectedOption?.value, setZone: true }));
</script> </script>
<Modal title={$t('edit_date_and_time')} icon={mdiCalendarEdit} onClose={() => onClose(false)} size="small"> <FormModal
<ModalBody> title={$t('edit_date_and_time')}
icon={mdiCalendarEdit}
onClose={() => onClose(false)}
{onSubmit}
submitText={$t('confirm')}
disabled={!date.isValid || !selectedOption}
size="small"
>
<Label for="datetime" class="block mb-1">{$t('date_and_time')}</Label> <Label for="datetime" class="block mb-1">{$t('date_and_time')}</Label>
<DateInput <DateInput
class="immich-form-input text-gray-700 w-full mb-2" class="immich-form-input text-gray-700 w-full mb-2"
@ -63,11 +70,4 @@
<Combobox bind:selectedOption label={$t('timezone')} options={timezones} placeholder={$t('search_timezone')} /> <Combobox bind:selectedOption label={$t('timezone')} options={timezones} placeholder={$t('search_timezone')} />
</div> </div>
{/if} {/if}
</ModalBody> </FormModal>
<ModalFooter>
<HStack fullWidth>
<Button shape="round" color="secondary" fullWidth onclick={() => onClose(false)}>{$t('cancel')}</Button>
<Button shape="round" type="submit" fullWidth onclick={handleClose}>{$t('confirm')}</Button>
</HStack>
</ModalFooter>
</Modal>

View file

@ -17,8 +17,8 @@ describe('DateSelectionModal component', () => {
const getRelativeInputToggle = () => screen.getByTestId('edit-by-offset-switch'); const getRelativeInputToggle = () => screen.getByTestId('edit-by-offset-switch');
const getDateInput = () => screen.getByLabelText('date_and_time') as HTMLInputElement; const getDateInput = () => screen.getByLabelText('date_and_time') as HTMLInputElement;
const getTimeZoneInput = () => screen.getByLabelText('timezone') as HTMLInputElement; const getTimeZoneInput = () => screen.getByLabelText('timezone') as HTMLInputElement;
const getCancelButton = () => screen.getByText('cancel'); const getCancelButton = () => screen.getByRole('button', { name: /cancel/i });
const getConfirmButton = () => screen.getByText('confirm'); const getConfirmButton = () => screen.getByRole('button', { name: /confirm/i });
beforeEach(() => { beforeEach(() => {
vi.stubGlobal('IntersectionObserver', getIntersectionObserverMock()); vi.stubGlobal('IntersectionObserver', getIntersectionObserverMock());

View file

@ -8,7 +8,7 @@
import { getOwnedAssetsWithWarning } from '$lib/utils/asset-utils'; import { getOwnedAssetsWithWarning } from '$lib/utils/asset-utils';
import { handleError } from '$lib/utils/handle-error'; import { handleError } from '$lib/utils/handle-error';
import { updateAssets } from '@immich/sdk'; import { updateAssets } from '@immich/sdk';
import { Button, Field, HStack, Label, Modal, ModalBody, ModalFooter, Switch } from '@immich/ui'; import { Field, FormModal, Label, Switch } from '@immich/ui';
import { mdiCalendarEdit } from '@mdi/js'; import { mdiCalendarEdit } from '@mdi/js';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import { t } from 'svelte-i18n'; import { t } from 'svelte-i18n';
@ -30,7 +30,7 @@
// the offsets (and validity) for time zones may change if the date is changed, which is why we recompute the list // the offsets (and validity) for time zones may change if the date is changed, which is why we recompute the list
let selectedOption = $derived(getPreferredTimeZone(initialDate, initialTimeZone, timezones, lastSelectedTimezone)); let selectedOption = $derived(getPreferredTimeZone(initialDate, initialTimeZone, timezones, lastSelectedTimezone));
const handleConfirm = async () => { const onSubmit = async () => {
const ids = getOwnedAssetsWithWarning(assets, $user); const ids = getOwnedAssetsWithWarning(assets, $user);
try { try {
if (showRelative && (selectedDuration || selectedOption)) { if (showRelative && (selectedDuration || selectedOption)) {
@ -63,8 +63,15 @@
const date = $derived(DateTime.fromISO(selectedDate, { zone: selectedOption?.value, setZone: true })); const date = $derived(DateTime.fromISO(selectedDate, { zone: selectedOption?.value, setZone: true }));
</script> </script>
<Modal title={$t('edit_date_and_time')} icon={mdiCalendarEdit} onClose={() => onClose(false)} size="small"> <FormModal
<ModalBody> title={$t('edit_date_and_time')}
icon={mdiCalendarEdit}
onClose={() => onClose(false)}
{onSubmit}
submitText={$t('confirm')}
disabled={!date.isValid}
size="small"
>
<Field label={$t('edit_date_and_time_by_offset')}> <Field label={$t('edit_date_and_time_by_offset')}>
<Switch data-testid="edit-by-offset-switch" bind:checked={showRelative} class="mb-2" /> <Switch data-testid="edit-by-offset-switch" bind:checked={showRelative} class="mb-2" />
</Field> </Field>
@ -114,15 +121,4 @@
</div> </div>
</CardBody> </CardBody>
</Card> --> </Card> -->
</ModalBody> </FormModal>
<ModalFooter>
<HStack fullWidth>
<Button shape="round" color="secondary" fullWidth onclick={() => onClose(false)}>
{$t('cancel')}
</Button>
<Button shape="round" color="primary" fullWidth onclick={handleConfirm} disabled={!date.isValid}>
{$t('confirm')}
</Button>
</HStack>
</ModalFooter>
</Modal>

View file

@ -3,10 +3,11 @@
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte'; import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types'; import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import { getPreferredTimeZone, getTimezones, toDatetime, type ZoneOption } from '$lib/modals/timezone-utils'; import { getPreferredTimeZone, getTimezones, toDatetime, type ZoneOption } from '$lib/modals/timezone-utils';
import { Button, HStack, Modal, ModalBody, ModalFooter, VStack } from '@immich/ui'; import { FormModal, HStack, VStack } from '@immich/ui';
import { mdiNavigationVariantOutline } from '@mdi/js'; import { mdiNavigationVariantOutline } from '@mdi/js';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import { t } from 'svelte-i18n'; import { t } from 'svelte-i18n';
interface Props { interface Props {
timelineManager: TimelineManager; timelineManager: TimelineManager;
onClose: (asset?: TimelineAsset) => void; onClose: (asset?: TimelineAsset) => void;
@ -20,7 +21,7 @@
// the offsets (and validity) for time zones may change if the date is changed, which is why we recompute the list // the offsets (and validity) for time zones may change if the date is changed, which is why we recompute the list
let selectedOption: ZoneOption | undefined = $derived(getPreferredTimeZone(initialDate, undefined, timezones)); let selectedOption: ZoneOption | undefined = $derived(getPreferredTimeZone(initialDate, undefined, timezones));
const handleClose = async () => { const onSubmit = async () => {
if (!date.isValid || !selectedOption) { if (!date.isValid || !selectedOption) {
onClose(); onClose();
return; return;
@ -36,8 +37,15 @@
const date = $derived(DateTime.fromISO(selectedDate, { zone: selectedOption?.value, setZone: true })); const date = $derived(DateTime.fromISO(selectedDate, { zone: selectedOption?.value, setZone: true }));
</script> </script>
<Modal title={$t('navigate_to_time')} icon={mdiNavigationVariantOutline} onClose={() => onClose()}> <FormModal
<ModalBody> title={$t('navigate_to_time')}
icon={mdiNavigationVariantOutline}
onClose={() => onClose()}
{onSubmit}
submitText={$t('confirm')}
disabled={!date.isValid || !selectedOption}
size="medium"
>
<VStack fullWidth> <VStack fullWidth>
<HStack fullWidth> <HStack fullWidth>
<label class="immich-form-label" for="datetime">{$t('date_and_time')}</label> <label class="immich-form-label" for="datetime">{$t('date_and_time')}</label>
@ -51,11 +59,4 @@
/> />
</HStack> </HStack>
</VStack> </VStack>
</ModalBody> </FormModal>
<ModalFooter>
<HStack fullWidth>
<Button shape="round" color="secondary" fullWidth onclick={() => onClose()}>{$t('cancel')}</Button>
<Button shape="round" type="submit" fullWidth onclick={handleClose}>{$t('confirm')}</Button>
</HStack>
</ModalFooter>
</Modal>