Skip to content

Commit

Permalink
Add view / edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
devleejb committed Jan 12, 2024
1 parent a01bc3c commit 59f61a0
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 50 deletions.
14 changes: 2 additions & 12 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"prettier": "prettier . --check"
},
"dependencies": {
"@codemirror/commands": "^6.3.3",
"@codemirror/lang-markdown": "^6.2.3",
"@codemirror/view": "^6.23.0",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@fontsource/roboto": "^5.0.8",
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { yorkieCodeMirror } from "../../utils/yorkie";
import toolbar, { markdownItems } from "codemirror-toolbar";
import { xcodeLight, xcodeDark } from "@uiw/codemirror-theme-xcode";
import { useCurrentTheme } from "../../hooks/useCurrentTheme";
import { keymap } from "@codemirror/view";
import { indentWithTab } from "@codemirror/commands";

function Editor() {
const themeMode = useCurrentTheme();
Expand Down Expand Up @@ -39,6 +41,7 @@ function Editor() {
"&": { width: "100%" },
}),
EditorView.lineWrapping,
keymap.of([indentWithTab]),
],
});

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/editor/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Preview() {
};
}, [editorStore.doc]);

if (!editorStore?.doc) return <CircularProgress sx={{ marginX: "auto" }} />;
if (!editorStore?.doc) return <CircularProgress sx={{ marginX: "auto", mt: 4 }} />;

return (
<MarkdownPreview
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/headers/EditorHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function EditorHeader() {
<VerticalSplitIcon />
</Tooltip>
</ToggleButton>
<ToggleButton value="view" aria-label="view">
<Tooltip title="View Mode">
<ToggleButton value="read" aria-label="read">
<Tooltip title="Read Mode">
<VisibilityIcon />
</Tooltip>
</ToggleButton>
Expand Down
78 changes: 44 additions & 34 deletions frontend/src/pages/editor/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useEffect } from "react";
import Editor from "../../components/editor/Editor";
import * as yorkie from "yorkie-js-sdk";
import { setClient, setDoc } from "../../store/editorSlice";
import { useDispatch } from "react-redux";
import { selectEditor, setClient, setDoc } from "../../store/editorSlice";
import { useDispatch, useSelector } from "react-redux";
import {
YorkieCodeMirrorDocType,
YorkieCodeMirrorPresenceType,
Expand All @@ -17,6 +17,7 @@ import Preview from "../../components/editor/Preview";
function EditorIndex() {
const dispatch = useDispatch();
const windowWidth = useWindowWidth();
const editorStore = useSelector(selectEditor);

useEffect(() => {
let client: yorkie.Client;
Expand Down Expand Up @@ -55,42 +56,51 @@ function EditorIndex() {

return (
<Box height="calc(100% - 64px)">
<Resizable axis={"x"} initial={windowWidth / 2} min={400}>
{({ position: width, separatorProps }) => (
<div
id="wrapper"
style={{
display: "flex",
height: "100%",
overflow: "hidden",
}}
>
<div id="left-block" style={{ width }}>
<Editor />
</div>
<Paper
id="splitter"
{...separatorProps}
sx={{
{/* For Markdown Preview Theme */}
<div className="wmde-markdown-var" />
{editorStore.mode === "both" && (
<Resizable axis={"x"} initial={windowWidth / 2} min={400}>
{({ position: width, separatorProps }) => (
<div
id="wrapper"
style={{
display: "flex",
height: "100%",
width: 8,
borderRadius: 0,
cursor: "col-resize",
zIndex: 100,
overflow: "hidden",
}}
/>
<div
className="right-block"
style={{ width: `calc(100% - ${width}px)`, overflow: "auto" }}
>
<div className="wmde-markdown-var" />
<Box sx={{ p: 4 }} height="100%">
<Preview />
</Box>
<div id="left-block" style={{ width }}>
<Editor />
</div>
<Paper
id="splitter"
{...separatorProps}
sx={{
height: "100%",
width: 8,
borderRadius: 0,
cursor: "col-resize",
zIndex: 100,
}}
/>
<div
className="right-block"
style={{ width: `calc(100% - ${width}px)`, overflow: "auto" }}
>
<Box sx={{ p: 4 }} height="100%">
<Preview />
</Box>
</div>
</div>
</div>
)}
</Resizable>
)}
</Resizable>
)}
{editorStore.mode === "read" && (
<Box sx={{ p: 4, overflow: "auto" }} height="100%">
<Preview />
</Box>
)}
{editorStore.mode === "edit" && <Editor />}
</Box>
);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/store/editorSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RootState } from "./store";
import * as yorkie from "yorkie-js-sdk";
import { YorkieCodeMirrorDocType, YorkieCodeMirrorPresenceType } from "../utils/yorkie/yorkieSync";

export type EditorModeType = "view" | "both" | "read";
export type EditorModeType = "edit" | "both" | "read";
export type CodePairDocType = yorkie.Document<
YorkieCodeMirrorDocType,
YorkieCodeMirrorPresenceType
Expand Down

0 comments on commit 59f61a0

Please sign in to comment.