2023-01-09 14:16:08 -06:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { goto } from '$app/navigation';
|
2024-02-14 08:09:49 -05:00
|
|
|
import ConfirmDialogue from '$lib/components/shared-components/confirm-dialogue.svelte';
|
|
|
|
|
import ControlAppBar from '$lib/components/shared-components/control-app-bar.svelte';
|
|
|
|
|
import CreateSharedLinkModal from '$lib/components/shared-components/create-share-link-modal/create-shared-link-modal.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
import {
|
|
|
|
|
notificationController,
|
|
|
|
|
NotificationType,
|
|
|
|
|
} from '$lib/components/shared-components/notification/notification';
|
2024-02-14 08:09:49 -05:00
|
|
|
import SharedLinkCard from '$lib/components/sharedlinks-page/shared-link-card.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { AppRoute } from '$lib/constants';
|
2024-01-03 21:54:48 -05:00
|
|
|
import { serverConfig } from '$lib/stores/server-config.store';
|
2024-02-14 08:09:49 -05:00
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
|
|
|
|
import { copyToClipboard, makeSharedLinkUrl, type SharedLinkResponseDto } from '@api';
|
|
|
|
|
import { getAllSharedLinks, removeSharedLink } from '@immich/sdk';
|
|
|
|
|
import { mdiArrowLeft } from '@mdi/js';
|
|
|
|
|
import { onMount } from 'svelte';
|
2023-01-09 14:16:08 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let sharedLinks: SharedLinkResponseDto[] = [];
|
|
|
|
|
let editSharedLink: SharedLinkResponseDto | null = null;
|
2023-01-09 14:16:08 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let deleteLinkId: string | null = null;
|
2023-01-09 14:16:08 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const refresh = async () => {
|
2024-02-14 08:09:49 -05:00
|
|
|
sharedLinks = await getAllSharedLinks();
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2023-01-09 14:16:08 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
onMount(async () => {
|
|
|
|
|
await refresh();
|
|
|
|
|
});
|
2023-01-09 14:16:08 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleDeleteLink = async () => {
|
|
|
|
|
if (!deleteLinkId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-09 14:16:08 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
try {
|
2024-02-14 08:09:49 -05:00
|
|
|
await removeSharedLink({ id: deleteLinkId });
|
2023-07-01 00:50:47 -04:00
|
|
|
notificationController.show({ message: 'Deleted shared link', type: NotificationType.Info });
|
|
|
|
|
deleteLinkId = null;
|
2023-08-27 07:31:52 +03:00
|
|
|
await refresh();
|
2023-07-01 00:50:47 -04:00
|
|
|
} catch (error) {
|
2023-08-27 07:31:52 +03:00
|
|
|
await handleError(error, 'Unable to delete shared link');
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
};
|
2023-01-09 14:16:08 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleEditDone = async () => {
|
2023-08-27 07:31:52 +03:00
|
|
|
await refresh();
|
2023-07-01 00:50:47 -04:00
|
|
|
editSharedLink = null;
|
|
|
|
|
};
|
2023-01-09 14:16:08 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleCopyLink = async (key: string) => {
|
2024-01-03 21:54:48 -05:00
|
|
|
await copyToClipboard(makeSharedLinkUrl($serverConfig.externalDomain, key));
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2023-01-09 14:16:08 -06:00
|
|
|
</script>
|
|
|
|
|
|
2023-12-15 03:54:21 +01:00
|
|
|
<ControlAppBar backIcon={mdiArrowLeft} on:close={() => goto(AppRoute.SHARING)}>
|
2023-07-01 00:50:47 -04:00
|
|
|
<svelte:fragment slot="leading">Shared links</svelte:fragment>
|
2023-01-09 14:16:08 -06:00
|
|
|
</ControlAppBar>
|
|
|
|
|
|
2023-07-18 13:19:39 -05:00
|
|
|
<section class="mt-[120px] flex flex-col pb-[120px]">
|
|
|
|
|
<div class="m-auto mb-4 w-[50%] dark:text-immich-gray">
|
2023-07-01 00:50:47 -04:00
|
|
|
<p>Manage shared links</p>
|
|
|
|
|
</div>
|
|
|
|
|
{#if sharedLinks.length === 0}
|
2023-12-19 03:26:55 +01:00
|
|
|
<div
|
|
|
|
|
class="m-auto flex w-[50%] place-content-center place-items-center rounded-lg bg-gray-100 dark:bg-immich-dark-gray dark:text-immich-gray p-12"
|
|
|
|
|
>
|
2023-07-01 00:50:47 -04:00
|
|
|
<p>You don't have any shared links</p>
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
2023-07-18 13:19:39 -05:00
|
|
|
<div class="m-auto flex w-[50%] flex-col">
|
2023-07-01 00:50:47 -04:00
|
|
|
{#each sharedLinks as link (link.id)}
|
|
|
|
|
<SharedLinkCard
|
|
|
|
|
{link}
|
|
|
|
|
on:delete={() => (deleteLinkId = link.id)}
|
|
|
|
|
on:edit={() => (editSharedLink = link)}
|
|
|
|
|
on:copy={() => handleCopyLink(link.key)}
|
|
|
|
|
/>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2023-01-09 14:16:08 -06:00
|
|
|
</section>
|
|
|
|
|
|
2023-06-20 21:08:43 -04:00
|
|
|
{#if editSharedLink}
|
2023-08-11 12:00:51 -04:00
|
|
|
<CreateSharedLinkModal editingLink={editSharedLink} on:close={handleEditDone} />
|
2023-01-09 14:16:08 -06:00
|
|
|
{/if}
|
2023-06-20 21:08:43 -04:00
|
|
|
|
|
|
|
|
{#if deleteLinkId}
|
2023-07-01 00:50:47 -04:00
|
|
|
<ConfirmDialogue
|
|
|
|
|
title="Delete Shared Link"
|
|
|
|
|
prompt="Are you sure you want to delete this shared link?"
|
|
|
|
|
confirmText="Delete"
|
|
|
|
|
on:confirm={() => handleDeleteLink()}
|
|
|
|
|
on:cancel={() => (deleteLinkId = null)}
|
|
|
|
|
/>
|
2023-06-20 21:08:43 -04:00
|
|
|
{/if}
|