2023-01-09 14:16:08 -06:00
|
|
|
<script lang="ts">
|
|
|
|
|
import ControlAppBar from '$lib/components/shared-components/control-app-bar.svelte';
|
|
|
|
|
import ArrowLeft from 'svelte-material-icons/ArrowLeft.svelte';
|
|
|
|
|
import { api, SharedLinkResponseDto } from '@api';
|
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
|
import SharedLinkCard from '$lib/components/sharedlinks-page/shared-link-card.svelte';
|
|
|
|
|
import {
|
|
|
|
|
notificationController,
|
|
|
|
|
NotificationType
|
|
|
|
|
} from '$lib/components/shared-components/notification/notification';
|
|
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import CreateSharedLinkModal from '$lib/components/shared-components/create-share-link-modal/create-shared-link-modal.svelte';
|
2023-06-20 21:08:43 -04:00
|
|
|
import ConfirmDialogue from '$lib/components/shared-components/confirm-dialogue.svelte';
|
|
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
|
|
|
|
import { AppRoute } from '$lib/constants';
|
2023-01-09 14:16:08 -06:00
|
|
|
|
|
|
|
|
let sharedLinks: SharedLinkResponseDto[] = [];
|
2023-06-20 21:08:43 -04:00
|
|
|
let editSharedLink: SharedLinkResponseDto | null = null;
|
2023-01-09 14:16:08 -06:00
|
|
|
|
2023-06-20 21:08:43 -04:00
|
|
|
let deleteLinkId: string | null = null;
|
2023-01-09 14:16:08 -06:00
|
|
|
|
2023-06-20 21:08:43 -04:00
|
|
|
const refresh = async () => {
|
|
|
|
|
const { data } = await api.sharedLinkApi.getAllSharedLinks();
|
|
|
|
|
sharedLinks = data;
|
2023-01-09 14:16:08 -06:00
|
|
|
};
|
|
|
|
|
|
2023-06-20 21:08:43 -04:00
|
|
|
onMount(async () => {
|
|
|
|
|
await refresh();
|
|
|
|
|
});
|
2023-01-09 14:16:08 -06:00
|
|
|
|
2023-06-20 21:08:43 -04:00
|
|
|
const handleDeleteLink = async () => {
|
|
|
|
|
if (!deleteLinkId) {
|
|
|
|
|
return;
|
2023-01-09 14:16:08 -06:00
|
|
|
}
|
|
|
|
|
|
2023-06-20 21:08:43 -04:00
|
|
|
try {
|
|
|
|
|
await api.sharedLinkApi.removeSharedLink({ id: deleteLinkId });
|
|
|
|
|
notificationController.show({ message: 'Deleted shared link', type: NotificationType.Info });
|
|
|
|
|
deleteLinkId = null;
|
|
|
|
|
refresh();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, 'Unable to delete shared link');
|
|
|
|
|
}
|
2023-01-09 14:16:08 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleEditDone = async () => {
|
2023-06-20 21:08:43 -04:00
|
|
|
refresh();
|
|
|
|
|
editSharedLink = null;
|
2023-01-09 14:16:08 -06:00
|
|
|
};
|
|
|
|
|
|
2023-06-20 21:08:43 -04:00
|
|
|
const handleCopyLink = async (key: string) => {
|
2023-01-09 14:16:08 -06:00
|
|
|
const link = `${window.location.origin}/share/${key}`;
|
|
|
|
|
await navigator.clipboard.writeText(link);
|
|
|
|
|
notificationController.show({
|
|
|
|
|
message: 'Link copied to clipboard',
|
|
|
|
|
type: NotificationType.Info
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2023-06-20 21:08:43 -04:00
|
|
|
<ControlAppBar backIcon={ArrowLeft} on:close-button-click={() => goto(AppRoute.SHARING)}>
|
2023-01-09 14:16:08 -06:00
|
|
|
<svelte:fragment slot="leading">Shared links</svelte:fragment>
|
|
|
|
|
</ControlAppBar>
|
|
|
|
|
|
2023-05-15 19:58:35 +02:00
|
|
|
<section class="flex flex-col pb-[120px] mt-[120px]">
|
2023-01-09 14:16:08 -06:00
|
|
|
<div class="w-[50%] m-auto mb-4 dark:text-immich-gray">
|
|
|
|
|
<p>Manage shared links</p>
|
|
|
|
|
</div>
|
|
|
|
|
{#if sharedLinks.length === 0}
|
|
|
|
|
<div
|
|
|
|
|
class="w-[50%] m-auto bg-gray-100 flex place-items-center place-content-center rounded-lg p-12"
|
|
|
|
|
>
|
|
|
|
|
<p>You don't have any shared links</p>
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="flex flex-col w-[50%] m-auto">
|
|
|
|
|
{#each sharedLinks as link (link.id)}
|
|
|
|
|
<SharedLinkCard
|
|
|
|
|
{link}
|
2023-06-20 21:08:43 -04:00
|
|
|
on:delete={() => (deleteLinkId = link.id)}
|
|
|
|
|
on:edit={() => (editSharedLink = link)}
|
|
|
|
|
on:copy={() => handleCopyLink(link.key)}
|
2023-01-09 14:16:08 -06:00
|
|
|
/>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</section>
|
|
|
|
|
|
2023-06-20 21:08:43 -04:00
|
|
|
{#if editSharedLink}
|
2023-01-09 14:16:08 -06:00
|
|
|
<CreateSharedLinkModal
|
|
|
|
|
editingLink={editSharedLink}
|
|
|
|
|
shareType={editSharedLink.type}
|
|
|
|
|
album={editSharedLink.album}
|
|
|
|
|
on:close={handleEditDone}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
2023-06-20 21:08:43 -04:00
|
|
|
|
|
|
|
|
{#if deleteLinkId}
|
|
|
|
|
<ConfirmDialogue
|
|
|
|
|
title="Delete Shared Link"
|
2023-06-30 21:53:16 +02:00
|
|
|
prompt="Are you sure you want to delete this shared link?"
|
2023-06-20 21:08:43 -04:00
|
|
|
confirmText="Delete"
|
|
|
|
|
on:confirm={() => handleDeleteLink()}
|
|
|
|
|
on:cancel={() => (deleteLinkId = null)}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|