Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): View all duplicates page #15856

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@
"delete_library": "Delete Library",
"delete_link": "Delete link",
"delete_others": "Delete others",
"has_duplicates": "Has duplicates",
"delete_shared_link": "Delete shared link",
"delete_tag": "Delete tag",
"delete_tag_confirmation_prompt": "Are you sure you want to delete {tagName} tag?",
Expand Down
18 changes: 18 additions & 0 deletions web/src/lib/components/asset-viewer/detail-panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
mdiClose,
mdiEye,
mdiEyeOff,
mdiImageMultipleOutline,
mdiImageOutline,
mdiInformationOutline,
mdiPencil,
Expand Down Expand Up @@ -464,6 +465,23 @@
</div>
{/if}

{#if asset.duplicateId}
<div class="flex gap-4 py-4">
<div><Icon path={mdiImageMultipleOutline} size="24" /></div>

<div>
<p>
<a
href="{AppRoute.DUPLICATES}/{asset.duplicateId}"
class="hover:dark:text-immich-dark-primary hover:text-immich-primary"
>
{$t('has_duplicates')}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this doesn't give a good indication that it's a button that takes you to a different view.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this feature to see the duplicate info on the image details. I agree with mert about it not being clear that it is clickable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to improve this in the latest iteration :D

</a>
</p>
</div>
</div>
{/if}

<DetailPanelLocation {isOwner} {asset} />
</div>
</section>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script lang="ts">
import Icon from '$lib/components/elements/icon.svelte';
import { AppRoute } from '$lib/constants';
import { getAssetThumbnailUrl } from '$lib/utils';
import { getAltText } from '$lib/utils/thumbnail-util';
import type { DuplicateResponseDto } from '@immich/sdk';
import { mdiImageMultipleOutline } from '@mdi/js';

interface Props {
duplicate: DuplicateResponseDto;
}

let { duplicate }: Props = $props();

let assetToDisplay = duplicate.assets[0];
let title = $derived(
JSON.stringify(
duplicate.assets.map((asset) => asset.originalFileName),
null,
2,
),
);
arnolicious marked this conversation as resolved.
Show resolved Hide resolved
</script>

<a href="{AppRoute.DUPLICATES}/{duplicate.duplicateId}" class="block relative w-full">
<img
src={getAssetThumbnailUrl(assetToDisplay.id)}
alt={$getAltText(assetToDisplay)}
{title}
class="h-60 object-cover rounded-xl w-full"
draggable="false"
/>

<div class="absolute top-2 right-3">
<div class="bg-immich-primary/90 px-2 py-1 my-0.5 rounded-xl text-xs text-white">
<div class="flex items-center justify-center">
<div class="mr-1">{duplicate.assets.length}</div>
<Icon path={mdiImageMultipleOutline} size="18" />
</div>
</div>
</div>
</a>
24 changes: 24 additions & 0 deletions web/src/routes/(user)/utilities/duplicates/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script lang="ts">
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
import DuplicateThumbnail from '$lib/components/utilities-page/duplicates/duplicate-thumbnail.svelte';
import { locale } from '$lib/stores/preferences.store';
import type { PageData } from './$types';

interface Props {
data: PageData;
}

let { data = $bindable() }: Props = $props();

let duplicates = $state(data.duplicates);
</script>

<UserPageLayout title={data.meta.title + ` (${duplicates.length.toLocaleString($locale)})`} scrollbar={true}>
<section class="mt-2 h-[calc(100%-theme(spacing.20))] overflow-auto immich-scrollbar">
<div class="w-full grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-6 2xl:grid-cols-8 gap-2 rounded-2xl">
{#each duplicates as duplicate}
<DuplicateThumbnail {duplicate} />
{/each}
</div>
</section>
</UserPageLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import { mdiCheckOutline, mdiInformationOutline, mdiKeyboard, mdiTrashCanOutline } from '@mdi/js';
import { t } from 'svelte-i18n';
import type { PageData } from './$types';
import { AppRoute } from '$lib/constants';
import { goto } from '$app/navigation';

interface Props {
data: PageData;
Expand Down Expand Up @@ -54,6 +56,7 @@
],
};

let activeDuplicate = $state(data.activeDuplicate);
let duplicates = $state(data.duplicates);
let hasDuplicates = $derived(duplicates.length > 0);
const withConfirmation = async (callback: () => Promise<void>, prompt?: string, confirmText?: string) => {
Expand Down Expand Up @@ -90,9 +93,19 @@
await deleteAssets({ assetBulkDeleteDto: { ids: trashIds, force: !$featureFlags.trash } });
await updateAssets({ assetBulkUpdateDto: { ids: duplicateAssetIds, duplicateId: null } });

const currentDuplicateIndex = duplicates.findIndex((duplicate) => duplicate.duplicateId === duplicateId);
duplicates = duplicates.filter((duplicate) => duplicate.duplicateId !== duplicateId);

deletedNotification(trashIds.length);

// Move to the next duplicate
if (duplicates.length > 0) {
// The index of the next duplicate is the same as the current one, since we removed the current one
activeDuplicate = duplicates[currentDuplicateIndex] || duplicates[0];
} else {
// If there are no more duplicates, redirect to the duplicates page
await goto(AppRoute.DUPLICATES);
}
},
trashIds.length > 0 && !$featureFlags.trash ? $t('delete_duplicates_confirmation') : undefined,
trashIds.length > 0 && !$featureFlags.trash ? $t('permanently_delete') : undefined,
Expand All @@ -103,7 +116,17 @@
await stackAssets(assets, false);
const duplicateAssetIds = assets.map((asset) => asset.id);
await updateAssets({ assetBulkUpdateDto: { ids: duplicateAssetIds, duplicateId: null } });
const currentDuplicateIndex = duplicates.findIndex((duplicate) => duplicate.duplicateId === duplicateId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just track the index instead of doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't think I really understand by "tracking" in this context.
Where would you calculate the index? In the API endpoint?

duplicates = duplicates.filter((duplicate) => duplicate.duplicateId !== duplicateId);

// Move to the next duplicate
if (duplicates.length > 0) {
// The index of the next duplicate is the same as the current one, since we removed the current one
activeDuplicate = duplicates[currentDuplicateIndex] || duplicates[0];
} else {
// If there are no more duplicates, redirect to the duplicates page
await goto(AppRoute.DUPLICATES);
}
};

const handleDeduplicateAll = async () => {
Expand Down Expand Up @@ -209,12 +232,12 @@
/>
</div>

{#key duplicates[0].duplicateId}
{#key activeDuplicate.duplicateId}
<DuplicatesCompareControl
assets={duplicates[0].assets}
assets={activeDuplicate.assets}
onResolve={(duplicateAssetIds, trashIds) =>
handleResolve(duplicates[0].duplicateId, duplicateAssetIds, trashIds)}
onStack={(assets) => handleStack(duplicates[0].duplicateId, assets)}
handleResolve(activeDuplicate.duplicateId, duplicateAssetIds, trashIds)}
onStack={(assets) => handleStack(activeDuplicate.duplicateId, assets)}
/>
{/key}
{:else}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetDuplicates } from '@immich/sdk';
import { fail } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load = (async ({ params }) => {
await authenticate();
const duplicates = await getAssetDuplicates();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This view only needs to know the number of each duplicate group, not fetch all their members. It can fetch much less data with a different endpoint that only returns the data it actually needs (one asset to display per group, and the number of duplicates in the group).

const $t = await getFormatter();

const activeDuplicate = duplicates.find((duplicate) => duplicate.duplicateId === params.duplicateId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well.


if (!activeDuplicate) {
return fail(404);
}

return {
duplicates,
activeDuplicate,
meta: {
title: $t('duplicates'),
},
};
}) satisfies PageLoad;
Loading