Skip to content

Commit b54815c

Browse files
fix: make saving persistent metadata work
1 parent 487abd0 commit b54815c

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

src/components/dialog/account-metadata-dialog.tsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import { useForm } from "@tanstack/react-form";
33
import { useMutation, useQueryClient } from "@tanstack/react-query";
44
import { useRouteContext } from "@tanstack/react-router";
55
import { PlusIcon, TrashIcon } from "lucide-react";
6-
import { Suspense, use, useCallback, useMemo, useState } from "react";
6+
import {
7+
Suspense,
8+
use,
9+
useCallback,
10+
useEffect,
11+
useMemo,
12+
useState,
13+
} from "react";
714
import { useTranslation } from "react-i18next";
815
import { toast } from "sonner";
916
import { z } from "zod";
@@ -84,7 +91,11 @@ export function AccountMetadataDialog({
8491
</DialogDescription>
8592
</DialogHeader>
8693
<Suspense fallback={<DialogSkeleton />}>
87-
<DialogContentInner account={account} onOpenChange={onOpenChange} />
94+
<DialogContentInner
95+
account={account}
96+
open={open}
97+
onOpenChange={onOpenChange}
98+
/>
8899
</Suspense>
89100
</DialogContent>
90101
</Dialog>
@@ -104,9 +115,11 @@ function DialogSkeleton() {
104115

105116
function DialogContentInner({
106117
account,
118+
open,
107119
onOpenChange,
108120
}: {
109121
account: ProfileAccount;
122+
open: boolean;
110123
onOpenChange: (open: boolean) => void;
111124
}) {
112125
const { t } = useTranslation("instance");
@@ -123,6 +136,7 @@ function DialogContentInner({
123136

124137
// Load metadata on mount
125138
const loadMetadata = useCallback(async () => {
139+
setIsLoading(true);
126140
if (transport === null) {
127141
setEntries([]);
128142
setIsLoading(false);
@@ -143,10 +157,10 @@ function DialogContentInner({
143157
setIsLoading(false);
144158
}, [transport, instanceId, account.profileId]);
145159

146-
// Load on first render
147-
if (isLoading && entries === null) {
148-
loadMetadata();
149-
}
160+
useEffect(() => {
161+
if (!open) return;
162+
void loadMetadata();
163+
}, [open, loadMetadata]);
150164

151165
// Check for duplicate namespace+key
152166
const isDuplicate = useCallback(
@@ -183,10 +197,12 @@ function DialogContentInner({
183197
},
184198
onSuccess: () => {
185199
toast.success(t("account.metadata.addSuccess"));
200+
void loadMetadata();
186201
},
187202
onError: (e) => {
188203
console.error(e);
189204
toast.error(t("account.metadata.addError"));
205+
void loadMetadata();
190206
},
191207
});
192208

@@ -226,9 +242,13 @@ function DialogContentInner({
226242
value: Value.fromJson(entry.value),
227243
});
228244
},
245+
onSuccess: () => {
246+
void loadMetadata();
247+
},
229248
onError: (e) => {
230249
console.error(e);
231250
toast.error(t("account.metadata.updateError"));
251+
void loadMetadata();
232252
},
233253
});
234254

@@ -248,10 +268,12 @@ function DialogContentInner({
248268
},
249269
onSuccess: () => {
250270
toast.success(t("account.metadata.deleteSuccess"));
271+
void loadMetadata();
251272
},
252273
onError: (e) => {
253274
console.error(e);
254275
toast.error(t("account.metadata.deleteError"));
276+
void loadMetadata();
255277
},
256278
});
257279

src/routes/_dashboard/instance/$instance/meta.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "@tanstack/react-query";
88
import { createFileRoute } from "@tanstack/react-router";
99
import { PlusIcon, TrashIcon } from "lucide-react";
10-
import { use, useCallback, useMemo, useState } from "react";
10+
import { use, useCallback, useEffect, useMemo, useState } from "react";
1111
import { useTranslation } from "react-i18next";
1212
import { toast } from "sonner";
1313
import { z } from "zod";
@@ -238,6 +238,7 @@ function InstanceMetadataEditor({ instanceId }: { instanceId: string }) {
238238
const [isLoading, setIsLoading] = useState(true);
239239

240240
const loadMetadata = useCallback(async () => {
241+
setIsLoading(true);
241242
if (transport === null) {
242243
setEntries([]);
243244
setIsLoading(false);
@@ -257,9 +258,9 @@ function InstanceMetadataEditor({ instanceId }: { instanceId: string }) {
257258
setIsLoading(false);
258259
}, [transport, instanceId]);
259260

260-
if (isLoading && entries === null) {
261-
loadMetadata();
262-
}
261+
useEffect(() => {
262+
void loadMetadata();
263+
}, [loadMetadata]);
263264

264265
const isDuplicate = useCallback(
265266
(namespace: string, key: string, excludeId?: string) => {
@@ -293,10 +294,12 @@ function InstanceMetadataEditor({ instanceId }: { instanceId: string }) {
293294
},
294295
onSuccess: () => {
295296
toast.success(t("instanceMetadata.addSuccess"));
297+
void loadMetadata();
296298
},
297299
onError: (e) => {
298300
console.error(e);
299301
toast.error(t("instanceMetadata.addError"));
302+
void loadMetadata();
300303
},
301304
});
302305

@@ -331,9 +334,13 @@ function InstanceMetadataEditor({ instanceId }: { instanceId: string }) {
331334
value: Value.fromJson(entry.value),
332335
});
333336
},
337+
onSuccess: () => {
338+
void loadMetadata();
339+
},
334340
onError: (e) => {
335341
console.error(e);
336342
toast.error(t("instanceMetadata.updateError"));
343+
void loadMetadata();
337344
},
338345
});
339346

@@ -351,10 +358,12 @@ function InstanceMetadataEditor({ instanceId }: { instanceId: string }) {
351358
},
352359
onSuccess: () => {
353360
toast.success(t("instanceMetadata.deleteSuccess"));
361+
void loadMetadata();
354362
},
355363
onError: (e) => {
356364
console.error(e);
357365
toast.error(t("instanceMetadata.deleteError"));
366+
void loadMetadata();
358367
},
359368
});
360369

0 commit comments

Comments
 (0)