Skip to content

Commit b46bfa3

Browse files
committed
use json store
1 parent 3e9b130 commit b46bfa3

5 files changed

Lines changed: 83 additions & 434 deletions

File tree

packages/learningmap/src/EditorDialogs.tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useEditorStore } from "./editorStore";
44
import { ShareDialog } from "./ShareDialog";
55
import { LoadExternalDialog } from "./LoadExternalDialog";
66
import { getTranslations } from "./translations";
7+
import { useJsonStore } from "./useJsonStore";
78

89
interface EditorDialogsProps {
910
defaultLanguage?: string;
@@ -15,14 +16,14 @@ export const EditorDialogs = memo(({ defaultLanguage = "en", jsonStore = "https:
1516
const settings = useEditorStore(state => state.settings);
1617
const helpOpen = useEditorStore(state => state.helpOpen);
1718
const pendingExternalId = useEditorStore(state => state.pendingExternalId);
18-
19+
const [getFromJsonStore] = useJsonStore();
20+
1921
// Get actions from store
2022
const setHelpOpen = useEditorStore(state => state.setHelpOpen);
2123
const setShareDialogOpen = useEditorStore(state => state.setShareDialogOpen);
2224
const setLoadExternalDialogOpen = useEditorStore(state => state.setLoadExternalDialogOpen);
2325
const setPendingExternalId = useEditorStore(state => state.setPendingExternalId);
2426
const getRoadmapData = useEditorStore(state => state.getRoadmapData);
25-
const loadRoadmapData = useEditorStore(state => state.loadRoadmapData);
2627

2728
const language = settings?.language || defaultLanguage;
2829
const t = getTranslations(language);
@@ -38,19 +39,6 @@ export const EditorDialogs = memo(({ defaultLanguage = "en", jsonStore = "https:
3839
downloadAnchorNode.remove();
3940
};
4041

41-
const onLoadFromStore = async (id: string) => {
42-
try {
43-
const response = await fetch(`${jsonStore}/api/json/${id}`);
44-
if (!response.ok) throw new Error("Failed to load from JSON store");
45-
const data = await response.json();
46-
loadRoadmapData(data);
47-
setLoadExternalDialogOpen(false);
48-
setPendingExternalId(null);
49-
} catch (error) {
50-
console.error("Failed to load from JSON store", error);
51-
}
52-
};
53-
5442
const keyboardShortcuts = [
5543
{ action: t.shortcuts.undo, shortcut: "Ctrl+Z" },
5644
{ action: t.shortcuts.redo, shortcut: "Ctrl+Y or Ctrl+Shift+Z" },
@@ -121,7 +109,7 @@ export const EditorDialogs = memo(({ defaultLanguage = "en", jsonStore = "https:
121109
onDownloadCurrent={onDownload}
122110
onReplace={() => {
123111
if (pendingExternalId) {
124-
onLoadFromStore(pendingExternalId);
112+
getFromJsonStore(pendingExternalId);
125113
}
126114
}}
127115
/>

packages/learningmap/src/ShareDialog.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import React, { useState } from "react";
1+
import { useEffect, useState } from "react";
22
import { X, Link2, Check } from "lucide-react";
33
import { getTranslations } from "./translations";
44
import { useEditorStore } from "./editorStore";
5+
import { useJsonStore } from "./useJsonStore";
56

67
export function ShareDialog() {
78
const [copied, setCopied] = useState(false);
8-
9+
const [_, postToJsonStore] = useJsonStore();
10+
911
// Get state from store
1012
const open = useEditorStore(state => state.shareDialogOpen);
1113
const shareLink = useEditorStore(state => state.shareLink);
@@ -14,9 +16,13 @@ export function ShareDialog() {
1416

1517
const language = settings?.language || "en";
1618
const t = getTranslations(language);
17-
19+
1820
const onClose = () => setShareDialogOpen(false);
1921

22+
useEffect(() => {
23+
postToJsonStore();
24+
}, [])
25+
2026
if (!open) return null;
2127

2228
const handleCopyLink = async () => {

packages/learningmap/src/editorStore.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export interface EditorState {
2525
edges: Edge[];
2626
settings: Settings;
2727

28+
jsonStore?: string;
29+
defaultLanguage?: string;
30+
2831
// UI state
2932
previewMode: boolean;
3033
debugMode: boolean;

0 commit comments

Comments
 (0)