-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
154 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import TextInput from "./TextInput"; | ||
import HomePost from "./HomePost"; | ||
import { useAuth } from "../hooks/UseAuth"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { ss_backend } from "../../../declarations/ss_backend"; | ||
import { useLocation } from "react-router-dom"; | ||
|
||
export default function MiddleHomePartSearched({ setCurrPost, currPost }) { | ||
const { isAuthenticated, user } = useAuth(); | ||
const [posts, setPosts] = useState([]); | ||
const { search } = useLocation(); | ||
const searchQuery = new URLSearchParams(search).get("query"); | ||
|
||
const { status: statusFetchingData, mutate: dataMutate } = useMutation({ | ||
mutationKey: ["checkFetch"], | ||
mutationFn: fetchDatas, | ||
}); | ||
|
||
async function fetchDatas() { | ||
await fetchPosts(); | ||
// await fetchFriendHeader(); | ||
return true; | ||
} | ||
|
||
async function fetchPosts() { | ||
const fetchedPosts = await ss_backend.searchPost( | ||
searchQuery === undefined ? "" : searchQuery | ||
); | ||
// console.log(fetchedPosts); | ||
|
||
if (fetchedPosts.ok) { | ||
setPosts(fetchedPosts.ok); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
dataMutate(); | ||
}, [user, posts]); | ||
|
||
return ( | ||
<div className="w-1/2 h-full flex flex-col justify-start"> | ||
<div className=" flex flex-col gap-6"> | ||
{posts.length != 0 && | ||
posts.map((post) => { | ||
return ( | ||
<HomePost | ||
choosePost={setCurrPost} | ||
post={post} | ||
refetch={dataMutate} | ||
/> | ||
); | ||
})} | ||
|
||
{/* <HomePost choosePost={setCurrPost} postId={"dummy"} /> | ||
<HomePost choosePost={setCurrPost} postId={"dummy"} /> */} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,40 @@ | ||
import React from "react"; | ||
import React, { useState } from "react"; | ||
import { useLocation } from "react-router-dom"; | ||
import MainTemplate from "../templates/MainTemplate"; | ||
import ProfileSidebar from "../components/ProfileSidebar"; | ||
import RightHomePart from "../components/RightHomePart"; | ||
import CommentDetailPage from "../components/CommentDetailPage"; | ||
import MiddleHomePart from "../components/MiddleHomePart"; | ||
import DetailPage from "../components/DetailPage"; | ||
import MiddleHomePartSearched from "../components/MiddleHomePartSearched"; | ||
|
||
export default function SearchPage() { | ||
const { search } = useLocation(); | ||
const searchQuery = new URLSearchParams(search).get("query"); | ||
const [currPost, setCurrPost] = useState(); | ||
|
||
return ( | ||
<MainTemplate> | ||
<div>{searchQuery}</div> | ||
<div className=""> | ||
<div className="flex pt-[5rem] justify-around "> | ||
<div className="sticky self-start top-[5rem]"> | ||
<ProfileSidebar /> | ||
</div> | ||
{currPost !== undefined ? ( | ||
<DetailPage currPost={currPost} setCurrPost={setCurrPost} /> | ||
) : ( | ||
<MiddleHomePartSearched | ||
setCurrPost={setCurrPost} | ||
currPost={currPost} | ||
/> | ||
)} | ||
{currPost === undefined ? ( | ||
<div className="sticky self-start top-[5rem]"> | ||
<RightHomePart /> | ||
</div> | ||
) : ( | ||
<CommentDetailPage currPost={currPost} setCurrPost={setCurrPost} /> | ||
)} | ||
</div> | ||
</div> | ||
</MainTemplate> | ||
); | ||
} |