Skip to content

Commit

Permalink
backup to swap
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasgauvin committed Jan 21, 2024
1 parent a81150c commit 81ad53a
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 28 deletions.
2 changes: 1 addition & 1 deletion sample-markdown-folder/folder/subfolder/test5.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
hello this is a test

# test 5
# test 5test
4 changes: 2 additions & 2 deletions sample-markdown-folder/folder/test3.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
hello this is a test
hello this is a **test**

# test 3this is a test another
# This is a test
2 changes: 1 addition & 1 deletion sample-markdown-folder/test2.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ this is a new test

## this is another test asdf

sadfasd
sadfasdojasljfsad
26 changes: 18 additions & 8 deletions src/components/FileSystemAdapters/FileSystem/Folder.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "react";
import DirectoryNode from "../../../models/DirectoryNode";
import { ChevronRight } from "lucide-react";
import { ChevronDown, ChevronRight, ChevronUp } from "lucide-react";

export function Folder({
node,
Expand All @@ -18,31 +18,41 @@ export function Folder({
<div key={node.name}>
{depth === 0 ? null : (
<div
className="p-2 hover:bg-zinc-200 rounded"
className="p-1 hover:bg-zinc-200/70 rounded flex"
onClick={() => {
setExpanded(!expanded);
}}
>
<ChevronRight />
<h3 className="text-sm font-semibold">{node.name}</h3>
{expanded ? (
<ChevronDown className="h-5 w-5 cursor-pointer hover:bg-zinc-300 rounded" />
) : (
<ChevronRight className="h-5 w-5 cursor-pointer hover:bg-zinc-300 rounded" />
)}
<div className="pl-0.5 text-sm">{node.name}</div>
</div>
)}
<div className={`ml-4 ${expanded ? "block" : "hidden"}`}>
<div
className={`${depth === 0 ? "" : "ml-4"} ${
expanded ? "block" : "hidden"
}`}
>
{node.children.map((child) => (
<div key={child.name}>
{child.children.length === 0 ? ( // Render file
<div
className={`ml-${(depth + 1) * 20} cursor-pointer
text-sm
p-2 hover:bg-zinc-200 rounded ${
p-1 hover:bg-zinc-200/70 rounded ${
child.unsavedChanges ? "italic" : ""
}`}
onClick={() => {
handleFileSelect(child);
}}
>
{child.name}
{child.unsavedChanges ? "*" : ""}
<div className="pl-1">
{child.name}
{child.unsavedChanges ? "*" : ""}
</div>
</div>
) : (
<Folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ export const LocalFileSystem = ({
};

return (
<div>
<div className="min-w-16 bg-zinc-50">
{selectedDirectory && (
<div className="divide-y font-semibold text-base">
<div className="text-sm p-2 text-slate-500">
{selectedDirectory.name}
</div>
<div className="font-normal">
<div className="font-normal p-1">
<Folder
node={selectedDirectory}
depth={0}
Expand All @@ -114,7 +114,9 @@ export const LocalFileSystem = ({
</div>
</div>
)}
<button onClick={handleDirectorySelect}>Select Directory</button>
{!selectedDirectory && (
<button onClick={handleDirectorySelect}>Select Directory</button>
)}
</div>
);
};
15 changes: 15 additions & 0 deletions src/components/MarkdownEditor/FileEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import DirectoryNode from "../../models/DirectoryNode";
import { RemirrorComponent } from "./RemirrorComponent";

export const FileEditor: React.FC = ({
selectedFile,
}: {
selectedFile: DirectoryNode | null;
}) => {
return (
<div className="flex-1">
<TextField.Input size="3" placeholder="Search the docs…" />
<RemirrorComponent selectedFile={selectedFile} />
</div>
);
};
18 changes: 10 additions & 8 deletions src/components/MarkdownEditor/RemirrorComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const RemirrorComponent: React.FC = ({
};

return (
<div style={{ padding: 16 }}>
<div>
<div className="ml-4 flex flex-col">
<div className="flex flex-row justify-end m-1">
<button
className={` bg-blue-500 text-white px-2 py-1 rounded hover:bg-blue-600 focus:outline-none focus:ring focus:border-blue-300`}
onClick={() => {
Expand All @@ -53,12 +53,14 @@ export const RemirrorComponent: React.FC = ({
Save
</button>
</div>
<RemirrorMarkdownEditor
key={selectedFile?.getFullPath()}
initialContent={selectedFile?.fileContent}
hooks={hooks}
persistMarkdown={handleMarkdownChange}
></RemirrorMarkdownEditor>
<div className="flex-1 overflow-y-scroll">
<RemirrorMarkdownEditor
key={selectedFile?.getFullPath()}
initialContent={selectedFile?.fileContent}
hooks={hooks}
persistMarkdown={handleMarkdownChange}
></RemirrorMarkdownEditor>
</div>
</div>
);
};
10 changes: 8 additions & 2 deletions src/components/MarkdownEditor/RemirrorMarkdownEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import type { CreateEditorStateProps, Extension } from "remirror";
import type { RemirrorProps, UseThemeProps } from "@remirror/react";
import { Menu as CustomMenu } from "./RemirrorMenu";
import { OnChangeMarkdown } from "./OnChangeMarkdown";
import "./index.css";

interface ReactEditorProps
extends Pick<CreateEditorStateProps, "stringHandler">,
Expand Down Expand Up @@ -92,8 +93,13 @@ export const RemirrorMarkdownEditor: FC<
});

return (
<Remirror manager={manager} autoFocus {...rest}>
<MarkdownToolbar />
<Remirror
manager={manager}
autoFocus
{...rest}
classNames={["overflow-hidden"]}
>
{/* <MarkdownToolbar /> */}
<EditorComponent />
<OnChangeMarkdown
persistMarkdown={(markdown) => {
Expand Down
3 changes: 3 additions & 0 deletions src/components/MarkdownEditor/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.remirror-editor.ProseMirror.overflow-hidden {
overflow: hidden;
}
6 changes: 3 additions & 3 deletions src/pages/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "react";
import { LocalFileSystem } from "../components/FileSystemAdapters/FileSystem/LocalFileSystem";
import { RemirrorComponent } from "../components/MarkdownEditor/RemirrorComponent";
import { FileEditor } from "../components/MarkdownEditor/FileEditor";
import DirectoryNode from "../models/DirectoryNode";

export const EditorPage: React.FC = () => {
Expand All @@ -11,7 +11,7 @@ export const EditorPage: React.FC = () => {
);

return (
<div className="EditorPage">
<div className="EditorPage flex h-dvh w-vw overflow-hidden">
<LocalFileSystem
selectedFile={selectedFile}
setSelectedFile={setSelectedFile}
Expand All @@ -20,7 +20,7 @@ export const EditorPage: React.FC = () => {
selectedFileContent={selectedFileContent}
setSelectedFileContent={setSelectedFileContent}
/>
<RemirrorComponent selectedFile={selectedFile} />
<FileEditor selectedFile={selectedFile} />
</div>
);
};

0 comments on commit 81ad53a

Please sign in to comment.