-
Notifications
You must be signed in to change notification settings - Fork 41
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: 메인 페이지 글로벌 피드에 실 데이터를 적용 합니다. #123
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
977cdbf
chore: BACKEND_URL 환경 변수 추가
geeonie a64e4d8
chore: 이미지 호스트 변경
geeonie ad7058a
feat: article api service 에 getArticles 추가
geeonie 3809fc8
feat: GlobalPage 에서 searchParams 받도록 디렉토리 구조 변경
geeonie 3ac6416
feat: pagenation 분기 처리 추가
geeonie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
BACKEND_URL=https://api.realworld.io/api |
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,29 @@ | ||
import { FeedItem } from 'components/home/feed'; | ||
import { Pagination } from 'components/ui'; | ||
import { ARTICLE_PAGE_LIMIT } from 'constants/article'; | ||
import { articleApi } from 'services'; | ||
|
||
type Props = { | ||
searchParams: Record<string, string>; | ||
}; | ||
const GlobalPage = async ({ searchParams }: Props) => { | ||
const page = Number(searchParams.page ?? 1); | ||
|
||
const { articles, articlesCount } = await articleApi.getArticles({ | ||
limit: ARTICLE_PAGE_LIMIT, | ||
offset: (page - 1) * ARTICLE_PAGE_LIMIT, | ||
}); | ||
|
||
return ( | ||
<> | ||
<ul className="p-0"> | ||
{articles.map((feed) => { | ||
return <FeedItem feed={feed} key={feed.slug} />; | ||
})} | ||
</ul> | ||
<Pagination total={articlesCount / ARTICLE_PAGE_LIMIT} current={page} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default GlobalPage; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
23 changes: 5 additions & 18 deletions
23
components/home/feed-list/feed-item.tsx → components/home/feed/feed-item.tsx
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
1 change: 0 additions & 1 deletion
1
components/home/feed-list/index.ts → components/home/feed/index.ts
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,2 +1 @@ | ||
export * from './feed-list'; | ||
export * from './feed-item'; |
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 @@ | ||
export const ARTICLE_PAGE_LIMIT = 10; |
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,22 @@ | ||
import { z } from 'zod'; | ||
import { AuthorSchema } from './author'; | ||
|
||
export const ArticleSchema = z.object({ | ||
slug: z.string(), | ||
title: z.string(), | ||
description: z.string(), | ||
body: z.string(), | ||
tagList: z.array(z.string()), | ||
createdAt: z.string(), | ||
updatedAt: z.string(), | ||
favorited: z.boolean(), | ||
favoritesCount: z.number(), | ||
author: AuthorSchema, | ||
}); | ||
|
||
export const ArticleListSchema = z.object({ | ||
articles: z.array(ArticleSchema), | ||
articlesCount: z.number(), | ||
}); | ||
|
||
export type Article = z.infer<typeof ArticleSchema>; |
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,8 @@ | ||
import { z } from 'zod'; | ||
|
||
export const AuthorSchema = z.object({ | ||
username: z.string(), | ||
bio: z.string().nullable(), | ||
image: z.string(), | ||
following: z.boolean(), | ||
}); |
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,3 @@ | ||
export * from './article'; | ||
export * from './author'; | ||
export * from './search-params'; |
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,7 @@ | ||
export type SearchParams = { | ||
limit: number; | ||
offset: number; | ||
author: string; | ||
tag: string; | ||
favorited: string; | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
import { get } from 'services/fetch-utils'; | ||
import { ArticleListSchema, SearchParams } from 'models'; | ||
|
||
class ArticleApiService { | ||
async getArticles({ limit = 10, offset = 0 }: Partial<SearchParams> = {}) { | ||
const params = new URLSearchParams({ | ||
limit: limit.toString(), | ||
offset: offset.toString(), | ||
}); | ||
|
||
return await get(`/articles?${params}`, ArticleListSchema); | ||
} | ||
} | ||
|
||
export const articleApi = new ArticleApiService(); |
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 @@ | ||
export * from './article'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.env 는 레포지토리에 시켜도 좋다고 하여 .gitignore 에서 제외 합니당