Skip to content

Commit 2244a6c

Browse files
committed
fix(mobile): preserve removal guards across checkout changes
1 parent 688d233 commit 2244a6c

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

‎apps/mobile/src/features/settings/SettingsProjectOverviewRouteScreen.tsx‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ import { useSettingsEnvironmentFilter, type SettingsTarget } from "./settings-en
3535

3636
export function SettingsProjectOverviewRouteScreen() {
3737
const insets = useSafeAreaInsets();
38+
const [isRemoving, setIsRemoving] = useState(false);
39+
const removalPending = useRef(false);
40+
const startRemoval = () => {
41+
if (removalPending.current) return false;
42+
removalPending.current = true;
43+
return true;
44+
};
45+
const finishRemoval = () => {
46+
removalPending.current = false;
47+
setIsRemoving(false);
48+
};
3849
const { selectedTargets, projectGroups, selectedProjectKey } = useSettingsEnvironmentFilter();
3950
const group = projectGroups.find((entry) => entry.key === selectedProjectKey);
4051
const selectedEnvironmentIds = new Set(selectedTargets.map((entry) => entry.environmentId));
@@ -65,6 +76,10 @@ export function SettingsProjectOverviewRouteScreen() {
6576
members={members}
6677
environments={selectedTargets}
6778
hasOtherMembers={members.length < (group?.members.length ?? 0)}
79+
isRemoving={isRemoving}
80+
setIsRemoving={setIsRemoving}
81+
startRemoval={startRemoval}
82+
finishRemoval={finishRemoval}
6883
/>
6984
)}
7085
</ScrollView>
@@ -77,13 +92,16 @@ function ProjectOverviewContent(props: {
7792
readonly members: readonly EnvironmentProject[];
7893
readonly environments: readonly SettingsTarget[];
7994
readonly hasOtherMembers: boolean;
95+
readonly isRemoving: boolean;
96+
readonly setIsRemoving: (isRemoving: boolean) => void;
97+
readonly startRemoval: () => boolean;
98+
readonly finishRemoval: () => void;
8099
}) {
100+
const { isRemoving, setIsRemoving, startRemoval, finishRemoval } = props;
81101
const representative = props.members[0]!;
82102
const displayName = deriveProjectGroupLabel({ representative, members: props.members });
83103
const [draftName, setDraftName] = useState<string | null>(null);
84104
const [isSaving, setIsSaving] = useState(false);
85-
const [isRemoving, setIsRemoving] = useState(false);
86-
const removalPending = useRef(false);
87105
const navigation = useNavigation();
88106
const threads = useThreadShells();
89107
const removableEnvironments = useEnvironmentsWithScope(
@@ -117,7 +135,7 @@ function ProjectOverviewContent(props: {
117135
};
118136

119137
const removeMembers = (members: readonly EnvironmentProject[]) => {
120-
if (removalPending.current || !checkRemovalAccess(members)) return;
138+
if (!checkRemovalAccess(members) || !startRemoval()) return;
121139
const plan = planProjectRemoval({
122140
members: members.map((member) => ({
123141
...member,
@@ -130,15 +148,12 @@ function ProjectOverviewContent(props: {
130148
displayName,
131149
threads,
132150
});
133-
removalPending.current = true;
134151
Dialog.confirm({
135152
title: plan.targetKind === "checkout" ? "Remove checkout" : "Remove project",
136153
message: plan.confirmationMessage,
137154
confirmText: plan.targetKind === "checkout" ? "Remove checkout" : "Remove project",
138155
destructive: true,
139-
onCancel: () => {
140-
removalPending.current = false;
141-
},
156+
onCancel: finishRemoval,
142157
onConfirm: () => {
143158
void (async () => {
144159
setIsRemoving(true);
@@ -162,10 +177,7 @@ function ProjectOverviewContent(props: {
162177
}
163178
// Nothing is left to show once the whole project is gone.
164179
if (plan.targetKind === "project" && navigation.isFocused()) navigation.goBack();
165-
})().finally(() => {
166-
removalPending.current = false;
167-
setIsRemoving(false);
168-
});
180+
})().finally(finishRemoval);
169181
},
170182
});
171183
};

0 commit comments

Comments
 (0)