Skip to content

Commit

Permalink
[Edit] show all boards and create board
Browse files Browse the repository at this point in the history
  • Loading branch information
winnieworld committed Oct 10, 2023
1 parent abf82b3 commit 9d647b7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
7 changes: 4 additions & 3 deletions Types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export type LayoutType = React.PropsWithChildren & {
export interface FeedInfoType {
id: number;
nickName: string;
content: string;
time: string;
img: string;
contents: string;
title: string;
imageUrl: string;
updated_at: string;
}
6 changes: 3 additions & 3 deletions app/components/Feed/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Feed: React.FC<Props> = ({ feeds }) => {
</svg> */}
</FeedFlex>
<Background>
<FeedImg src="https://mblogthumb-phinf.pstatic.net/MjAyMTAzMDFfNjUg/MDAxNjE0NTI4ODc2NzQ0.pWSoz-Jz0w_oGaU0CGeY5ft44-JR0-imABKI8c75HZUg.TzCOn_c2cG2Z_Ih5q1hT9tNMozqbha7PYXK0NyMUObog.JPEG.qkrchdud5/output_2772876332.jpg?type=w800"></FeedImg>
<FeedImg src={feed.imageUrl}></FeedImg>
</Background>
{/* 다음 버전 */}
{/* <FeedFlex style={{ margin: "4px 0" }}>
Expand Down Expand Up @@ -93,9 +93,9 @@ const Feed: React.FC<Props> = ({ feeds }) => {
{/* <LikeNum>{`좋아요 ${feed.likeNum}개`}</LikeNum> */}
<FlexBox>
<ContentNickName>{feed.nickName}</ContentNickName>
<Discription>{feed.content}</Discription>
<Discription>{feed.contents}</Discription>
</FlexBox>
<Time>{feed.time}</Time>
<Time>{feed.updated_at}</Time>
</Content>
</div>
))}
Expand Down
26 changes: 8 additions & 18 deletions app/create/FileLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,9 @@ const FileLoader = () => {
const makeBoard = () => {
const formData = new FormData();

images.forEach((image) => {
formData.append("files", image);
});
formData.append(
"request",
new Blob(
[
JSON.stringify({
title,
contents,
}),
],
{ type: "application/json" }
)
);
formData.append("files", images[0][0]);
formData.append("request", `{"title":"${title}","contents":"${contents}"}`);

const res = createBoard(formData);
res.then((info) => {
if (info.code !== 200) console.log(info.message);
Expand Down Expand Up @@ -83,7 +71,9 @@ const FileLoader = () => {

return (
<div>
<AbsoluteIcon onClick={makeBoard}>등록</AbsoluteIcon>
<AbsoluteIcon onClick={makeBoard} style={{ right: "16px", top: "14px" }}>
등록
</AbsoluteIcon>
<div style={{ flex: 1 }}>
{!showImages.length ? (
<ImgBox className="input-file-button" htmlFor="input-file">
Expand Down Expand Up @@ -198,8 +188,8 @@ const Image = styled.img`
`;
const AbsoluteIcon = styled.button`
position: absolute;
right: 16px;
top: 14px;
right: -14px;
top: -14px;
color: #6f85a8;
font-family: Pretendard;
font-size: 16px;
Expand Down
13 changes: 12 additions & 1 deletion app/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import styled from "styled-components";
import FriendsList from "../components/FriendList/FriendList";
import Feed from "../components/\bFeed/Feed";
import { Scroll } from "@/styles/base";
import { useEffect, useState } from "react";
import { getBoards } from "@/axios/boards";

const Container = styled.div`
height: 100%;
Expand Down Expand Up @@ -47,11 +49,20 @@ const feedsMock = [
},
];
const Home: NextPage = () => {
const [feeds, setFeeds] = useState([]);

useEffect(() => {
const result = getBoards();
result.then((data) => {
setFeeds(data.data);
});
}, []);

return (
<Layout menu="home">
<Scroll>
<FriendsList Friends={friendListMock} />
<Feed feeds={feedsMock} />
<Feed feeds={feeds} />
</Scroll>
</Layout>
);
Expand Down
14 changes: 10 additions & 4 deletions axios/boards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ const client = useAxiosWithAuth();

export const createBoard = async (formData: any) => {
try {
// eslint-disable-next-line no-restricted-syntax
for (const key of formData.keys()) {
console.log(key, ":", formData.get(key));
}
const response = await client.post("/boards", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
});
return response.data;
} catch (error: any) {
console.log(error);
// alert('다시 시도해주세요');
return error;
}
};
export const getBoards = async () => {
try {
const response = await client.get("/boards");

return response.data;
} catch (error: any) {
Expand Down
2 changes: 1 addition & 1 deletion axios/useAxiosWithAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const useAxiosWithAuth = (): AxiosInstance => {
if (statusCode === 401) {
error.response.statusText = "Unauthorized";
error.response.status = 401;
window.location.href = "/";
window.location.href = "/login";
}
return Promise.reject(error);
}
Expand Down

0 comments on commit 9d647b7

Please sign in to comment.