mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-17 23:34:14 +01:00
GroupMemberLabelEditor: After save, ensure dirty = false before navigate
This commit is contained in:
@@ -42,6 +42,7 @@ import type {
|
|||||||
import type { LocalizerType, ThemeType } from '../../../types/Util.std.js';
|
import type { LocalizerType, ThemeType } from '../../../types/Util.std.js';
|
||||||
import type { PreferredBadgeSelectorType } from '../../../state/selectors/badges.preload.js';
|
import type { PreferredBadgeSelectorType } from '../../../state/selectors/badges.preload.js';
|
||||||
import type { Location } from '../../../types/Nav.std.js';
|
import type { Location } from '../../../types/Nav.std.js';
|
||||||
|
import { usePrevious } from '../../../hooks/usePrevious.std.js';
|
||||||
|
|
||||||
export type PropsDataType = {
|
export type PropsDataType = {
|
||||||
existingLabelEmoji: string | undefined;
|
existingLabelEmoji: string | undefined;
|
||||||
@@ -119,8 +120,8 @@ export function GroupMemberLabelEditor({
|
|||||||
|
|
||||||
const labelStringForSave = labelString ? labelString.trim() : labelString;
|
const labelStringForSave = labelString ? labelString.trim() : labelString;
|
||||||
const isDirty =
|
const isDirty =
|
||||||
labelEmoji !== existingLabelEmoji ||
|
(labelEmoji || undefined) !== (existingLabelEmoji || undefined) ||
|
||||||
labelStringForSave !== existingLabelString;
|
(labelStringForSave || undefined) !== (existingLabelString || undefined);
|
||||||
const canSave =
|
const canSave =
|
||||||
isDirty && ((!labelEmoji && !labelStringForSave) || labelStringForSave);
|
isDirty && ((!labelEmoji && !labelStringForSave) || labelStringForSave);
|
||||||
const spinner = isSaving
|
const spinner = isSaving
|
||||||
@@ -157,6 +158,15 @@ export function GroupMemberLabelEditor({
|
|||||||
}, [confirmDiscardIf, isDirty]);
|
}, [confirmDiscardIf, isDirty]);
|
||||||
tryClose.current = onTryClose;
|
tryClose.current = onTryClose;
|
||||||
|
|
||||||
|
// Popping the panel here after a save is far safer; we may not have re-rendered with
|
||||||
|
// the new existing values yet when the onSuccess callback down-file is called.
|
||||||
|
const previousIsSaving = usePrevious(isSaving, isSaving);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isSaving === false && previousIsSaving !== isSaving && !isDirty) {
|
||||||
|
popPanelForConversation();
|
||||||
|
}
|
||||||
|
}, [isDirty, isSaving, popPanelForConversation, previousIsSaving]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={tw('flex size-full flex-col')}>
|
<div className={tw('flex size-full flex-col')}>
|
||||||
<div className={tw('grow flex-col overflow-y-scroll')}>
|
<div className={tw('grow flex-col overflow-y-scroll')}>
|
||||||
@@ -385,7 +395,6 @@ export function GroupMemberLabelEditor({
|
|||||||
{
|
{
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
setIsSaving(false);
|
setIsSaving(false);
|
||||||
popPanelForConversation();
|
|
||||||
},
|
},
|
||||||
onFailure() {
|
onFailure() {
|
||||||
setIsSaving(false);
|
setIsSaving(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user