Skip to content

Commit a625028

Browse files
authored
Merge pull request #173 from thedadams/pass-id-to-edit
fix: pass script id to edit for loading
2 parents 1eeb6f0 + 0d6a813 commit a625028

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

app/edit/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function EditFile() {
3131
initialScriptId={scriptId}
3232
initialThread=""
3333
>
34-
<EditContextProvider scriptPath={file}>
34+
<EditContextProvider scriptPath={file} initialScriptId={scriptId}>
3535
<div
3636
className={`w-full h-full grid ${collapsed ? 'grid-cols-4' : 'grid-cols-2'}`}
3737
>

contexts/edit.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type DependencyBlock = {
2222

2323
interface EditContextProps {
2424
scriptPath: string;
25+
initialScriptId: string;
2526
children: React.ReactNode;
2627
}
2728

@@ -62,14 +63,15 @@ interface EditContextState {
6263
const EditContext = createContext<EditContextState>({} as EditContextState);
6364
const EditContextProvider: React.FC<EditContextProps> = ({
6465
scriptPath,
66+
initialScriptId,
6567
children,
6668
}) => {
6769
const [loading, setLoading] = useState(true);
6870
const [notFound, setNotFound] = useState(false);
6971
const [root, setRoot] = useState<Tool>({} as Tool);
7072
const [tools, setTools] = useState<Tool[]>([]);
7173
const [script, setScript] = useState<Block[]>([]);
72-
const [scriptId, setScriptId] = useState<number>(-1);
74+
const [scriptId, setScriptId] = useState<number>(parseInt(initialScriptId));
7375
const [visibility, setVisibility] = useState<
7476
'public' | 'private' | 'protected'
7577
>('private');
@@ -90,7 +92,7 @@ const EditContextProvider: React.FC<EditContextProps> = ({
9092
setModels(m);
9193
});
9294

93-
getScript(scriptPath)
95+
getScript(initialScriptId)
9496
.then(async (script) => {
9597
if (script === undefined) {
9698
setNotFound(true);

0 commit comments

Comments
 (0)