From 33dd7110f1705d345de3dc2d90ae2943786611ad Mon Sep 17 00:00:00 2001 From: O4FDev Date: Tue, 12 Nov 2024 15:39:24 +0000 Subject: [PATCH 1/3] fix: nothing selected bug --- src/components/dialogs/PostInteractionSettingsDialog.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/dialogs/PostInteractionSettingsDialog.tsx b/src/components/dialogs/PostInteractionSettingsDialog.tsx index 81590e3c98e..1d5f50f918a 100644 --- a/src/components/dialogs/PostInteractionSettingsDialog.tsx +++ b/src/components/dialogs/PostInteractionSettingsDialog.tsx @@ -257,6 +257,11 @@ export function PostInteractionSettingsForm({ newSelected.splice(i, 1) } + // if nothing is selected, default to 'everybody' + if (newSelected.length === 0) { + newSelected.push({type: 'everybody'}) + } + onChangeThreadgateAllowUISettings(newSelected) } From f01f82f0a16c5203de68e9e01b5328b4456d3aef Mon Sep 17 00:00:00 2001 From: O4FDev Date: Tue, 12 Nov 2024 17:46:57 +0000 Subject: [PATCH 2/3] fix: consolidate related logic for audience settings --- .../dialogs/PostInteractionSettingsDialog.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/components/dialogs/PostInteractionSettingsDialog.tsx b/src/components/dialogs/PostInteractionSettingsDialog.tsx index 1d5f50f918a..7f04a6c73c7 100644 --- a/src/components/dialogs/PostInteractionSettingsDialog.tsx +++ b/src/components/dialogs/PostInteractionSettingsDialog.tsx @@ -249,19 +249,21 @@ export function PostInteractionSettingsForm({ threadgateAllowUISettings.filter( v => v.type !== 'nobody' && v.type !== 'everybody', ) - // toggle + /** + * Handle updating the selected audience settings: + * - If the setting doesn't exist yet, add it to the list + * - If it's the only setting and being removed, revert to default (everybody) + * - If it exists and there are other settings, remove it from the list + */ const i = newSelected.findIndex(v => isEqual(v, setting)) if (i === -1) { newSelected.push(setting) + } else if (newSelected.length === 1) { + newSelected = [{type: 'everybody'}] } else { newSelected.splice(i, 1) } - // if nothing is selected, default to 'everybody' - if (newSelected.length === 0) { - newSelected.push({type: 'everybody'}) - } - onChangeThreadgateAllowUISettings(newSelected) } From 5204310c539ed775cfb9edc867d9c1bec47a6a50 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sat, 23 Nov 2024 20:06:32 +0000 Subject: [PATCH 3/3] simplify --- .../dialogs/PostInteractionSettingsDialog.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/components/dialogs/PostInteractionSettingsDialog.tsx b/src/components/dialogs/PostInteractionSettingsDialog.tsx index 7f04a6c73c7..8536001da4e 100644 --- a/src/components/dialogs/PostInteractionSettingsDialog.tsx +++ b/src/components/dialogs/PostInteractionSettingsDialog.tsx @@ -249,20 +249,16 @@ export function PostInteractionSettingsForm({ threadgateAllowUISettings.filter( v => v.type !== 'nobody' && v.type !== 'everybody', ) - /** - * Handle updating the selected audience settings: - * - If the setting doesn't exist yet, add it to the list - * - If it's the only setting and being removed, revert to default (everybody) - * - If it exists and there are other settings, remove it from the list - */ + // toggle const i = newSelected.findIndex(v => isEqual(v, setting)) if (i === -1) { newSelected.push(setting) - } else if (newSelected.length === 1) { - newSelected = [{type: 'everybody'}] } else { newSelected.splice(i, 1) } + if (newSelected.length === 0) { + newSelected.push({type: 'everybody'}) + } onChangeThreadgateAllowUISettings(newSelected) }