update: PythonEditor.tsx
This commit is contained in:
@@ -32,6 +32,8 @@ export default function ScriptsPage() {
|
||||
const latestVersion = useScriptWorkspaceStore((s) => s.latestVersion);
|
||||
const latestVersionLoading = useScriptWorkspaceStore((s) => s.latestVersionLoading);
|
||||
|
||||
const pythonEditorBuffers = useScriptWorkspaceStore((s) => s.pythonEditorBuffers);
|
||||
|
||||
// store actions
|
||||
const setKeyword = useScriptWorkspaceStore((s) => s.setKeyword);
|
||||
const load = useScriptWorkspaceStore((s) => s.load);
|
||||
@@ -42,6 +44,10 @@ export default function ScriptsPage() {
|
||||
const switchTab = useScriptWorkspaceStore((s) => s.switchTab);
|
||||
const openScriptEditor = useScriptWorkspaceStore((s) => s.openScriptEditor);
|
||||
const endEditing = useScriptWorkspaceStore((s) => s.endEditing);
|
||||
const openPythonEditor = useScriptWorkspaceStore((s) => s.openPythonEditor);
|
||||
const setPythonEditorContent = useScriptWorkspaceStore((s) => s.setPythonEditorContent);
|
||||
const savePythonEditor = useScriptWorkspaceStore((s) => s.savePythonEditor);
|
||||
const exitPythonEditor = useScriptWorkspaceStore((s) => s.exitPythonEditor);
|
||||
const loadLatestVersion = useScriptWorkspaceStore((s) => s.loadLatestVersion);
|
||||
const createScript = useScriptWorkspaceStore((s) => s.createScript);
|
||||
const uploadScripts = useScriptWorkspaceStore((s) => s.uploadScripts);
|
||||
@@ -166,6 +172,20 @@ export default function ScriptsPage() {
|
||||
};
|
||||
}, [contextMenu, closeContextMenu]);
|
||||
|
||||
// python editor handlers with scriptId forwarding
|
||||
const handleSetPythonEditorContent = (scriptId: string, value: string) => {
|
||||
setPythonEditorContent(scriptId, value);
|
||||
};
|
||||
const handleSavePythonEditor = (scriptId: string) => {
|
||||
void savePythonEditor(scriptId);
|
||||
};
|
||||
const handleExitPythonEditor = (scriptId: string) => {
|
||||
exitPythonEditor(scriptId);
|
||||
};
|
||||
const handleClosePythonTab = (scriptId: string) => {
|
||||
void closeTab(scriptId);
|
||||
};
|
||||
|
||||
// 5) handlers
|
||||
const handleUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const files = Array.from(event.target.files ?? []);
|
||||
@@ -242,12 +262,31 @@ export default function ScriptsPage() {
|
||||
scriptType: s?.script_type ?? "notebook",
|
||||
};
|
||||
})}
|
||||
onOpenEditor={() => void openScriptEditor(selected)}
|
||||
onEndEditing={() => void endEditing()}
|
||||
onOpenEditor={() => {
|
||||
if (selected.script_type === "python") {
|
||||
void openPythonEditor(selected);
|
||||
} else {
|
||||
void openScriptEditor(selected);
|
||||
}
|
||||
}}
|
||||
onEndEditing={() => {
|
||||
if (selected && pythonEditorBuffers[selected.script_id]) {
|
||||
exitPythonEditor(selected.script_id);
|
||||
} else {
|
||||
void endEditing();
|
||||
}
|
||||
}}
|
||||
onClose={(scriptId, event) => void closeTab(scriptId, event)}
|
||||
onSwitchTab={switchTab}
|
||||
onNewTab={() => openCreateDialog("")}
|
||||
onPublish={() => openPublishDialog(selected)}
|
||||
scripts={scripts}
|
||||
pythonEditorBuffers={pythonEditorBuffers}
|
||||
onOpenPythonEditor={() => void openPythonEditor(selected)}
|
||||
onSetPythonEditorContent={handleSetPythonEditorContent}
|
||||
onSavePythonEditor={handleSavePythonEditor}
|
||||
onExitPythonEditor={handleExitPythonEditor}
|
||||
onClosePythonTab={handleClosePythonTab}
|
||||
onInfo={(t) => pushToast(t)}
|
||||
/>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user