Skip to content

Commit

Permalink
Merge pull request #64 from prgrms-fe-devcourse/Deploy/version-1.0.0
Browse files Browse the repository at this point in the history
hotfix: ์ฑ„๋„ ์—†์„ ์‹œ ๋ฐ”๋กœ๊ฐ€๊ธฐ ๋ฒ„ํŠผ ์ถ”๊ฐ€
  • Loading branch information
SoJuSo committed Jan 11, 2024
2 parents d165d13 + 4028e00 commit a59679d
Showing 1 changed file with 51 additions and 14 deletions.
65 changes: 51 additions & 14 deletions src/pages/HomePage/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useEffect, useState } from "react";
import PostSimpleCard from "@/components/common/PostSimpleCard";
import styled from "styled-components";

import { useEffect, useState } from "react";
import { _GET } from "@/api";
import { _CHANNEL_POSTS } from "@/api/queries/channelPosts";
import { useLocalStorage } from "@/hooks/useLocalStorage";
import PostSimpleCard from "@/components/common/PostSimpleCard";
import { _CHANNEL_POSTS } from "@/api/queries/channelPosts";
import { Button } from "@/components/common";
import { useNavigate } from "react-router-dom";

const Container = styled.div`
box-sizing: border-box;
Expand All @@ -19,30 +20,66 @@ const Container = styled.div`
`;

const Home = () => {
const navigate = useNavigate();
const [channel, _] = useLocalStorage("ViewChannelObj");
const [data, setData] = useState<any[]>([]);
const [data, setData] = useState<any[] | null>(null);

const fetchData = async (query: string) => {
const res = await _CHANNEL_POSTS(query);
if (res) setData(res);
};

const handleClick = () => {
navigate("/channels");
};

useEffect(() => {
if (channel) {
const parsedData = JSON.parse(channel);
fetchData(parsedData._id);
}
}, []);

return (
<>
<Container>
{data.map((value, index) => (
<PostSimpleCard key={index} postData={value} />
))}
</Container>
</>
);
if (channel === null) {
return (
<>
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
paddingTop: "3rem",
paddingBottom: "3rem",
width: "100%",
height: "100%",
}}
>
<span style={{ fontSize: "2rem", marginBottom: "1rem" }}>
์ฑ„๋„์„ ์„ ํƒํ•ด๋ณด์„ธ์š”!
</span>
<Button
onClick={handleClick}
style={{ width: "50%" }}
variant="symbol"
>
๋ฐ”๋กœ ๊ฐ€๊ธฐ
</Button>
</div>
</>
);
}

if (data && data.length > 0) {
return (
<>
<Container>
{data.map((value, index) => (
<PostSimpleCard key={index} postData={value} />
))}
</Container>
</>
);
}
};

export default Home;

0 comments on commit a59679d

Please sign in to comment.