2023-05-16 16:13:20 +02:00
|
|
|
<script lang="ts">
|
|
|
|
|
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
2023-06-20 21:08:43 -04:00
|
|
|
import { SharedLinkResponseDto, api } from '@api';
|
2023-05-16 16:13:20 +02:00
|
|
|
import DeleteOutline from 'svelte-material-icons/DeleteOutline.svelte';
|
2023-06-20 21:08:43 -04:00
|
|
|
import ConfirmDialogue from '../../shared-components/confirm-dialogue.svelte';
|
2023-05-16 16:13:20 +02:00
|
|
|
import { getAssetControlContext } from '../asset-select-control-bar.svelte';
|
2023-06-20 21:08:43 -04:00
|
|
|
import {
|
|
|
|
|
NotificationType,
|
|
|
|
|
notificationController
|
|
|
|
|
} from '../../shared-components/notification/notification';
|
|
|
|
|
import { handleError } from '../../../utils/handle-error';
|
2023-05-16 16:13:20 +02:00
|
|
|
|
|
|
|
|
export let sharedLink: SharedLinkResponseDto;
|
2023-06-20 21:08:43 -04:00
|
|
|
|
|
|
|
|
let removing = false;
|
2023-05-16 16:13:20 +02:00
|
|
|
|
|
|
|
|
const { getAssets, clearSelect } = getAssetControlContext();
|
|
|
|
|
|
2023-06-20 21:08:43 -04:00
|
|
|
const handleRemove = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const { data: results } = await api.sharedLinkApi.removeSharedLinkAssets({
|
|
|
|
|
id: sharedLink.id,
|
|
|
|
|
assetIdsDto: {
|
|
|
|
|
assetIds: Array.from(getAssets()).map((asset) => asset.id)
|
2023-05-16 16:13:20 +02:00
|
|
|
},
|
2023-06-20 21:08:43 -04:00
|
|
|
key: sharedLink.key
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (const result of results) {
|
|
|
|
|
if (!result.success) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sharedLink.assets = sharedLink.assets.filter((asset) => asset.id !== result.assetId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const count = results.filter((item) => item.success).length;
|
|
|
|
|
|
|
|
|
|
notificationController.show({
|
|
|
|
|
type: NotificationType.Info,
|
|
|
|
|
message: `Removed ${count} assets`
|
2023-05-28 04:52:22 +03:00
|
|
|
});
|
2023-05-16 16:13:20 +02:00
|
|
|
|
|
|
|
|
clearSelect();
|
2023-06-20 21:08:43 -04:00
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, 'Unable to remove assets from shared link');
|
2023-05-16 16:13:20 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<CircleIconButton
|
2023-06-20 21:08:43 -04:00
|
|
|
title="Remove from shared link"
|
|
|
|
|
on:click={() => (removing = true)}
|
2023-05-16 16:13:20 +02:00
|
|
|
logo={DeleteOutline}
|
|
|
|
|
/>
|
2023-06-20 21:08:43 -04:00
|
|
|
|
|
|
|
|
{#if removing}
|
|
|
|
|
<ConfirmDialogue
|
|
|
|
|
title="Remove Assets?"
|
|
|
|
|
prompt="Are you sure you want to remove {getAssets().size} asset(s) from this shared link?"
|
|
|
|
|
confirmText="Remove"
|
|
|
|
|
on:confirm={() => handleRemove()}
|
|
|
|
|
on:cancel={() => (removing = false)}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|