2023-04-25 22:19:23 -04:00
|
|
|
<script lang="ts">
|
2024-04-19 06:47:29 -04:00
|
|
|
import { deleteAllSessions, deleteSession, getSessions, type SessionResponseDto } from '@immich/sdk';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { handleError } from '../../utils/handle-error';
|
|
|
|
|
import Button from '../elements/buttons/button.svelte';
|
2024-04-19 06:47:29 -04:00
|
|
|
import { notificationController, NotificationType } from '../shared-components/notification/notification';
|
2023-07-01 00:50:47 -04:00
|
|
|
import DeviceCard from './device-card.svelte';
|
2024-05-28 09:10:43 +07:00
|
|
|
import { dialogController } from '$lib/components/shared-components/dialog/dialog';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2023-04-25 22:19:23 -04:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
devices: SessionResponseDto[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let { devices = $bindable() }: Props = $props();
|
2023-04-25 22:19:23 -04:00
|
|
|
|
2024-04-19 06:47:29 -04:00
|
|
|
const refresh = () => getSessions().then((_devices) => (devices = _devices));
|
2023-04-25 22:19:23 -04:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let currentDevice = $derived(devices.find((device) => device.current));
|
|
|
|
|
let otherDevices = $derived(devices.filter((device) => !device.current));
|
2023-04-25 22:19:23 -04:00
|
|
|
|
2024-05-28 09:10:43 +07:00
|
|
|
const handleDelete = async (device: SessionResponseDto) => {
|
|
|
|
|
const isConfirmed = await dialogController.show({
|
2024-06-24 15:50:01 +02:00
|
|
|
prompt: $t('logout_this_device_confirmation'),
|
2024-05-28 09:10:43 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!isConfirmed) {
|
2023-07-01 00:50:47 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2023-04-25 22:19:23 -04:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
try {
|
2024-05-28 09:10:43 +07:00
|
|
|
await deleteSession({ id: device.id });
|
2024-06-24 15:50:01 +02:00
|
|
|
notificationController.show({ message: $t('logged_out_device'), type: NotificationType.Info });
|
2023-07-01 00:50:47 -04:00
|
|
|
} catch (error) {
|
2024-06-24 15:50:01 +02:00
|
|
|
handleError(error, $t('errors.unable_to_log_out_device'));
|
2023-07-01 00:50:47 -04:00
|
|
|
} finally {
|
|
|
|
|
await refresh();
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-05-09 15:34:17 -04:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleDeleteAll = async () => {
|
2024-07-03 16:41:17 -04:00
|
|
|
const isConfirmed = await dialogController.show({ prompt: $t('logout_all_device_confirmation') });
|
2024-05-28 09:10:43 +07:00
|
|
|
if (!isConfirmed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
try {
|
2024-04-19 06:47:29 -04:00
|
|
|
await deleteAllSessions();
|
2023-07-01 00:50:47 -04:00
|
|
|
notificationController.show({
|
2024-06-24 15:50:01 +02:00
|
|
|
message: $t('logged_out_all_devices'),
|
2023-07-01 00:50:47 -04:00
|
|
|
type: NotificationType.Info,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
2024-06-24 15:50:01 +02:00
|
|
|
handleError(error, $t('errors.unable_to_log_out_all_devices'));
|
2023-07-01 00:50:47 -04:00
|
|
|
} finally {
|
|
|
|
|
await refresh();
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-04-25 22:19:23 -04:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<section class="my-4">
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if currentDevice}
|
|
|
|
|
<div class="mb-6">
|
2024-06-04 21:53:00 +02:00
|
|
|
<h3 class="mb-2 text-xs font-medium text-immich-primary dark:text-immich-dark-primary">
|
|
|
|
|
{$t('current_device').toUpperCase()}
|
|
|
|
|
</h3>
|
2023-07-01 00:50:47 -04:00
|
|
|
<DeviceCard device={currentDevice} />
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if otherDevices.length > 0}
|
|
|
|
|
<div class="mb-6">
|
2024-06-04 21:53:00 +02:00
|
|
|
<h3 class="mb-2 text-xs font-medium text-immich-primary dark:text-immich-dark-primary">
|
|
|
|
|
{$t('other_devices').toUpperCase()}
|
|
|
|
|
</h3>
|
2025-03-03 14:24:26 +00:00
|
|
|
{#each otherDevices as device, index (device.id)}
|
2024-09-19 18:20:09 -04:00
|
|
|
<DeviceCard {device} onDelete={() => handleDelete(device)} />
|
2024-02-02 04:18:00 +01:00
|
|
|
{#if index !== otherDevices.length - 1}
|
2023-07-01 00:50:47 -04:00
|
|
|
<hr class="my-3" />
|
|
|
|
|
{/if}
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
2024-06-04 21:53:00 +02:00
|
|
|
<h3 class="mb-2 text-xs font-medium text-immich-primary dark:text-immich-dark-primary">
|
|
|
|
|
{$t('log_out_all_devices').toUpperCase()}
|
|
|
|
|
</h3>
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex justify-end">
|
2024-11-14 08:43:25 -06:00
|
|
|
<Button color="red" size="sm" onclick={handleDeleteAll}>{$t('log_out_all_devices')}</Button>
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
2023-04-25 22:19:23 -04:00
|
|
|
</section>
|