Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f554999
git 연결
Namgyeon Jan 19, 2025
9b6a5ca
feat: 기본기능 구현
Namgyeon Jan 19, 2025
5569432
feat: favicon추가, font:Pretendard 적용
Namgyeon Jan 20, 2025
2fab846
feat: 검색기능 추가
Namgyeon Jan 20, 2025
fba2e36
chors: 배포 코드추가
Namgyeon Jan 20, 2025
8acaf03
chors: 배포 코드추가2
Namgyeon Jan 20, 2025
7cfb7c7
feat: props nickname 기본값 추가
Namgyeon Jan 20, 2025
6becf40
배포 코드 수정
Namgyeon Jan 20, 2025
a71f491
배포 코드 수정
Namgyeon Jan 20, 2025
ed284bb
배포 코드 수정
Namgyeon Jan 20, 2025
badd979
배포 코드 수정
Namgyeon Jan 21, 2025
eac3d41
배포 오류 수정을 위해 파일경로 수정
Namgyeon Jan 21, 2025
b8f1f6e
배포 오류 수정을 위해 파일경로 수정
Namgyeon Jan 21, 2025
c9c3229
배포 오류 수정
Namgyeon Jan 21, 2025
4e00daa
feat: 서버사이드 렌더링으로 변경
Namgyeon Jan 21, 2025
f4de0eb
feat: AllPosts SSR로 변경
Namgyeon Jan 21, 2025
38b936a
feat: api요청에 URLSearchParams를 사용
Namgyeon Jan 22, 2025
6f7bdb6
feat: OrderByValue type alias 추가
Namgyeon Jan 22, 2025
979b2ac
feat: baseURL 상수화
Namgyeon Jan 22, 2025
a0c4627
feat: 에러 핸들링 수정
Namgyeon Jan 22, 2025
75419fb
feat: 불필요한 상태 제거
Namgyeon Jan 22, 2025
895e82a
refactor: 콤포넌트 prop 가독성, 유지보수 개선
Namgyeon Jan 23, 2025
a09eae4
refactor: 불필요한 useState삭제, textMapper 객체를 활용하여 기능 유지
Namgyeon Jan 23, 2025
bbaa9f2
refactor: useMediaQuery hooks를 따로 구분하여 가독성 개선
Namgyeon Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions next/src/lib/fetch-posts.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { baseURL } from "@/constants";
import { PostData, PostListData } from "../types";
import { Post, Posts } from "../types";

export default async function fetchPosts({
page = "1",
pageSize = 3,
orderBy = "recent",
keyword = "",
}): Promise<PostData[]> {
}): Promise<Post[]> {
const params = new URLSearchParams({
page: String(page),
pageSize: String(pageSize),
Expand All @@ -20,10 +20,9 @@ export default async function fetchPosts({
if (!response.ok) {
throw new Error(`Failed to fetch, ${response.statusText}`);
}
const data: PostListData = await response.json();
const data: Posts = await response.json();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우리 멘토링떄 이야기했던것처럼 list 반환타입의 경우 제네릭을 활용해서 거기에 list필드가 반환하는 값이 Post[] 가 될 수 있도록 한번 해볼까요?

return data.list;
} catch (err) {
console.error(err);
return [];
throw new Error(`FetchPosts Error: ${(err as Error).message}`);
}
}
9 changes: 4 additions & 5 deletions next/src/pages/boards/components/AllPosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import BasePost from "./BasePost";
import { useEffect, useState } from "react";
import ToggleBtn from "../../../components/ToggleBtn";
import Link from "next/link";
import { PostData } from "../../../types";
import { Post } from "../../../types";
import fetchPosts from "@/lib/fetch-posts";

interface AllPostProps {
initialAllPosts: PostData[];
initialAllPosts: Post[];
}

export default function AllPosts({ initialAllPosts }: AllPostProps) {
const [postList, setPostList] = useState<PostData[]>(initialAllPosts);
const [postList, setPostList] = useState<Post[]>(initialAllPosts);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[postList, ...] 보다 마찬가지로 해당 엔티티 그 자체를 사용해 posts라고 변수선언을 해보면 어떨까요?

const [orderBy, setOrderBy] = useState<"recent" | "like">("recent");
const [filterPostList, setFilterPostList] =
useState<PostData[]>(initialAllPosts);
const [filterPostList, setFilterPostList] = useState<Post[]>(initialAllPosts);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter값이 바뀔때마다 리렌더링 되다보니 그냥

const [filter, setFilter] = useState('')

const filteredPosts = posts.filter(post => post.title.includes(filter))

return { fileredPosts.map( ... ) }

하는식으로 하는걸 추천드려요!

const [searchValue, setSearchValue] = useState<string>("");

const onChangeOrderBy = (orderByValue: "recent" | "like") => {
Expand Down
4 changes: 2 additions & 2 deletions next/src/pages/boards/components/BasePost.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Image from "next/image";
import styles from "./BasePost.module.css";
import formatDate from "../../../utils/date";
import { PostData } from "../../../types";
import { Post } from "../../../types";

export default function BasePost({
content,
image,
writer = { nickname: "익명 사용자" },
likeCount,
createdAt,
}: PostData) {
}: Post) {
return (
<div className={styles.container}>
<div className={styles.product}>
Expand Down
4 changes: 2 additions & 2 deletions next/src/pages/boards/components/BestPost.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Image from "next/image";
import styles from "./BestPost.module.css";
import formatDate from "../../../utils/date";
import { PostData } from "../../../types";
import { Post } from "../../../types";

export default function BestPost({
content,
image,
writer,
likeCount,
createdAt,
}: PostData) {
}: Post) {
return (
<div className={styles.container}>
<div className={styles.tag}>
Expand Down
6 changes: 3 additions & 3 deletions next/src/pages/boards/components/BestPosts.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { PostData } from "@/types";
import { Post } from "@/types";
import BestPost from "./BestPost";
import styles from "./BestPosts.module.css";
import { useEffect, useState } from "react";
import fetchPosts from "@/lib/fetch-posts";

interface BestPostProps {
initialBestPosts: PostData[];
initialBestPosts: Post[];
}

// 479, 767, 1023

export default function BestPosts({ initialBestPosts }: BestPostProps) {
const [pageSize, setPageSize] = useState(3);
const [bestPosts, setBestPosts] = useState<PostData[]>(initialBestPosts);
const [bestPosts, setBestPosts] = useState<Post[]>(initialBestPosts);

const pageSizeCheck = () => {
const pageWidth = window.innerWidth;
Expand Down
6 changes: 3 additions & 3 deletions next/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface PostData {
export interface Post {
id: number;
title: string;
content: string;
Expand All @@ -12,8 +12,8 @@ export interface PostData {
};
}

export interface PostListData {
list: PostData[];
export interface Posts {
list: Post[];
totalCount: number;
}

Expand Down