Skip to content

Commit 2e86f50

Browse files
committed
Use only queryClient for cache
1 parent 4b4d417 commit 2e86f50

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/extension/ui/src/queries/useConfig.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const getTemplateForItem = (
2121

2222
export function useConfig(client: v1.DockerDesktopClient) {
2323
const queryClient = useQueryClient();
24-
const configRef = useRef<any>(null);
2524

2625
const {
2726
data: config = undefined,
@@ -33,8 +32,6 @@ export function useConfig(client: v1.DockerDesktopClient) {
3332
try {
3433
const response = await getStoredConfig(client);
3534
const result = response || {};
36-
// Store a deep copy of the config in the ref
37-
configRef.current = JSON.parse(JSON.stringify(result));
3835
return result;
3936
} catch (error) {
4037
client.desktopUI.toast.error("Failed to get stored config: " + error);
@@ -56,13 +53,12 @@ export function useConfig(client: v1.DockerDesktopClient) {
5653
}) => {
5754
try {
5855
// Use the ref which contains the pre-optimistic update state
59-
const currentStoredConfig = { ...(configRef.current || {}) };
60-
const updatedConfig = { ...currentStoredConfig, [itemName]: newConfig };
56+
const updatedConfig = { ...((queryClient.getQueryData(["config"]) as Record<string, any>) ||
57+
{}), [itemName]: newConfig };
6158

6259
await writeToPromptsVolume(client, 'config.yaml', stringify(updatedConfig));
6360

6461
const updatedConfigRef = JSON.parse(JSON.stringify(updatedConfig));
65-
configRef.current = updatedConfigRef;
6662
return { itemName, updatedConfig: updatedConfigRef };
6763
} catch (error) {
6864
client.desktopUI.toast.error("Failed to update config: " + error);

0 commit comments

Comments
 (0)