fix(tunnels): restore profiles after settings navigation

This commit is contained in:
t8y2 committed 2026-07-13 09:52:34 +08:00
1 parent 0745fbc53c
commit 73f6801df9
1 file changed
+7 -1
@@ -20,6 +20,7 @@ const store = useTunnelProfileStore();
const draft = ref<TunnelProfile[]>([]); const draft = ref<TunnelProfile[]>([]);
const selectedId = ref<string | null>(null); const selectedId = ref<string | null>(null);
const isSaving = ref(false); const isSaving = ref(false);
const hasInitializedDraft = ref(false);
function cloneProfiles(profiles: TunnelProfile[]): TunnelProfile[] { function cloneProfiles(profiles: TunnelProfile[]): TunnelProfile[] {
return JSON.parse(JSON.stringify(profiles)) as TunnelProfile[]; return JSON.parse(JSON.stringify(profiles)) as TunnelProfile[];
@@ -38,7 +39,12 @@ void store.init();
watch( watch(
() => store.isLoaded, () => store.isLoaded,
(loaded) => { (loaded) => {
if (loaded && !isDirty.value) resetDraft(); // A remounted settings panel starts with an empty draft even when Pinia
// already contains profiles, so the initial empty state is not a user edit.
if (loaded && (!hasInitializedDraft.value || !isDirty.value)) {
resetDraft();
hasInitializedDraft.value = true;
}
}, },
{ immediate: true }, { immediate: true },
); );