diff --git a/src/components/Editor/Components/Builder.tsx b/src/components/Editor/Components/Builder.tsx
index 527e343..e8e4a92 100644
--- a/src/components/Editor/Components/Builder.tsx
+++ b/src/components/Editor/Components/Builder.tsx
@@ -6,7 +6,7 @@ const Builder = () => {
return (
-
+
diff --git a/src/components/Editor/Components/EditSection.tsx b/src/components/Editor/Components/EditSection.tsx
index 763940a..f7bd927 100644
--- a/src/components/Editor/Components/EditSection.tsx
+++ b/src/components/Editor/Components/EditSection.tsx
@@ -1,17 +1,29 @@
-import React, { useState } from "react";
+import React, { useEffect, useState } from "react";
import { List, Reset, TrashCan } from "@carbon/icons-react";
import { useSortable } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";
import clsx from "clsx";
+import { useSection } from "context/SectionContext";
+import { SectionsType } from "../types";
-interface Props {
- id: number;
- title: string | undefined;
- markdown: string | undefined;
+interface Props extends SectionsType {
+ focusSection: number;
+ setFocusSection: React.Dispatch
>;
onDeleteSection: (e: React.MouseEvent, targetId: number) => void;
+ onResetSection: (e: React.MouseEvent, targetId: number) => void;
}
-const EditSection = ({ id, title, markdown, onDeleteSection }: Props) => {
+const EditSection = ({
+ id,
+ title,
+ markdown,
+ focusSection,
+ setFocusSection,
+ onDeleteSection,
+ onResetSection,
+}: Props) => {
+ const { state, actions } = useSection();
+
const [hover, setHover] = useState(false);
const onMouseEnter = () => setHover(true);
const onMouseLeave = () => setHover(false);
@@ -23,11 +35,21 @@ const EditSection = ({ id, title, markdown, onDeleteSection }: Props) => {
transform: CSS.Transform.toString(transform),
};
+ const onClickSection = () => {
+ actions.setEditorMarkDown(prev => ({ ...prev, id, title, markdown }));
+ setFocusSection(id);
+ };
+
+ useEffect(() => {
+ localStorage.setItem("select-section", JSON.stringify(state.editorMarkDown));
+ }, [onClickSection]);
+
return (
{
"rounded-[8px] border-solid border bg-white border-[#F1F3F5] drop-shadow-[0_1px_1px_rgba(173,181,189,0.25)]",
"cursor-pointer",
{
- "focus:outline-none focus:ring-2 focus:ring-textBlue": true,
+ "ring-2 ring-textBlue": focusSection === id,
},
)}
>
{title}
- {hover && (
+ {focusSection === id && (
-
- {selectedTab === "Preview" &&
}
- {selectedTab === "Raw" &&
}
+ {selectedTab === "Preview" &&
}
+ {selectedTab === "Raw" &&
}
>
diff --git a/src/components/Editor/Modal/AddSectionModal.tsx b/src/components/Editor/Modal/AddSectionModal.tsx
index 04279b4..fb800a2 100644
--- a/src/components/Editor/Modal/AddSectionModal.tsx
+++ b/src/components/Editor/Modal/AddSectionModal.tsx
@@ -14,7 +14,7 @@ const AddSectionModal = ({ modalRef, modalOutSideClick, onClose, openModal }: Pr
if (openModal) {
inputRef.current?.focus();
}
- }, []);
+ }, [openModal]);
return (
void;
+ state: { markDowns: SectionsType[]; editorMarkDown: SectionsType };
+ actions: {
+ setMarkDowns: React.Dispatch>;
+ setEditorMarkDown: React.Dispatch>;
+ };
}
interface SectionContextProviderProps {
@@ -20,16 +24,17 @@ export const useSection = () => {
};
export const SectionProvider = ({ children }: SectionContextProviderProps) => {
- const [value, setValue] = useState("# Welcome To README-MONSTER");
+ const [markDowns, setMarkDowns] = useState([]);
+ const [editorMarkDown, setEditorMarkDown] = useState({
+ id: 0,
+ title: "",
+ markdown: "# Welcome To README-MONSTER",
+ });
- return (
-
- {children}
-
- );
+ const value = {
+ state: { markDowns, editorMarkDown },
+ actions: { setMarkDowns, setEditorMarkDown },
+ };
+
+ return {children};
};
diff --git a/src/styles/global.css b/src/styles/global.css
index a40545b..75ed1d7 100644
--- a/src/styles/global.css
+++ b/src/styles/global.css
@@ -19,7 +19,7 @@
}
.editor .w-md-editor-content {
- padding: 5px
+ padding: 10px
}
.white {