-
Notifications
You must be signed in to change notification settings - Fork 6
Feat: 링크 검색 기능, 링크 추가 기능 구현 #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "feature/Link-\uD398\uC774\uC9C0"
Changes from 4 commits
7dd4754
4055f2b
6eaaace
68874c1
db99170
ba25f72
729e5a5
b00868b
866a0f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,20 @@ | ||
| import { ChangeEvent, KeyboardEvent, useState } from "react"; | ||
| import { FolderListData } from "@/types/folderTypes"; | ||
| import { Modal } from "../modal/modalManager/ModalManager"; | ||
| import Image from "next/image"; | ||
| import SubmitButton from "../SubMitButton"; | ||
| import useModalStore from "@/store/useModalStore"; | ||
|
|
||
| const AddLinkInput = ({ folderList }: FolderListData) => { | ||
| const { isOpen, openModal } = useModalStore(); | ||
| const [link, setLink] = useState(""); | ||
|
|
||
| const handleChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
| setLink(e.target.value); | ||
| }; | ||
|
|
||
| const handleClick = () => { | ||
| // Addmodal 띄우면서 link 전달 | ||
| openModal("AddModal", { list: folderList, link: link }); | ||
| }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 잘 적용해주셨군요👍
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 링크 추가 후에도 인풋에 입력값이 남아있어서 여기서 초기값 "" 으로 setLink 해주는게 좋을것같아요! |
||
|
|
||
| const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => { | ||
|
|
@@ -34,6 +37,7 @@ const AddLinkInput = ({ folderList }: FolderListData) => { | |
| <div onClick={handleClick}> | ||
| <SubmitButton className="w-[80px] h-[37px]">추가하기</SubmitButton> | ||
| </div> | ||
| {isOpen && <Modal />} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| interface SearchResultMessageProps { | ||
| message: string | string[]; | ||
| } | ||
|
|
||
| const SearchResultMessage = ({ message }: SearchResultMessageProps) => { | ||
| return ( | ||
| <div className="text-[32px] text-gray400 mt-[40px]"> | ||
| <span className="text-black300">"{message}"</span>으로 검색한 | ||
| 결과입니다. | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default SearchResultMessage; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,27 @@ | ||
| import { useEffect } from "react"; | ||
| import { GetServerSidePropsContext } from "next"; | ||
| import { useRouter } from "next/router"; | ||
| import { proxy } from "@/lib/api/axiosInstanceApi"; | ||
| import { LinkData } from "@/types/linkTypes"; | ||
| import { FolderData } from "@/types/folderTypes"; | ||
| import { SearchInput } from "../../components/Search/SearchInput"; | ||
| import { Modal } from "@/components/modal/modalManager/ModalManager"; | ||
| import { useLinkCardStore } from "@/store/useLinkCardStore"; | ||
| import { useEffect } from "react"; | ||
| import Container from "@/components/Layout/Container"; | ||
| import { SearchInput } from "../../components/Search/SearchInput"; | ||
| import CardsLayout from "@/components/Layout/CardsLayout"; | ||
| import ActionButtons from "@/components/Link/ActionButtons"; | ||
| import AddLinkInput from "@/components/Link/AddLinkInput"; | ||
| import Container from "@/components/Layout/Container"; | ||
| import ActionButtons from "@/components/link/ActionButtons"; | ||
| import AddLinkInput from "@/components/link/AddLinkInput"; | ||
| import SearchResultMessage from "@/components/Search/SearchResultMessage"; | ||
| import useModalStore from "@/store/useModalStore"; | ||
| import FolderTag from "../../components/FolderTag"; | ||
| import LinkCard from "../../components/LinkCard"; | ||
| import useModalStore from "@/store/useModalStore"; | ||
|
|
||
| interface LinkPageProps { | ||
| linkList: LinkData[]; | ||
| folderList: FolderData[]; | ||
| } | ||
|
|
||
| // /link 페이지 접속시에 초기렌더링 데이터(전체 폴더, 전체링크리스트)만 fetch해서 client로 전달. | ||
| export const getServerSideProps = async ( | ||
| context: GetServerSidePropsContext | ||
| ) => { | ||
|
|
@@ -40,21 +43,34 @@ export const getServerSideProps = async ( | |
|
|
||
| return { | ||
| props: { | ||
| link: links || [], | ||
| linkList: links.list || [], | ||
| folderList: folders || [], | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| const LinkPage = ({ linkList, folderList }: LinkPageProps) => { | ||
| const LinkPage = ({ linkList: initialLinkList, folderList }: LinkPageProps) => { | ||
| const router = useRouter(); | ||
| const { search } = router.query; | ||
| const { isOpen, openModal } = useModalStore(); | ||
| const { linkCardList, setLinkCardList } = useLinkCardStore(); | ||
|
|
||
| // 검색어 입력시 관련된 목록으로 setLinkCardList | ||
| useEffect(() => { | ||
| const fetchNewList = async () => { | ||
| const res = await proxy.get("/api/links", { | ||
| params: { search }, | ||
| }); | ||
| console.log(res.data); | ||
|
||
| setLinkCardList(res.data.list); | ||
| }; | ||
| if (search !== undefined) fetchNewList(); | ||
| }, [setLinkCardList, search]); | ||
|
|
||
| // 클라이언트에서 초기 목록을 설정 | ||
| useEffect(() => { | ||
| setLinkCardList(linkList); | ||
| }, [linkList, setLinkCardList]); | ||
| setLinkCardList(initialLinkList); | ||
| }, [initialLinkList, setLinkCardList]); | ||
|
|
||
| // EditLink 호출 | ||
| const openEdit = (link: string, linkId: number) => { | ||
|
|
@@ -74,6 +90,7 @@ const LinkPage = ({ linkList, folderList }: LinkPageProps) => { | |
| <main className="mt-[40px]"> | ||
| <Container> | ||
| <SearchInput /> | ||
| {search && <SearchResultMessage message={search} />} | ||
| <div className="flex justify-between mt-[40px]"> | ||
| {folderList && <FolderTag folderList={folderList} />} | ||
| <button className="w-[79px] h-[19px] text-purple100"> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CardsLayout 레이아웃에 margin 을 추가하면 즐겨찾기 페이지에서도 css 가 적용되어서 아래 영역에 추가하는 게 더 좋을 것 같습니다!
