diff --git a/src/components/Editor/Components/EditSection.tsx b/src/components/Editor/Components/EditSection.tsx index d47c9f5..f7f2636 100644 --- a/src/components/Editor/Components/EditSection.tsx +++ b/src/components/Editor/Components/EditSection.tsx @@ -11,7 +11,7 @@ interface Props extends SectionsType { onResetSection: (e: React.MouseEvent, section: SectionsType) => void; } -const EditSection = ({ id, title, markdown, onDeleteSection, onResetSection }: Props) => { +const EditSection = ({ id, title, markdown, name, onDeleteSection, onResetSection }: Props) => { const { state, actions } = useSection(); const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id }); @@ -20,6 +20,13 @@ const EditSection = ({ id, title, markdown, onDeleteSection, onResetSection }: P transform: CSS.Transform.toString(transform), }; + const section = { + id, + name, + title, + markdown, + }; + const onClickSection = (e: React.MouseEvent, section: SectionsType) => { e.stopPropagation(); actions.setEditorMarkDown(prev => ({ ...prev, ...section })); @@ -35,7 +42,7 @@ const EditSection = ({ id, title, markdown, onDeleteSection, onResetSection }: P ref={setNodeRef} {...attributes} style={style} - onClick={e => onClickSection(e, { id, title, markdown })} + onClick={e => onClickSection(e, section)} className={clsx( "w-full h-[45px] py-[8px] px-[12px]", "flex flex-row gap-[10px] items-center", @@ -50,10 +57,10 @@ const EditSection = ({ id, title, markdown, onDeleteSection, onResetSection }: P

{title}

{state.focusSection === id && (
- -
diff --git a/src/components/Editor/Components/EditSections.tsx b/src/components/Editor/Components/EditSections.tsx index 7003cbb..44c1145 100644 --- a/src/components/Editor/Components/EditSections.tsx +++ b/src/components/Editor/Components/EditSections.tsx @@ -128,6 +128,7 @@ const EditSections = () => { {sections.map(section => ( { +interface Props { + search: string; + setSearch: React.Dispatch>; +} + +const SearchSection = ({ search, setSearch }: Props) => { return ( -
-
- - + + setSearch(e.target.value)} + type="text" + className=" w-full h-[45px] p-[10px] pl-[40px] rounded-[8px] drop-shadow-[0_1px_1px_rgba(173,181,189,0.25)] border border-[#F1F3F5] focus:outline-none focus:ring-2 focus:ring-textBlue placeholder-[#ADB5BD] placeholder:text-[14px] " - placeholder="Search for a section" - /> -
-
+ placeholder="Search for a section" + /> + ); }; diff --git a/src/components/Editor/Components/SelectSection.tsx b/src/components/Editor/Components/SelectSection.tsx index 1ada40b..695f251 100644 --- a/src/components/Editor/Components/SelectSection.tsx +++ b/src/components/Editor/Components/SelectSection.tsx @@ -7,10 +7,17 @@ interface Props extends SectionsType { onClickSection: (e: React.MouseEvent, section: SectionsType) => void; } -const SelectSection = ({ id, title, markdown, onClickSection }: Props) => { +const SelectSection = ({ id, name, title, markdown, onClickSection }: Props) => { + const section = { + id, + name, + title, + markdown, + }; + return (
onClickSection(e, { id, title, markdown })} + onClick={e => onClickSection(e, section)} className=" w-full h-[45px] py-[8px] px-[12px] flex items-center diff --git a/src/components/Editor/Components/SelectSections.tsx b/src/components/Editor/Components/SelectSections.tsx index ca25812..46bfe14 100644 --- a/src/components/Editor/Components/SelectSections.tsx +++ b/src/components/Editor/Components/SelectSections.tsx @@ -12,9 +12,11 @@ const SelectSections = () => { const localData = JSON.parse(localStorage.getItem("select-sections-list") || "[]"); return localData.length > 0 ? localData : state.selectSections; }); - + const [search, setSearch] = useState(""); + const [searchSection, setSerchSection] = useState([]); const [openModal, setOpenModal] = useState(false); const modalRef = useRef(null); + const sectionList = search.length > 0 ? searchSection : sections; const modalOutSideClick = (e: any) => { if (modalRef.current === e.target) { @@ -42,6 +44,18 @@ const SelectSections = () => { }, []); useEffect(() => { + if (search.length > 0) { + const searchSection = sections.filter(s => { + return s.name.toLowerCase().includes(search.toLowerCase()); + }); + setSerchSection(searchSection); + } else { + setSections(state.selectSections); + } + }, [search]); + + useEffect(() => { + setSearch(""); setSections(state.selectSections); }, [state.selectSections]); @@ -56,11 +70,12 @@ const SelectSections = () => {
- - {sections.map(section => ( + + {sectionList.map(section => ( { const [editSections, setEditSections] = useState([]); const [editorMarkDown, setEditorMarkDown] = useState({ id: 0, - title: "", + name: "Welcome", + title: "Welcome", markdown: "# Welcome To README-MONSTER", }); const [focusSection, setFocusSection] = useState(undefined); diff --git a/src/data/index.ts b/src/data/index.ts index 01ff3e4..df5d2c4 100644 --- a/src/data/index.ts +++ b/src/data/index.ts @@ -3,61 +3,66 @@ import { SectionsType } from "components/Editor/types"; export const sections: SectionsType[] = [ { id: 1, + name: "Project Title", title: "Project Title", markdown: `## Project Title - A brief description of what this project does and who it's for +A brief description of what this project does and who it's for `, }, { id: 2, + name: "Installation", title: "Installation", markdown: `## Installation - Install my-project with npm +Install my-project with npm - \`\`\`bash - npm install my-project - cd my-project - \`\`\` +\`\`\`bash + npm install my-project + cd my-project +\`\`\` `, }, { id: 3, + name: "Running Tests", title: "Running Tests", markdown: `## Running Tests - To run tests, run the following command +To run tests, run the following command - \`\`\`bash - npm run test - \`\`\` +\`\`\`bash + npm run test +\`\`\` `, }, { id: 4, + name: "Tech Stack", title: "Tech Stack", markdown: `## 🛠️ Tech Stack - - [React](https://reactjs.org/) - - [Next.js](https://nextjs.org/) - - [TypeScript](https://www.typescriptlang.org/) - - [Tailwind CSS](https://tailwindcss.com/) +- [React](https://reactjs.org/) +- [Next.js](https://nextjs.org/) +- [TypeScript](https://www.typescriptlang.org/) +- [Tailwind CSS](https://tailwindcss.com/) `, }, { id: 5, + name: "Add Table", title: "Add Table", markdown: `## Add Table - | Column 1 | Column 2 | Column 3 | - | -------- | -------- | -------- | - | Row 1 | Row 1 | Row 1 | - | Row 2 | Row 2 | Row 2 | - | Row 3 | Row 3 | Row 3 | +| Column 1 | Column 2 | Column 3 | +| -------- | -------- | -------- | +| Row 1 | Row 1 | Row 1 | +| Row 2 | Row 2 | Row 2 | +| Row 3 | Row 3 | Row 3 | `, },