Skip to content

Commit 42bba7a

Browse files
committed
integrate the TextEditor component with workflow
1 parent 005c754 commit 42bba7a

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

client/src/App.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import Menu from "./components/Menu";
1313
import EraserCursor from "./components/EraserCursor";
1414
import TextEditor from "./components/TextEditor";
1515
import { useRecoilValue, useRecoilState } from "recoil";
16-
import { eraserState, cursorPosition, canvasColors, canvasState } from "./atoms";
16+
import { eraserState, cursorPosition, canvasColors, canvasState, showMenuState, showTextEditor } from "./atoms";
1717

1818
function App() {
19-
const [showMenu, setShowMenu] = useState(false);
19+
const [showMenu, setShowMenu] = useRecoilState(showMenuState);
2020
const eraserMode = useRecoilValue(eraserState);
2121
const [position, setPosition] = useRecoilState(cursorPosition);
2222
const [ctx, setCtx] = useState(null);
@@ -29,6 +29,7 @@ function App() {
2929
const [doc, setDoc] = useState(null);
3030
const [provider, setProvider] = useState(null);
3131
const [text, setText] = useState('');
32+
const textEditor = useRecoilValue(showTextEditor);
3233

3334
useEffect(() => {
3435
if (!doc) {
@@ -202,7 +203,7 @@ function App() {
202203
<Canvas canvasRef={canvasRef}></Canvas>
203204
{eraserMode && <EraserCursor></EraserCursor>}
204205
{showMenu && <Menu></Menu>}
205-
<TextEditor></TextEditor>
206+
{textEditor && <TextEditor></TextEditor>}
206207
</div>
207208
);
208209
}

client/src/atoms.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,14 @@ export const canvasColors = atom({
1818
export const canvasState = atom({
1919
key: 'canvasState',
2020
default: ''
21+
})
22+
23+
export const showMenuState = atom({
24+
key: "showMenu",
25+
default: false
26+
})
27+
28+
export const showTextEditor = atom({
29+
key: "showTextEditor",
30+
default: false
2131
})

client/src/components/Menu.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import MenuItem from "./MenuItem";
22
import Socials from "./Socials";
33
import SponsorBtn from "./SponsorBtn";
4-
import { useRecoilValue } from "recoil";
5-
import { canvasState, canvasColors } from "../atoms";
4+
import { useRecoilValue, useRecoilState, useSetRecoilState} from "recoil";
5+
import { canvasState, canvasColors, showTextEditor, showMenuState } from "../atoms";
66
import { jsPDF } from "jspdf";
77

88
function Menu(){
99
const canvas = useRecoilValue(canvasState);
1010
const canvasColor = useRecoilValue(canvasColors);
11+
const [textEditor, setTextEditor] = useRecoilState(showTextEditor)
12+
const setMenuStateFalse = useSetRecoilState(showMenuState);
1113

1214
// function to save canvas as pdf
1315
function saveAsPdf() {
@@ -47,12 +49,18 @@ function Menu(){
4749
document.body.removeChild(link);
4850
}
4951

52+
function openTextEditor(){
53+
setTextEditor(true);
54+
setMenuStateFalse(false);
55+
}
56+
5057
return (
5158
<div className="w-52 h-71 rounded-xl bg-gradient-to-r from-slate-900 to-slate-700 absolute left-52 top-8 rounded-lg shadow-xl">
5259
<MenuItem feat="Start Collaboration"></MenuItem>
5360
<MenuItem feat="Start Chat"></MenuItem>
5461
<MenuItem feat="Save as pdf" clickHandler={saveAsPdf}></MenuItem>
5562
<MenuItem feat="Save as png" clickHandler={saveAsPng}></MenuItem>
63+
<MenuItem feat="Open text editor" clickHandler={openTextEditor}></MenuItem>
5664
<SponsorBtn></SponsorBtn>
5765
<Socials></Socials>
5866
</div>

client/src/components/TextEditor.jsx

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
1-
function TextEditor(){
2-
return (
3-
<div className="w-96 h-96 absolute shadow rounded absolute">
4-
<div className="bg-gray bg-slate-800 w-96 h-14 content-center">
5-
<h1 className="font-sans text-white text-lg justify-center flex">
6-
Plan your drawing
7-
</h1>
8-
</div>
9-
<textarea
10-
className="w-96 h-80 border rounded absolute focus:outline-none focus:ring-0 focus:border-transparent"
11-
placeholder="E.g. Make a painting with trees..."
12-
></textarea>
1+
import { useSetRecoilState } from "recoil";
2+
import { showTextEditor } from "../atoms";
3+
4+
function TextEditor() {
5+
const setTextEditorFalse = useSetRecoilState(showTextEditor);
6+
7+
function removeTextEditor() {
8+
setTextEditorFalse(false);
9+
}
10+
11+
return (
12+
<div className="w-96 h-96 absolute shadow rounded absolute">
13+
<div className="bg-gray bg-slate-800 w-96 h-14 content-center">
14+
<h1 className="font-sans text-white text-lg justify-center flex">
15+
Plan your drawing
16+
</h1>
17+
<h1
18+
className="font-sans text-white text-2xl justify-center absolute right-5 top-3 cursor-pointer hover:text-emerald-300"
19+
onClick={removeTextEditor}
20+
>
21+
×
22+
</h1>
1323
</div>
14-
);
24+
<textarea
25+
className="w-96 h-80 border rounded absolute focus:outline-none focus:ring-0 focus:border-transparent"
26+
placeholder="E.g. Make a painting with trees..."
27+
></textarea>
28+
</div>
29+
);
1530
}
1631

17-
export default TextEditor;
32+
export default TextEditor;

0 commit comments

Comments
 (0)