diff --git a/forum/src/components/Atoms.tsx b/forum/src/components/Atoms.tsx index 233e7fc60..fbd9c29e0 100644 --- a/forum/src/components/Atoms.tsx +++ b/forum/src/components/Atoms.tsx @@ -1,8 +1,8 @@ -import * as React from 'react'; -import { atom } from 'recoil'; -import { useRecoilState } from 'recoil'; +import * as React from "react"; +import { atom } from "recoil"; +import { useRecoilState } from "recoil"; -export const TagState = atom({ - key: 'tagState', - default: [], - }); \ No newline at end of file +export const TagState = atom({ + key: "tagState", + default: [], +}); diff --git a/forum/src/components/BoardMenu.tsx b/forum/src/components/BoardMenu.tsx index 6076e6143..af5bd1d7a 100644 --- a/forum/src/components/BoardMenu.tsx +++ b/forum/src/components/BoardMenu.tsx @@ -26,7 +26,6 @@ const menuItems: any[] = [ // icon: , // title: "School Select" // }, - ]; const BoardMenu = () => { diff --git a/forum/src/components/FilterMenu.tsx b/forum/src/components/FilterMenu.tsx index 8c25b730f..51ef87765 100644 --- a/forum/src/components/FilterMenu.tsx +++ b/forum/src/components/FilterMenu.tsx @@ -1,17 +1,16 @@ import React, { useState } from "react"; import { useNavigate } from "react-router-dom"; -import TagsModal from "./TagsModal"; - +import SearchTags from "./SearchTags"; const FilterMenu = () => { const [openSchoolModal, setOpenSchoolModal] = useState(false); const [openTagsModal, setOpenTagsModal] = useState(false); - + const navigate = useNavigate(); const showTagsModal = () => { setOpenSchoolModal(true); - } + }; return ( // New component created by Michael -- Zero functionality so far, moreso there for visuals @@ -34,7 +33,7 @@ const FilterMenu = () => { > Select the School - + {/* School Select Div */}

Undergrad, Grad

@@ -44,9 +43,9 @@ const FilterMenu = () => {

English

-
+
- +
); diff --git a/forum/src/components/SearchTags.tsx b/forum/src/components/SearchTags.tsx new file mode 100644 index 000000000..89887814d --- /dev/null +++ b/forum/src/components/SearchTags.tsx @@ -0,0 +1,185 @@ +import React, { useState } from "react"; +import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil"; +import { atom } from "recoil"; +import { TagState } from "./Atoms"; + +const SearchTags: React.FC = () => { + const [show, setShow] = useState(false); + const toggleShow = () => setShow(!show); + + const tagState = useRecoilValue(TagState); + + const [selectedTags, setSelectedTags] = useState<[]>([]); + const setTagsSelected = useSetRecoilState(TagState); + { + /* Later, use useEffect hook to fetch tags from the server side. */ + } + const tags: Array = [ + "alpha", + "apple", + "adios", + "amigo", + "amino", + "bravo", + "charlie", + "delta", + ]; + const academicTags: Array = [ + "Courses", + "Professors", + "Seminars/Labs", + "Research", + "School Applications", + ]; + const campusTags: Array = [ + "Facilities", + "Circles", + "Events", + "Scholarships", + ]; + const lifeTags: Array = [ + "Gourmet", + "Culture", + "Languages", + "Housing", + "Travels", + "Events", + ]; + const jobTags: Array = ["Part-time", "Internships", "Job Hunting"]; + + const [query, setQuery] = useState(""); + + const handleClick = (item: string) => { + if (!selectedTags.includes(item)) { + setSelectedTags((selectedTags) => [...selectedTags, item]); + } + }; + + const handleCloseModal = () => { + toggleShow(); + setSelectedTags([]); + }; + + const handleClose = () => { + setSelectedTags([]); + setQuery(""); + setShow(false); + }; + + const handleChange = (event: React.ChangeEvent) => { + const value = event.target.value; + if (selectedTags.indexOf(value) === -1) { + setSelectedTags([...selectedTags, value]); + } else { + setSelectedTags(selectedTags.filter((item) => item !== value)); + } + }; + + const handleSubmit = (event: React.FormEvent) => { + event.preventDefault(); + toggleShow(); + setTagsSelected(selectedTags); + setQuery(""); + }; + + return ( + <> + + {/* -------------------------------------------------- */} +
+
+
+ Choose Your Tags +
+
+ {/* SEARCH COMPONENT PART */} +
+
+ setQuery(e.target.value)} + className="h-full w-full px-4 py-4 shadow-lg rounded-md" + placeholder="Search" + /> +
+
    + {tags + .filter((item) => { + const searchTerm = query.toLowerCase(); + const existingTerm = item.toLocaleLowerCase(); + return searchTerm && existingTerm.startsWith(searchTerm); + }) + .map((item) => ( +
  • handleClick(item)} + > + {item} +
  • + ))} +
+ +
+ {tags.map((tag) => ( + + ))} +
+ {/* DISPLAY FOR CURRENT SELECTED TAGS */} + {selectedTags.length > 0 && ( +
+ {selectedTags.map((tag) => ( + + ))} +
+ )} +
+ + +
+
+
+ + ); +}; + +export default SearchTags; diff --git a/forum/src/components/TagsModal.tsx b/forum/src/components/TagsModal.tsx deleted file mode 100644 index 143fbbb2b..000000000 --- a/forum/src/components/TagsModal.tsx +++ /dev/null @@ -1,102 +0,0 @@ -import React from "react"; -import { useState, useEffect } from "react"; -import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'; -import { atom } from 'recoil'; -import { TagState } from './Atoms' - -const TagsModal: React.FC = () => { - const [show, setShow] = useState(false); - - const handleClose = () => setShow(false); - const toggleShow = () => setShow(!show); - - const testing = useRecoilState(TagState) - - const tags: Array = ["tag1", "tag2", "tag3"]; - /* const tags = useRecoilValue(TagState) */ - const [selectedTags, setSelectedTags] = useState<[]>([]) - const setTagsSelected = useSetRecoilState(TagState); - const handleChange = (event: React.ChangeEvent) => { - const value = event.target.value; - if (selectedTags.indexOf(value) === -1) { - setSelectedTags([...selectedTags, value]); - } else { - setSelectedTags(selectedTags.filter((item) => item !== value)); - } - }; - console.log(selectedTags); - - const handleSubmit = (event: React.FormEvent) => { - event.preventDefault(); - toggleShow(); - setTagsSelected(selectedTags) - }; - console.log(testing) - return ( - <> - - - {/* avoid using undefined class name and attributes (modal and data-bs-blablabla are from the library Bootstrap, which is not installed in Forum app) */} - {/* Why not making use of the state `show` since you are already defined one? */} - {/* TODO for KJ: Remove all undefined classnames and attributes (those from Bootstrap) (Hao removed some but plz check if there are other not removed ones) */} - {/* TODO for KJ: Try to adjust the size and margin (You can do it after moving the modal to board menu) */} -
-
-
-
-
- Choose Your Tags -
-
-
- {tags.map(tag => ( -
- -
- ))} -
-
- - -
-
-
-
- - ); -}; - -export default TagsModal; diff --git a/forum/src/root.component.tsx b/forum/src/root.component.tsx index 83f00d8a2..82a7857b9 100644 --- a/forum/src/root.component.tsx +++ b/forum/src/root.component.tsx @@ -7,7 +7,7 @@ import App from "@app/components/App"; import translationEN from "@app/constants/locales/en/translation.json"; import translationJA from "@app/constants/locales/ja/translation.json"; import { ThemeProvider } from "@app/utils/theme-context"; -import { RecoilRoot } from 'recoil'; +import { RecoilRoot } from "recoil"; import "@app/styles/main.css";