Skip to content

Commit

Permalink
GUI: New empty file (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasavila00 committed Mar 26, 2024
1 parent c0232c7 commit b18f212
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
6 changes: 5 additions & 1 deletion egui/src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BlockEditor } from "gui/src/editor/BlockEditor";
import { useDarkmode } from "gui/src/lib/use-dark-mode";
import { createPortal } from "react-dom";
import { RenderDarkModeSwitcher } from "gui/src/components/dark-mode";
import { initialContent } from "gui/src/editor/hooks/init";
import { emptyInitialContent, initialContent } from "gui/src/editor/hooks/init";
import { useState } from "react";
import { LmEditorState } from "gui/src/editor/lib/types";
import { useSidebar } from "gui/src/editor/hooks/useSideBar";
Expand Down Expand Up @@ -46,6 +46,10 @@ function App(): JSX.Element {
bumpKey();
});
}}
onNewEmpty={() => {
setInitialEditorData(emptyInitialContent);
bumpKey();
}}
onSaveFile={onSaveFile}
onOpenFile={() => {
window.electron.ipcRenderer.invoke("openFile").then((data) => {
Expand Down
4 changes: 4 additions & 0 deletions gui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default function App() {
// eslint-disable-next-line no-console
console.log("open file");
}}
onNewEmpty={
// eslint-disable-next-line no-console
() => console.log("new empty")
}
sidebarState={sidebarState}
initialContent={initialContent}
onSaveFileAs={(content) => {
Expand Down
14 changes: 13 additions & 1 deletion gui/src/editor/BlockEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type LoadedEditorCommonProps = {
onSaveFile: (content: LmEditorState) => void;
sidebarState: SidebarState;
onOpenFile: () => void;
onNewEmpty: () => void;
initialContent: LmEditorState;
};

Expand Down Expand Up @@ -146,6 +147,7 @@ const LoadedBlockEditor: FC<
sidebarState,
onOpenFile,
initialContent,
onNewEmpty,
}) => {
const menuContainerRef = useRef(null);
const backendConfigHook = useBackendConfig();
Expand Down Expand Up @@ -173,6 +175,7 @@ const LoadedBlockEditor: FC<
onOpenFile,
onSaveFile: () => onSaveFile(getLmEditorState()),
onSaveAsFile: () => onSaveFileAs(getLmEditorState()),
onNewEmpty,
}}
onExportToTasks={() => setIsExporting(true)}
/>
Expand Down Expand Up @@ -244,7 +247,15 @@ export const BlockEditor: FC<
LoadedEditorCommonProps & {
initialContent: LmEditorState;
}
> = ({ initialContent, onSaveFileAs, currentFilePath, onSaveFile, sidebarState, onOpenFile }) => {
> = ({
onNewEmpty,
initialContent,
onSaveFileAs,
currentFilePath,
onSaveFile,
sidebarState,
onOpenFile,
}) => {
const { isExecuting, toggleExecuting, editor, variablesHook, samplingParamsHook } =
useBlockEditor(initialContent);

Expand All @@ -266,6 +277,7 @@ export const BlockEditor: FC<
sidebarState={sidebarState}
onOpenFile={onOpenFile}
initialContent={initialContent}
onNewEmpty={onNewEmpty}
/>
);
};
2 changes: 2 additions & 0 deletions gui/src/editor/components/EditorHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type FileManagerProps = {
onOpenFile: () => void;
onSaveFile: () => void;
onSaveAsFile: () => void;
onNewEmpty: () => void;
};
const getFileNameFromPath = (path: string | undefined) => {
if (path == null) {
Expand Down Expand Up @@ -89,6 +90,7 @@ export const EditorHeader: FC<{
<DropdownMenuLabel>Manage Files</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem onClick={fileManagement.onNewEmpty}>New</DropdownMenuItem>
<DropdownMenuItem onClick={fileManagement.onOpenFile}>
Open
<DropdownMenuShortcut>⌘O</DropdownMenuShortcut>
Expand Down
21 changes: 21 additions & 0 deletions gui/src/editor/hooks/init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import { LmEditorState } from "../lib/types";

export const emptyInitialContent: LmEditorState = {
doc: {
type: "doc",
content: [
{
type: "authorSelect",
attrs: {
author: "system",
},
},
{
type: "paragraph",
},
],
},
variables: [],
samplingParams: {
temperature: 0.1,
},
version: "1",
};
export const initialContent: LmEditorState = {
doc: {
type: "doc",
Expand Down

0 comments on commit b18f212

Please sign in to comment.