2023-05-16 16:13:20 +02:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
2024-01-20 13:47:41 -05:00
|
|
|
import { type SharedLinkResponseDto, api } from '@api';
|
2023-07-01 00:50:47 -04:00
|
|
|
import ConfirmDialogue from '../../shared-components/confirm-dialogue.svelte';
|
|
|
|
|
import { getAssetControlContext } from '../asset-select-control-bar.svelte';
|
|
|
|
|
import { NotificationType, notificationController } from '../../shared-components/notification/notification';
|
|
|
|
|
import { handleError } from '../../../utils/handle-error';
|
2023-10-25 09:48:25 -04:00
|
|
|
import { mdiDeleteOutline } from '@mdi/js';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
export let sharedLink: SharedLinkResponseDto;
|
|
|
|
|
|
|
|
|
|
let removing = false;
|
|
|
|
|
|
|
|
|
|
const { getAssets, clearSelect } = getAssetControlContext();
|
|
|
|
|
|
|
|
|
|
const handleRemove = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const { data: results } = await api.sharedLinkApi.removeSharedLinkAssets({
|
|
|
|
|
id: sharedLink.id,
|
|
|
|
|
assetIdsDto: {
|
2024-02-02 04:18:00 +01:00
|
|
|
assetIds: [...getAssets()].map((asset) => asset.id),
|
2023-07-01 00:50:47 -04:00
|
|
|
},
|
2023-08-25 00:03:28 -04:00
|
|
|
key: api.getKey(),
|
2023-07-01 00:50:47 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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`,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
clearSelect();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, 'Unable to remove assets from shared link');
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-05-16 16:13:20 +02:00
|
|
|
</script>
|
|
|
|
|
|
2023-10-25 09:48:25 -04:00
|
|
|
<CircleIconButton title="Remove from shared link" on:click={() => (removing = true)} icon={mdiDeleteOutline} />
|
2023-06-20 21:08:43 -04:00
|
|
|
|
|
|
|
|
{#if removing}
|
2023-07-01 00:50:47 -04:00
|
|
|
<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)}
|
|
|
|
|
/>
|
2023-06-20 21:08:43 -04:00
|
|
|
{/if}
|