From 86922119602ecb4d3e6fe256679e01bb3aff2547 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Wed, 8 May 2024 23:17:40 +0100 Subject: [PATCH 1/2] enhancement: delete profile while logged out --- .../components/ProfileCardActionsMenu.svelte | 24 +++++++++++++++++++ .../views/profile/DeleteProfile.svelte | 3 ++- .../settings/actions/deleteProfile.ts | 15 +++++------- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/packages/desktop/views/login/components/ProfileCardActionsMenu.svelte b/packages/desktop/views/login/components/ProfileCardActionsMenu.svelte index 00c333150a..0ff50687eb 100644 --- a/packages/desktop/views/login/components/ProfileCardActionsMenu.svelte +++ b/packages/desktop/views/login/components/ProfileCardActionsMenu.svelte @@ -1,5 +1,6 @@ diff --git a/packages/desktop/views/settings/views/profile/DeleteProfile.svelte b/packages/desktop/views/settings/views/profile/DeleteProfile.svelte index 3f14d34c8b..01d28892f3 100644 --- a/packages/desktop/views/settings/views/profile/DeleteProfile.svelte +++ b/packages/desktop/views/settings/views/profile/DeleteProfile.svelte @@ -4,6 +4,7 @@ import { localize } from '@core/i18n' import { PopupId, openPopup } from '@desktop/auxiliary/popup' import SettingsSection from '../SettingsSection.svelte' + import { getActiveProfileId } from '@core/profile/stores' function onDeleteClick(): void { openPopup({ @@ -13,7 +14,7 @@ title: localize('popups.deleteProfile.title'), alert: { variant: 'warning', text: localize('popups.deleteProfile.confirmation') }, confirmText: localize('actions.delete'), - onConfirm: deleteProfile, + onConfirm: () => deleteProfile(getActiveProfileId() as string), }, }) } diff --git a/packages/shared/src/lib/contexts/settings/actions/deleteProfile.ts b/packages/shared/src/lib/contexts/settings/actions/deleteProfile.ts index 1438d0fa64..ff7351c02f 100644 --- a/packages/shared/src/lib/contexts/settings/actions/deleteProfile.ts +++ b/packages/shared/src/lib/contexts/settings/actions/deleteProfile.ts @@ -1,22 +1,18 @@ import { AppContext } from '@core/app/enums' import { removeProfileFolder } from '@core/profile' import { logout, removeAllProfileData } from '@core/profile/actions' -import { activeProfileId, profiles } from '@core/profile/stores' +import { profiles } from '@core/profile/stores' import { routerManager } from '@core/router/stores' import { get } from 'svelte/store' +import { closePopup } from '../../../../../../desktop/lib/auxiliary/popup' /** * It removes the active profile from the app's list of profiles, removes the profile's directory from * the file system, and logs the user out * @returns A Promise that resolves to void. */ -export async function deleteProfile(): Promise { +export async function deleteProfile(profileId: string): Promise { try { - const _activeProfileId = get(activeProfileId) - if (!_activeProfileId) { - return - } - /** * CAUTION: Logout must occur before the profile is removed * from the Svelte store list of profiles. @@ -27,14 +23,15 @@ export async function deleteProfile(): Promise { * CAUTION: The profile and its data must be removed from the * app's list of profiles that lives as a Svelte store. */ - removeAllProfileData(_activeProfileId) + removeAllProfileData(profileId) /** * CAUTION: This removes the actual directory for the profile, * so it should occur last. */ - await removeProfileFolder(_activeProfileId) + await removeProfileFolder(profileId) + closePopup() /** * NOTE: If there are no more profiles, then the user should be * routed to the welcome screen. From 7680ca6c27683ee738715af98afa9518727891e9 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Fri, 10 May 2024 14:17:27 +0100 Subject: [PATCH 2/2] pr comments to improve ux --- .../login/components/ProfileCardActionsMenu.svelte | 11 +++++++---- .../lib/contexts/settings/actions/deleteProfile.ts | 2 -- packages/shared/src/locales/en.json | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/desktop/views/login/components/ProfileCardActionsMenu.svelte b/packages/desktop/views/login/components/ProfileCardActionsMenu.svelte index 0ff50687eb..09628b7b54 100644 --- a/packages/desktop/views/login/components/ProfileCardActionsMenu.svelte +++ b/packages/desktop/views/login/components/ProfileCardActionsMenu.svelte @@ -3,7 +3,7 @@ import { deleteProfile } from '@contexts/settings/actions' import { localize } from '@core/i18n' import { IPersistedProfile } from '@core/profile' - import { PopupId, openPopup } from '@desktop/auxiliary/popup' + import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup' export let profile: IPersistedProfile @@ -26,10 +26,13 @@ id: PopupId.Confirmation, props: { variant: 'danger', - title: localize('popups.deleteProfile.title'), + title: localize('popups.deleteProfile.title', { name: profile.name }), alert: { variant: 'warning', text: localize('popups.deleteProfile.confirmation') }, confirmText: localize('actions.delete'), - onConfirm: () => deleteProfile(profile.id), + onConfirm: () => { + deleteProfile(profile.id) + closePopup() + }, }, }, false, @@ -48,7 +51,7 @@ { variant: 'danger', icon: IconName.Trash, - title: localize('popups.deleteProfile.title'), + title: localize('views.settings.deleteProfile.title'), onClick: onDeleteClick, }, ]} diff --git a/packages/shared/src/lib/contexts/settings/actions/deleteProfile.ts b/packages/shared/src/lib/contexts/settings/actions/deleteProfile.ts index ff7351c02f..ce6b1da019 100644 --- a/packages/shared/src/lib/contexts/settings/actions/deleteProfile.ts +++ b/packages/shared/src/lib/contexts/settings/actions/deleteProfile.ts @@ -4,7 +4,6 @@ import { logout, removeAllProfileData } from '@core/profile/actions' import { profiles } from '@core/profile/stores' import { routerManager } from '@core/router/stores' import { get } from 'svelte/store' -import { closePopup } from '../../../../../../desktop/lib/auxiliary/popup' /** * It removes the active profile from the app's list of profiles, removes the profile's directory from @@ -31,7 +30,6 @@ export async function deleteProfile(profileId: string): Promise { */ await removeProfileFolder(profileId) - closePopup() /** * NOTE: If there are no more profiles, then the user should be * routed to the welcome screen. diff --git a/packages/shared/src/locales/en.json b/packages/shared/src/locales/en.json index 06f68cb2d3..e32e2ade0e 100644 --- a/packages/shared/src/locales/en.json +++ b/packages/shared/src/locales/en.json @@ -991,7 +991,7 @@ "empty": "The error log is empty." }, "deleteProfile": { - "title": "Delete profile", + "title": "Delete {name} profile", "confirmation": "Are you sure you want to delete this profile? This operation cannot be undone.", "typePassword": "Type your password to confirm." },