feat: toggle in options modal
parent
fa43fae2a5
commit
d9e7f8e7cf
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { PersistedLocalStorage } from '$lib/utils/persisted';
|
||||||
|
|
||||||
|
class AlbumSettingsManager {
|
||||||
|
#showAssetOwners = new PersistedLocalStorage<boolean>('album-show-asset-owners', false);
|
||||||
|
|
||||||
|
get showAssetOwners() {
|
||||||
|
return this.#showAssetOwners.current;
|
||||||
|
}
|
||||||
|
|
||||||
|
setShowAssetOwners(value: boolean) {
|
||||||
|
this.#showAssetOwners.current = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleShowAssetOwners() {
|
||||||
|
this.#showAssetOwners.current = !this.#showAssetOwners.current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const albumSettingsManager = new AlbumSettingsManager();
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
import SettingSwitch from '$lib/components/shared-components/settings/setting-switch.svelte';
|
import SettingSwitch from '$lib/components/shared-components/settings/setting-switch.svelte';
|
||||||
import UserAvatar from '$lib/components/shared-components/user-avatar.svelte';
|
import UserAvatar from '$lib/components/shared-components/user-avatar.svelte';
|
||||||
import type { RenderedOption } from '$lib/elements/Dropdown.svelte';
|
import type { RenderedOption } from '$lib/elements/Dropdown.svelte';
|
||||||
|
import { albumSettingsManager } from '$lib/managers/album-settings-manager.svelte';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import {
|
import {
|
||||||
AlbumUserRole,
|
AlbumUserRole,
|
||||||
|
|
@ -24,12 +25,26 @@
|
||||||
album: AlbumResponseDto;
|
album: AlbumResponseDto;
|
||||||
order: AssetOrder | undefined;
|
order: AssetOrder | undefined;
|
||||||
user: UserResponseDto;
|
user: UserResponseDto;
|
||||||
|
showAlbumUsers?: boolean;
|
||||||
onClose: (
|
onClose: (
|
||||||
result?: { action: 'changeOrder'; order: AssetOrder } | { action: 'shareUser' } | { action: 'refreshAlbum' },
|
result?:
|
||||||
|
| { action: 'changeOrder'; order: AssetOrder }
|
||||||
|
| { action: 'shareUser' }
|
||||||
|
| { action: 'refreshAlbum'; showAlbumUsers?: boolean },
|
||||||
) => void;
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { album, order, user, onClose }: Props = $props();
|
let { album, order, user, showAlbumUsers = $bindable(false), onClose }: Props = $props();
|
||||||
|
|
||||||
|
// managerから読み込んで初期値を設定
|
||||||
|
if (showAlbumUsers === false) {
|
||||||
|
showAlbumUsers = albumSettingsManager.showAssetOwners;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleToggleShowAlbumUsers = () => {
|
||||||
|
showAlbumUsers = !showAlbumUsers;
|
||||||
|
albumSettingsManager.setShowAssetOwners(showAlbumUsers);
|
||||||
|
};
|
||||||
|
|
||||||
const options: Record<AssetOrder, RenderedOption> = {
|
const options: Record<AssetOrder, RenderedOption> = {
|
||||||
[AssetOrder.Asc]: { icon: mdiArrowUpThin, title: $t('oldest_first') },
|
[AssetOrder.Asc]: { icon: mdiArrowUpThin, title: $t('oldest_first') },
|
||||||
|
|
@ -86,7 +101,7 @@
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await removeUserFromAlbum({ id: album.id, userId: user.id });
|
await removeUserFromAlbum({ id: album.id, userId: user.id });
|
||||||
onClose({ action: 'refreshAlbum' });
|
onClose({ action: 'refreshAlbum', showAlbumUsers });
|
||||||
toastManager.success($t('album_user_removed', { values: { user: user.name } }));
|
toastManager.success($t('album_user_removed', { values: { user: user.name } }));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, $t('errors.unable_to_remove_album_users'));
|
handleError(error, $t('errors.unable_to_remove_album_users'));
|
||||||
|
|
@ -99,7 +114,7 @@
|
||||||
const message = $t('user_role_set', {
|
const message = $t('user_role_set', {
|
||||||
values: { user: user.name, role: role == AlbumUserRole.Viewer ? $t('role_viewer') : $t('role_editor') },
|
values: { user: user.name, role: role == AlbumUserRole.Viewer ? $t('role_viewer') : $t('role_editor') },
|
||||||
});
|
});
|
||||||
onClose({ action: 'refreshAlbum' });
|
onClose({ action: 'refreshAlbum', showAlbumUsers });
|
||||||
toastManager.success(message);
|
toastManager.success(message);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, $t('errors.unable_to_change_album_user_role'));
|
handleError(error, $t('errors.unable_to_change_album_user_role'));
|
||||||
|
|
@ -107,7 +122,7 @@
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal title={$t('options')} onClose={() => onClose({ action: 'refreshAlbum' })} size="small">
|
<Modal title={$t('options')} onClose={() => onClose({ action: 'refreshAlbum', showAlbumUsers })} size="small">
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<div class="items-center justify-center">
|
<div class="items-center justify-center">
|
||||||
<div class="py-2">
|
<div class="py-2">
|
||||||
|
|
@ -127,6 +142,14 @@
|
||||||
checked={album.isActivityEnabled}
|
checked={album.isActivityEnabled}
|
||||||
onToggle={handleToggleActivity}
|
onToggle={handleToggleActivity}
|
||||||
/>
|
/>
|
||||||
|
{#if album?.shared && album.albumUsers.some(({ role }) => role === AlbumUserRole.Editor)}
|
||||||
|
<SettingSwitch
|
||||||
|
title={$t('show_asset_owners')}
|
||||||
|
subtitle={$t('display_who_uploaded_each_asset')}
|
||||||
|
checked={showAlbumUsers}
|
||||||
|
onToggle={handleToggleShowAlbumUsers}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="py-2">
|
<div class="py-2">
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
import Timeline from '$lib/components/timeline/Timeline.svelte';
|
import Timeline from '$lib/components/timeline/Timeline.svelte';
|
||||||
import { AlbumPageViewMode, AppRoute } from '$lib/constants';
|
import { AlbumPageViewMode, AppRoute } from '$lib/constants';
|
||||||
import { activityManager } from '$lib/managers/activity-manager.svelte';
|
import { activityManager } from '$lib/managers/activity-manager.svelte';
|
||||||
|
import { albumSettingsManager } from '$lib/managers/album-settings-manager.svelte';
|
||||||
import { featureFlagsManager } from '$lib/managers/feature-flags-manager.svelte';
|
import { featureFlagsManager } from '$lib/managers/feature-flags-manager.svelte';
|
||||||
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
|
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
|
||||||
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
||||||
|
|
@ -66,7 +67,6 @@
|
||||||
} from '@immich/sdk';
|
} from '@immich/sdk';
|
||||||
import { Button, Icon, IconButton, modalManager, toastManager } from '@immich/ui';
|
import { Button, Icon, IconButton, modalManager, toastManager } from '@immich/ui';
|
||||||
import {
|
import {
|
||||||
mdiAccountEyeOutline,
|
|
||||||
mdiArrowLeft,
|
mdiArrowLeft,
|
||||||
mdiCogOutline,
|
mdiCogOutline,
|
||||||
mdiDeleteOutline,
|
mdiDeleteOutline,
|
||||||
|
|
@ -101,7 +101,7 @@
|
||||||
let isCreatingSharedAlbum = $state(false);
|
let isCreatingSharedAlbum = $state(false);
|
||||||
let isShowActivity = $state(false);
|
let isShowActivity = $state(false);
|
||||||
let albumOrder: AssetOrder | undefined = $state(data.album.order);
|
let albumOrder: AssetOrder | undefined = $state(data.album.order);
|
||||||
let showAlbumUsers = $state(false);
|
let showAlbumUsers = $state(albumSettingsManager.showAssetOwners);
|
||||||
|
|
||||||
const assetInteraction = new AssetInteraction();
|
const assetInteraction = new AssetInteraction();
|
||||||
const timelineInteraction = new AssetInteraction();
|
const timelineInteraction = new AssetInteraction();
|
||||||
|
|
@ -394,7 +394,12 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOptions = async () => {
|
const handleOptions = async () => {
|
||||||
const result = await modalManager.show(AlbumOptionsModal, { album, order: albumOrder, user: $user });
|
const result = await modalManager.show(AlbumOptionsModal, {
|
||||||
|
album,
|
||||||
|
order: albumOrder,
|
||||||
|
user: $user,
|
||||||
|
showAlbumUsers,
|
||||||
|
});
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -410,6 +415,10 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'refreshAlbum': {
|
case 'refreshAlbum': {
|
||||||
|
// if (result.showAlbumUsers !== undefined) {
|
||||||
|
// showAlbumUsers = result.showAlbumUsers;
|
||||||
|
// albumSettingsManager.setShowAssetOwners(result.showAlbumUsers);
|
||||||
|
// }
|
||||||
await refreshAlbum();
|
await refreshAlbum();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -605,17 +614,6 @@
|
||||||
{#snippet trailing()}
|
{#snippet trailing()}
|
||||||
<CastButton />
|
<CastButton />
|
||||||
|
|
||||||
{#if containsEditors}
|
|
||||||
<IconButton
|
|
||||||
variant="ghost"
|
|
||||||
shape="round"
|
|
||||||
color="secondary"
|
|
||||||
aria-label="view asset owners"
|
|
||||||
icon={mdiAccountEyeOutline}
|
|
||||||
onclick={() => (showAlbumUsers = !showAlbumUsers)}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if isEditor}
|
{#if isEditor}
|
||||||
<IconButton
|
<IconButton
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue