From 52f33e0fb9f40760c581577bc431ae20ac58cc2d Mon Sep 17 00:00:00 2001 From: Josie Date: Sat, 25 Jul 2026 23:50:10 +0100 Subject: [PATCH] Add loading feedback in Persona settings menu --- ...ading_feedback_in_persona_settings_menu.md | 5 +++ .../Persona/PerMessageProfileEditor.tsx | 44 ++++++++++++------- .../Persona/PerMessageProfileOverview.tsx | 33 +++++++++----- 3 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 .changeset/add_loading_feedback_in_persona_settings_menu.md diff --git a/.changeset/add_loading_feedback_in_persona_settings_menu.md b/.changeset/add_loading_feedback_in_persona_settings_menu.md new file mode 100644 index 000000000..bafc389b1 --- /dev/null +++ b/.changeset/add_loading_feedback_in_persona_settings_menu.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +# Add loading feedback in Persona settings menu diff --git a/src/app/features/settings/Persona/PerMessageProfileEditor.tsx b/src/app/features/settings/Persona/PerMessageProfileEditor.tsx index 79d3b25d5..e0f46fab1 100644 --- a/src/app/features/settings/Persona/PerMessageProfileEditor.tsx +++ b/src/app/features/settings/Persona/PerMessageProfileEditor.tsx @@ -426,13 +426,15 @@ export function PerMessageProfileEditor({ /** * persisting the data :3 */ - const handleSave = useCallback(() => { - addOrUpdatePerMessageProfile(mx, { - id: profileId, - name: newDisplayName, - avatarUrl: avatarMxc, - pronouns: newPronouns, - }).then(() => { + const [saveState, handleSave] = useAsyncCallback( + useCallback(async () => { + await addOrUpdatePerMessageProfile(mx, { + id: profileId, + name: newDisplayName, + avatarUrl: avatarMxc, + pronouns: newPronouns, + }); + setCurrentDisplayName(newDisplayName); setCurrentPronouns(newPronouns); setImageHasChanges(false); @@ -443,16 +445,17 @@ export function PerMessageProfileEditor({ setCurrentId(newId); }); } - }); - }, [mx, profileId, newDisplayName, avatarMxc, newPronouns, hasIdChange, newId]); + }, [mx, profileId, newDisplayName, avatarMxc, newPronouns, hasIdChange, newId]) + ); - const handleDelete = useCallback(() => { - deletePerMessageProfile(mx, profileId).then(() => { + const [deleteState, handleDelete] = useAsyncCallback( + useCallback(async () => { + await deletePerMessageProfile(mx, profileId); setCurrentDisplayName(''); setCurrentPronouns([]); if (onDelete) onDelete(profileId); - }); - }, [mx, profileId, onDelete]); + }, [mx, profileId, onDelete]) + ); const handleIdChange = useCallback((e: React.ChangeEvent) => { setNewId(e.target.value); @@ -658,11 +661,16 @@ export function PerMessageProfileEditor({ size="400" radii="300" variant="Critical" + disabled={deleteState.status === AsyncStatus.Loading} fill="None" aria-label={`Delete profile ${profileId}`} title={`Delete profile ${profileId}`} > - Delete persona + {deleteState.status === AsyncStatus.Loading ? ( + + ) : ( + Delete persona + )} diff --git a/src/app/features/settings/Persona/PerMessageProfileOverview.tsx b/src/app/features/settings/Persona/PerMessageProfileOverview.tsx index b76b61dbb..68dcf3961 100644 --- a/src/app/features/settings/Persona/PerMessageProfileOverview.tsx +++ b/src/app/features/settings/Persona/PerMessageProfileOverview.tsx @@ -5,12 +5,13 @@ import { getAllPerMessageProfiles, getPerMessageProfileById, } from '$hooks/usePerMessageProfile'; -import { useEffect, useState } from 'react'; -import { Box, Button, Text } from 'folds'; +import { useCallback, useEffect, useState } from 'react'; +import { Box, Button, Spinner, Text } from 'folds'; import { generateShortId } from '$utils/shortIdGen'; import { SequenceCard, SequenceCardStyle } from '$components/sequence-card'; import { PerMessageProfileListItem } from './PerMessageProfileListItem'; import { SettingTile } from '$components/setting-tile'; +import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback'; type PerMessageProfileOverviewProps = { onCreateProfile: (profile: PerMessageProfile) => void; @@ -40,6 +41,17 @@ export function PerMessageProfileOverview({ if (profile) onEditProfile(profile); }; + const [addState, handleAdd] = useAsyncCallback( + useCallback(async () => { + const newProfile: PerMessageProfile = { + id: generateShortId(5), + name: 'New Profile', + }; + await addOrUpdatePerMessageProfile(mx, newProfile); + onCreateProfile(newProfile); + }, [mx, onCreateProfile]) + ); + return ( Personas @@ -58,17 +70,14 @@ export function PerMessageProfileOverview({ } />