Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/add_loading_feedback_in_persona_settings_menu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

# Add loading feedback in Persona settings menu
44 changes: 28 additions & 16 deletions src/app/features/settings/Persona/PerMessageProfileEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<HTMLInputElement>) => {
setNewId(e.target.value);
Expand Down Expand Up @@ -658,23 +661,32 @@ 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}`}
>
<Text size="B300">Delete persona</Text>
{deleteState.status === AsyncStatus.Loading ? (
<Spinner size="100" variant="Critical" fill="Solid" />
) : (
<Text size="B300">Delete persona</Text>
)}
</Button>

<Button
onClick={handleSave}
size="400"
radii="300"
variant="Primary"
disabled={!hasChanges}
disabled={!hasChanges || saveState.status === AsyncStatus.Loading}
aria-label={`Save profile changes for ${profileId}`}
title={`Save profile changes for ${profileId}`}
>
<Text size="B300">Save</Text>
{saveState.status === AsyncStatus.Loading ? (
<Spinner size="100" variant="Primary" fill="Solid" />
) : (
<Text size="B300">Save</Text>
)}
</Button>
</Box>

Expand Down
33 changes: 21 additions & 12 deletions src/app/features/settings/Persona/PerMessageProfileOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
<Box gap="100" direction="Column">
<Text size="L400">Personas</Text>
Expand All @@ -58,17 +70,14 @@ export function PerMessageProfileOverview({
<Button
size="300"
radii="300"
onClick={() => {
const newProfile: PerMessageProfile = {
id: generateShortId(5),
name: 'New Profile',
};
addOrUpdatePerMessageProfile(mx, newProfile).then(() => {
onCreateProfile(newProfile);
});
}}
onClick={handleAdd}
disabled={addState.status === AsyncStatus.Loading}
>
<Text size="B300">Add</Text>
{addState.status === AsyncStatus.Loading ? (
<Spinner size="100" variant="Primary" fill="Solid" />
) : (
<Text size="B300">Add</Text>
)}
</Button>
}
/>
Expand Down