-
Notifications
You must be signed in to change notification settings - Fork 40
[오병훈] Sprint10 #309
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
The head ref may contain hidden characters: "Next-\uC624\uBCD1\uD6C8-sprint10"
[오병훈] Sprint10 #309
Changes from all commits
b8fd42f
b890b1e
1d30200
fb8495f
94951e7
2dd6fc0
eac64f9
0ae51b2
21672ab
0f38785
ba7953a
e21c01e
d7ab28e
bad740e
bf1c9b3
16224d9
77c5c51
b5561f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import styles from '@styles/ArticleContentSection.module.css'; | ||
| import { ArticleList } from '@/components/types/articleTypes'; | ||
| import Heart from '@public/svgs/ic_heart.svg'; | ||
| import Profile from '@public/svgs/ic_profile.svg'; | ||
|
|
||
| interface ArticlesSectionProps { | ||
| article: ArticleList; | ||
| } | ||
|
|
||
| export default function ArticleContentSection({ | ||
| article, | ||
| }: ArticlesSectionProps) { | ||
| const formatDate = (isoDate: string) => { | ||
| const date = new Date(isoDate); | ||
| return date | ||
| .toLocaleDateString('ko-KR', { | ||
| year: 'numeric', | ||
| month: '2-digit', | ||
| day: '2-digit', | ||
| }) | ||
| .replace(/\. /g, '. ') | ||
| .slice(0, -1); // 공백 제거 | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={styles['article-section']}> | ||
| <div className={styles['article-title']}>{article.title}</div> | ||
| <div className={styles['article-info']}> | ||
| <div className={styles['article-userinfo']}> | ||
| <Profile /> | ||
| <div className={styles['article-nickname']}> | ||
| {article.writer.nickname} | ||
| </div> | ||
| <div className={styles['article-createdAt']}> | ||
| {formatDate(article.createdAt)} | ||
| </div> | ||
| </div> | ||
| <div className={styles['article-likecount']}> | ||
| <Heart /> | ||
| {article.likeCount} | ||
| </div> | ||
| </div> | ||
| <div className={styles['article-content']}>{article.content}</div> | ||
| </div> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { createContext, useContext, useState, ReactNode } from 'react'; | ||
| import axiosInstance from '@lib/axiosInstance'; | ||
|
|
||
| interface AuthContextType { | ||
| login: (credentials: { email: string; password: string }) => Promise<void>; | ||
| } | ||
|
|
||
| const AuthContext = createContext<AuthContextType>({ | ||
| login: async () => {}, | ||
| }); | ||
|
|
||
| interface AuthProviderProps { | ||
| children: ReactNode; | ||
| } | ||
|
|
||
| export function AuthProvider({ children }: AuthProviderProps) { | ||
| async function login(credentials: { email: string; password: string }) { | ||
| try { | ||
| const response = await axiosInstance.post('/auth/signIn', credentials); | ||
| const { accessToken } = response.data; | ||
|
|
||
| localStorage.setItem('accessToken', accessToken); | ||
| console.log('로그인 성공'); | ||
| } catch (error) { | ||
| console.error('로그인 실패:', error); | ||
| throw new Error('로그인에 실패했습니다.'); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <AuthContext.Provider | ||
| value={{ | ||
| login, | ||
| }} | ||
| > | ||
| {children} | ||
| </AuthContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
| export function useAuth() { | ||
| const context = useContext(AuthContext); | ||
|
|
||
| if (!context) { | ||
| throw new Error('반드시 AuthProvider 안에서 사용해야 합니다.'); | ||
| } | ||
|
|
||
| return context; | ||
| } | ||
|
Comment on lines
+16
to
+49
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. context API를 사용할 때는, value를 useMemo로 감싸서 불필요한 리렌더링 방지 처리를 꼭 해줘야해요.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useMemo뿐 아니라, useCallback도 추가할 수 있습니다. |
||
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.
리뷰 반영 굳 입니다! 👍