Files
paseo/packages/app/src/desktop/browser/settings/browser-data-section.tsx
T
Mohamed Boudra ae80ec4252 Let plugins contribute settings screens (#4357)
* feat(plugins): contribute settings screens and shared controls

* fix(plugins): localize settings and verify shared UI consumers

* test(composer): unmount draft test roots after each case

* test(app): keep launch terminals alive until cleanup

The fixed ten-second profile lifetime could expire before a busy CI browser attached or finished revisiting the composer. Keep the real process waiting for input until project teardown terminates it.

* test(server): await the initial snapshot before a buffered ref event

Watcher setup can read checkout facts before the initial refresh publishes a snapshot. Wait for publication before injecting the event so the test consistently exercises a second refresh.
2026-09-06 10:22:26 +02:00

81 lines
2.7 KiB
TypeScript

import { useCallback, useRef, useState } from "react";
import { Text, View } from "react-native";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { useToast } from "@/contexts/toast-context";
import { getDesktopHost } from "@/desktop/host";
import { SettingsSection } from "@/components/settings/headings/settings-section";
import { useBrowserStore } from "@/desktop/browser/store";
import { settingsStyles } from "@/styles/settings";
import { confirmDialog } from "@/utils/confirm-dialog";
export function BrowserDataSection() {
const { t } = useTranslation();
const toast = useToast();
const clearInFlightRef = useRef(false);
const [isClearing, setIsClearing] = useState(false);
const handleClear = useCallback(async () => {
if (clearInFlightRef.current) {
return;
}
clearInFlightRef.current = true;
setIsClearing(true);
try {
const confirmed = await confirmDialog({
title: t("settings.general.browserData.confirmTitle"),
message: t("settings.general.browserData.confirmMessage"),
confirmLabel: t("settings.general.browserData.clear"),
cancelLabel: t("common.actions.cancel"),
destructive: true,
});
if (!confirmed) {
return;
}
const clearProfile = getDesktopHost()?.browser?.clearProfile;
if (!clearProfile) {
throw new Error("Electron browser profile bridge is unavailable");
}
await clearProfile(Object.keys(useBrowserStore.getState().browsersById));
toast.show(t("settings.general.browserData.success"), { variant: "success" });
} catch {
toast.error(t("settings.general.browserData.error"));
} finally {
clearInFlightRef.current = false;
setIsClearing(false);
}
}, [t, toast]);
const clearButtonLabel = isClearing
? t("settings.general.browserData.clearing")
: t("settings.general.browserData.clear");
return (
<SettingsSection title={t("settings.general.browserData.title")}>
<View style={settingsStyles.card}>
<View style={settingsStyles.row}>
<View style={settingsStyles.rowContent}>
<Text style={settingsStyles.rowTitle}>
{t("settings.general.browserData.siteData")}
</Text>
<Text style={settingsStyles.rowHint}>
{t("settings.general.browserData.description")}
</Text>
</View>
<Button
variant="destructive"
size="sm"
loading={isClearing}
disabled={isClearing}
onPress={handleClear}
>
{clearButtonLabel}
</Button>
</View>
</View>
</SettingsSection>
);
}