Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(community): 학부소식 페이지 추가 #39

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
120 changes: 60 additions & 60 deletions apps/community/src/app/api/mock/board/data.ts

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions apps/community/src/app/api/mock/board/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export function GET(request: Request) {
const page = Number(url.searchParams.get('page')) || 0;
const size = Number(url.searchParams.get('size')) || 10;
const keyword = url.searchParams.get('keyword') || '';
const category =
url.searchParams.get('category')?.toLowerCase().replace(/\s+/g, '') || '';
const category = url.searchParams.get('category') || '';

const filteredBoards = board.filter((board) => {
const matchesKeyword = board.title
Expand Down
11 changes: 11 additions & 0 deletions apps/community/src/app/board/news/page.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { themeVars } from '@aics-client/design-system/styles';
import { style } from '@vanilla-extract/css';

const boardWrapper = style({
display: themeVars.display.flex,
flexDirection: themeVars.flexDirection.column,
alignItems: themeVars.alignItems.center,
gap: '2rem',
});

export { boardWrapper };
46 changes: 46 additions & 0 deletions apps/community/src/app/board/news/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { PageHeader } from '~/components/page-header';

import { BoardList } from '~/components/board/board-list';
import { SearchBar } from '~/components/board/search-bar';

import * as styles from '~/app/board/notice/page.css';
import { Pagination } from '~/components/board/pagination';
import { getBoards } from '../remote';

export const dynamic = 'force-dynamic';

export default async function NewsPage(props: {
searchParams?: Promise<{
category?: string;
page?: string;
keyword?: string;
}>;
Comment on lines +12 to +17
Copy link
Member

Choose a reason for hiding this comment

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

해당 타입을 따로 분리해주는건 어떨까요 ?
공지사항 페이지에도 공통으로 사용되는 부분으로 보여요

Copy link
Member

@gwansikk gwansikk Dec 3, 2024

Choose a reason for hiding this comment

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

공통적으로 사용하지만 성급한 추상화가 될 수 있다고 생각해요. 나중에 요구사항이 변경되어 공지사항과 학부소식이 동일하지 않는 파라미터로 사용할 수도 있는 가능성도 생각하여, 지금 처럼 복잡하지 않는 상태를 추상화하지 않고 두는 것도 괜찮다고 생각해요. 한 번 추상화나 레이어가 생긴다면 의존성과 커플링이 생겨버리니까요. 다른 분들 의견이 궁금합니다

@kgu-developers/1-client

Copy link
Contributor Author

Choose a reason for hiding this comment

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

저도 파라미터 변경 가능성이 있다고 생각하여 추상화하지 않았습니다!

}) {
const searchParams = await props.searchParams;
const currentPage = Number(searchParams?.page) || 0;
const keyword = searchParams?.keyword || '';

const { data } = await getBoards({
page: currentPage,
size: 10,
keyword,
category: 'DEPT_NEWS',
});

return (
<section>
<PageHeader
title="학부소식"
description="기사, 활동 및 수상 소식 등을 소개해요."
/>
<section className={styles.boardWrapper}>
<SearchBar placeholder="검색어를 입력하세요" />
<BoardList data={data.contents} />
<Pagination
totalPage={data.pagable.totalPage}
currentPage={currentPage}
/>
</section>
</section>
);
}
12 changes: 8 additions & 4 deletions apps/community/src/app/board/notice/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { SearchBar } from '~/components/board/search-bar';

import * as styles from '~/app/board/notice/page.css';
import { Pagination } from '~/components/board/pagination';
import { getBoards } from './remote';
import { getBoards } from '../remote';

export const dynamic = 'force-dynamic';

export default async function BoardPage(props: {
export default async function NoticePage(props: {
searchParams?: Promise<{
category?: string;
page?: string;
Expand All @@ -20,7 +20,12 @@ export default async function BoardPage(props: {
const currentPage = Number(searchParams?.page) || 0;
const keyword = searchParams?.keyword || '';

const { data } = await getBoards(currentPage, 10, keyword, '공지사항');
const { data } = await getBoards({
page: currentPage,
size: 10,
keyword,
category: 'DEPT_INFO',
});

return (
<section>
Expand All @@ -33,7 +38,6 @@ export default async function BoardPage(props: {
<BoardList data={data.contents} />
<Pagination
totalPage={data.pagable.totalPage}
pageCount={5}
currentPage={currentPage}
/>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ interface Board {
createAt: string;
}

async function getBoards(
page: number,
size: number,
keyword: string,
category: string,
) {
interface BoardParams {
page: number;
size: number;
keyword?: string;
category: string;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
category: string;
category: 'DEPT_INFO' | 'DEPT_NEWS';

}

async function getBoards({ page, size, keyword = '', category }: BoardParams) {
const params = new URLSearchParams({
page: page.toString(),
size: size.toString(),
Expand Down
2 changes: 1 addition & 1 deletion apps/community/src/components/board/board-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Eye, Paperclip, Pin } from '@aics-client/design-system/icons';

import { MOCK_END_POINT } from '~/constants/api';

import type { Board } from '~/app/board/notice/remote';
import type { Board } from '~/app/board/remote';

import * as styles from '~/components/board/board-list.css';

Expand Down
4 changes: 2 additions & 2 deletions apps/community/src/components/board/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import * as styles from '~/components/board/pagination.css';

interface Props {
totalPage: number; // 총 페이지 수
pageCount: number; // 보여줄 페이지 장 수
currentPage: number; // 현재 페이지
pageCount?: number; // 보여줄 페이지 장 수
}

function Pagination({ totalPage, pageCount, currentPage }: Props) {
function Pagination({ totalPage, pageCount = 5, currentPage }: Props) {
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
Expand Down
Loading