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

fix: web search add to album reactivity #13539

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion web/src/lib/components/photos-page/actions/add-to-album.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import { getAssetControlContext } from '../asset-select-control-bar.svelte';
import { mdiImageAlbum, mdiShareVariantOutline } from '@mdi/js';
import { t } from 'svelte-i18n';
import type { OnAddToAlbum } from '$lib/utils/actions';

export let shared = false;
export let onAddToAlbum: OnAddToAlbum = () => {};

let showAlbumPicker = false;

Expand All @@ -21,13 +23,19 @@
showAlbumPicker = false;

const assetIds = [...getAssets()].map((asset) => asset.id);
await addAssetsToNewAlbum(albumName, assetIds);
const album = await addAssetsToNewAlbum(albumName, assetIds);
if (!album) {
return;
}

onAddToAlbum(assetIds, album.id);
};

const handleAddToAlbum = async (album: AlbumResponseDto) => {
showAlbumPicker = false;
const assetIds = [...getAssets()].map((asset) => asset.id);
await addAssetsToAlbum(album.id, assetIds);
onAddToAlbum(assetIds, album.id);
};
</script>

Expand Down
1 change: 1 addition & 0 deletions web/src/lib/utils/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type OnDelete = (assetIds: string[]) => void;
export type OnRestore = (ids: string[]) => void;
export type OnLink = (assets: { still: AssetResponseDto; motion: AssetResponseDto }) => void;
export type OnUnlink = (assets: { still: AssetResponseDto; motion: AssetResponseDto }) => void;
export type OnAddToAlbum = (ids: string[], albumId: string) => void;
export type OnArchive = (ids: string[], isArchived: boolean) => void;
export type OnFavorite = (ids: string[], favorite: boolean) => void;
export type OnStack = (ids: string[]) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@

const triggerAssetUpdate = () => (searchResultAssets = searchResultAssets);

const onAddToAlbum = (assetIds: string[]) => {
const assetIdSet = new Set(assetIds);
searchResultAssets = searchResultAssets.filter((a: AssetResponseDto) => !assetIdSet.has(a.id));
};

function getObjectKeys<T extends object>(obj: T): (keyof T)[] {
return Object.keys(obj) as (keyof T)[];
}
Expand All @@ -230,8 +235,8 @@
<CreateSharedLink />
<CircleIconButton title={$t('select_all')} icon={mdiSelectAll} on:click={handleSelectAll} />
<ButtonContextMenu icon={mdiPlus} title={$t('add_to')}>
<AddToAlbum />
<AddToAlbum shared />
<AddToAlbum {onAddToAlbum} />
<AddToAlbum shared {onAddToAlbum} />
</ButtonContextMenu>
<FavoriteAction removeFavorite={isAllFavorite} onFavorite={triggerAssetUpdate} />

Expand Down
Loading