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): User removal from option menu on the top in shared album #12959

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
78640e8
bug fix
Pranav-8bit Sep 25, 2024
70d4df9
Merge pull request #1 from Pranav-8bit/fix/User-removel-through-options
Pranav-8bit Sep 25, 2024
53d6c5a
Merge branch 'main' into fix/user-removal-from-option-menu-on-the-top…
Pranav-8bit Sep 26, 2024
eef2245
Merge branch 'main' into fix/user-removal-from-option-menu-on-the-top…
Pranav-8bit Sep 28, 2024
fab5e13
Merge branch 'immich-app:main' into main
Pranav-8bit Sep 28, 2024
6c50533
Merge branch 'main' of https://github.com/Pranav-8bit/immich into fix…
Pranav-8bit Sep 28, 2024
07830f9
added few more type hint
Pranav-8bit Sep 28, 2024
dfcc137
Merge branch 'fix/user-removal-from-option-menu-on-the-top-in-shared-…
Pranav-8bit Sep 28, 2024
621b3e8
Merge branch 'main' into fix/user-removal-from-option-menu-on-the-top…
Pranav-8bit Sep 30, 2024
694801f
onMount removed, removed current user to user
Pranav-8bit Oct 1, 2024
321d1ed
Merge branch 'fix/user-removal-from-option-menu-on-the-top-in-shared-…
Pranav-8bit Oct 1, 2024
c5bfda2
Merge branch 'main' into fix/user-removal-from-option-menu-on-the-top…
Pranav-8bit Oct 1, 2024
9eb05a1
Merge branch 'immich-app:main' into fix/user-removal-from-option-menu…
Pranav-8bit Oct 2, 2024
91e2555
user check removed and conflict in view mode resolved between option …
Pranav-8bit Oct 2, 2024
e739052
Merge branch 'main' into fix/user-removal-from-option-menu-on-the-top…
Pranav-8bit Oct 4, 2024
0a83d6b
Merge branch 'main' into fix/user-removal-from-option-menu-on-the-top…
Pranav-8bit Oct 10, 2024
01f5e43
Merge branch 'fix/user-removal-from-option-menu-on-the-top-in-shared-…
alextran1502 Oct 10, 2024
3d524d2
format fix
alextran1502 Oct 10, 2024
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
81 changes: 73 additions & 8 deletions web/src/lib/components/album-page/album-options.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<script lang="ts">
import Icon from '$lib/components/elements/icon.svelte';
import { updateAlbumInfo, type AlbumResponseDto, type UserResponseDto, AssetOrder } from '@immich/sdk';
import { mdiArrowDownThin, mdiArrowUpThin, mdiPlus } from '@mdi/js';
import {
getMyUser, // Reintroduce the API to fetch the current user
updateAlbumInfo,
removeUserFromAlbum,
type AlbumResponseDto,
type UserResponseDto,
AssetOrder
} from '@immich/sdk';
import { mdiArrowDownThin, mdiArrowUpThin, mdiPlus, mdiDotsVertical } from '@mdi/js';
import FullScreenModal from '$lib/components/shared-components/full-screen-modal.svelte';
import UserAvatar from '$lib/components/shared-components/user-avatar.svelte';
import SettingSwitch from '$lib/components/shared-components/settings/setting-switch.svelte';
Expand All @@ -10,14 +17,22 @@
import { handleError } from '$lib/utils/handle-error';
import { findKey } from 'lodash-es';
import { t } from 'svelte-i18n';
import ButtonContextMenu from '$lib/components/shared-components/context-menu/button-context-menu.svelte';
import ConfirmDialog from '$lib/components/shared-components/dialog/confirm-dialog.svelte';
import { notificationController, NotificationType } from '../shared-components/notification/notification';
import MenuOption from '$lib/components/shared-components/context-menu/menu-option.svelte';
import { onMount } from 'svelte'; // Import onMount to fetch the user when component mounts

export let album: AlbumResponseDto;
export let order: AssetOrder | undefined;
export let user: UserResponseDto;
export let onChangeOrder: (order: AssetOrder) => void;
export let onClose: () => void;
export let onToggleEnabledActivity: () => void;
export let onShowSelectSharedUser: () => void;
export let onRemove: (userId: string) => void;

let currentUser: UserResponseDto | null = null; // Store the current user fetched from the API
let selectedRemoveUser: UserResponseDto | null = null; // Keep track of the user selected for removal

const options: Record<AssetOrder, RenderedOption> = {
[AssetOrder.Asc]: { icon: mdiArrowUpThin, title: $t('oldest_first') },
Expand All @@ -26,6 +41,15 @@

$: selectedOption = order ? options[order] : options[AssetOrder.Desc];

// Fetch the current user when the component mounts
onMount(async () => {
try {
currentUser = await getMyUser();
} catch (error) {
handleError(error, $t('errors.unable_to_refresh_user'));
}
});

const handleToggle = async (returnedOption: RenderedOption) => {
if (selectedOption === returnedOption) {
return;
Expand All @@ -45,6 +69,29 @@
handleError(error, $t('errors.unable_to_save_album'));
}
};

const handleMenuRemove = (user: UserResponseDto) => {
selectedRemoveUser = user;
};

const handleRemoveUser = async () => {
if (!selectedRemoveUser) {
return;
}
console.log(selectedRemoveUser,"selectedRemoveUser");
try {
await removeUserFromAlbum({ id: album.id, userId: selectedRemoveUser.id });
onRemove(selectedRemoveUser.id);
notificationController.show({
type: NotificationType.Info,
message: $t('album_user_removed', { values: { user: selectedRemoveUser.name } }),
});
} catch (error) {
handleError(error, $t('errors.unable_to_remove_album_users'));
} finally {
selectedRemoveUser = null;
}
};
</script>

<FullScreenModal title={$t('options')} {onClose}>
Expand Down Expand Up @@ -77,22 +124,40 @@
</div>
<div>{$t('invite_people')}</div>
</button>
<div class="flex items-center gap-2 py-2 mt-2">
<div>
<UserAvatar {user} size="md" />
{#if currentUser}
<div class="flex items-center gap-2 py-2 mt-2">
<div>
<UserAvatar user={currentUser} size="md" />
</div>
<div class="w-full">{user.name}</div>
<div class="w-full">{currentUser.name}</div>
<div>{$t('owner')}</div>
</div>
</div>
{/if}

{#each album.albumUsers as { user } (user.id)}
<div class="flex items-center gap-2 py-2">
<div>
<UserAvatar {user} size="md" />
</div>
<div class="w-full">{user.name}</div>
{#if user.id !== album.ownerId} <!-- Allow deletion for non-owners -->
<ButtonContextMenu icon={mdiDotsVertical} size="20" title={$t('options')}>
<MenuOption onClick={() => handleMenuRemove(user)} text={$t('remove')} />
</ButtonContextMenu>
{/if}
Pranav-8bit marked this conversation as resolved.
Show resolved Hide resolved
</div>
{/each}
</div>
</div>
</div>
</FullScreenModal>

{#if selectedRemoveUser}
<ConfirmDialog
title={$t('album_remove_user')}
prompt={$t('album_remove_user_confirmation', { values: { user: selectedRemoveUser.name } })}
confirmText={$t('remove_user')}
onConfirm={handleRemoveUser}
onCancel={() => (selectedRemoveUser = null)}
/>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@
albumOrder = order;
await setModeToView();
}}
onRemove={handleRemoveUser}
onClose={() => (viewMode = ViewMode.VIEW)}
onToggleEnabledActivity={handleToggleEnableActivity}
onShowSelectSharedUser={() => (viewMode = ViewMode.SELECT_USERS)}
Expand Down
Loading