diff --git a/job1/src/App.js b/job1/src/App.js
index d909bbd..4cdc501 100644
--- a/job1/src/App.js
+++ b/job1/src/App.js
@@ -24,7 +24,7 @@ function App() {
} />
} />
} />
- } />
+ } />
diff --git a/job1/src/Main/Preview/DataSample.js b/job1/src/Main/Preview/DataSample.js
new file mode 100644
index 0000000..d13bccf
--- /dev/null
+++ b/job1/src/Main/Preview/DataSample.js
@@ -0,0 +1,42 @@
+export const post = [
+ {
+ id: 1,
+ title: "취업",
+ likes: "50",
+ date: "08. 01.",
+ type: "laws",
+ contents: "취약계층이 어쩌구 저쩌구..",
+ },
+ {
+ id: 2,
+ title: "실업",
+ likes: "23",
+ date: "08. 01.",
+ type: "laws",
+ contents: "취약계층이 어쩌구 저쩌구..",
+ },
+ {
+ id: 3,
+ title: "보험",
+ likes: "1",
+ date: "08. 01.",
+ type: "news",
+ contents: "취약계층이 어쩌구 저쩌구..",
+ },
+ {
+ id: 4,
+ title: "임금",
+ likes: "46",
+ date: "08. 02.",
+ type: "community",
+ contents: "취약계층이 어쩌구 저쩌구..",
+ },
+ {
+ id: 5,
+ title: "직장 내 괴롭힘",
+ likes: "90",
+ date: "08. 02.",
+ type: "community",
+ contents: "취약계층이 어쩌구 저쩌구..",
+ },
+];
diff --git a/job1/src/Main/Preview/PrevCont.js b/job1/src/Main/Preview/PrevCont.js
deleted file mode 100644
index bafe1d1..0000000
--- a/job1/src/Main/Preview/PrevCont.js
+++ /dev/null
@@ -1,29 +0,0 @@
-import PrevArt from "./PrevArt";
-
-function PrevCont(props) {
- return (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- );
-}
-
-export default PrevCont;
diff --git a/job1/src/Main/Preview/Preview.js b/job1/src/Main/Preview/Preview.js
index d29837a..6c071bb 100644
--- a/job1/src/Main/Preview/Preview.js
+++ b/job1/src/Main/Preview/Preview.js
@@ -1,9 +1,36 @@
-import PrevCont from "./PrevCont";
+import PrevArt from "./PrevArt";
import PrevCommOp from "./PrevCommOp";
import { Link, useNavigate } from "react-router-dom";
+import { useState } from "react";
import "./Preview.css";
+import { post } from "./DataSample";
+
function Preview(props) {
+ const items = post
+ .filter((data) => {
+ if (
+ (data.title.toLowerCase().includes(props.query) ||
+ data.contents.toLowerCase().includes(props.query)) &&
+ data.type === props.type
+ ) {
+ return data;
+ }
+ })
+ .map((data) => {
+ return (
+
+ );
+ });
const navigate = useNavigate();
const navigateToWrite = () => {
navigate("./write");
@@ -12,15 +39,13 @@ function Preview(props) {
return props.type === "home" ? (
) : (
-
- 총 {props.resultNum}건의 검색 결과가 있습니다.
-
+ 총 {items.length}건의 검색 결과가 있습니다.
);
};
const selectBottom = () => {
return props.type !== "home" ? (
-
+
검색 결과 더 보기
@@ -29,20 +54,25 @@ function Preview(props) {
const selectBtn = () => {
return props.type === "home" ? (
) : null;
};
+ console.log(props.query);
+ console.log(post);
+ /*
+ const [searchWord, setSearch] = useState(props.query);
+ */
+
return (
-
{props.title}
+
{props.typeTitle}
{selectType()}
{selectBtn()}
-
-
+ {items}
{selectBottom()}
);
diff --git a/job1/src/View/Home.js b/job1/src/View/Home.js
index b7590e6..c04ee1c 100644
--- a/job1/src/View/Home.js
+++ b/job1/src/View/Home.js
@@ -2,14 +2,14 @@ import Search from "../View/Search";
import Preview from "../Main/Preview/Preview";
import MoreInfo from "../Main/MoreInfo";
-function Home(){
- return(
-
- )
+function Home() {
+ return (
+
+ );
}
export default Home;
diff --git a/job1/src/View/SearchResult.js b/job1/src/View/SearchResult.js
index e3daa19..31b2dd8 100644
--- a/job1/src/View/SearchResult.js
+++ b/job1/src/View/SearchResult.js
@@ -1,12 +1,23 @@
import Preview from "../Main/Preview/Preview";
+import Search from "./Search";
+
+import { useLocation } from "react-router-dom";
function SearchResult() {
+ const location = useLocation();
+ const searchParams = new URLSearchParams(location.search);
+ const query = searchParams.get("query");
return (
- Search Result
-
-
-
+
+
+
+
);
}