-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] add header and sidebar css and types #11
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
Changes from all commits
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 |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| .header { | ||
| color: yellowgreen; | ||
| .container { | ||
| display: flex; | ||
| height: 100%; | ||
| } | ||
|
|
||
| .sideBarWrapper { | ||
| border-right: 1px solid var(--gray-300); | ||
| padding: 22px; | ||
| } | ||
|
|
||
| .mainWrapper { | ||
| flex: 1; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,17 @@ | ||
| import { ReactNode } from 'react'; | ||
| import SideBar from '@/components/SideBar'; | ||
| import styles from './layout.module.css'; | ||
| import Header from '@/components/Header'; | ||
| import MainContainer from '@/components/MainContainer'; | ||
|
|
||
| export default function Layout({ children }: { children: ReactNode }) { | ||
| return ( | ||
| <> | ||
| <Header /> | ||
| <nav> | ||
| <div className={styles.container}> | ||
| <nav className={styles.sideBarWrapper}> | ||
| <SideBar /> | ||
| </nav> | ||
| <main>{children}</main> | ||
| </> | ||
| <div className={styles.mainWrapper}> | ||
| <MainContainer>{children}</MainContainer> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||
| import { useState, useEffect, useCallback } from 'react'; | ||||||||
| import { AxiosResponse, AxiosError } from 'axios'; | ||||||||
| import axiosInstance from '../utils/axiosInstance'; | ||||||||
|
|
||||||||
| type UseApiFetchReturnType<T> = { | ||||||||
| data: T | null; | ||||||||
| loading: boolean; | ||||||||
| error: AxiosError | null; | ||||||||
| refetch: () => Promise<void>; | ||||||||
| }; | ||||||||
|
|
||||||||
| type RequestOptions< | ||||||||
| TParams = Record<string, unknown>, | ||||||||
| TBody = Record<string, unknown>, | ||||||||
| > = { | ||||||||
| method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; | ||||||||
| params?: TParams; | ||||||||
| body?: TBody; | ||||||||
| }; | ||||||||
|
|
||||||||
| export default function useApi< | ||||||||
| T, | ||||||||
| TParams = Record<string, unknown>, | ||||||||
| TBody = Record<string, unknown>, | ||||||||
| >( | ||||||||
| url: string, | ||||||||
| options: RequestOptions<TParams, TBody> | ||||||||
| ): UseApiFetchReturnType<T> { | ||||||||
| const [data, setData] = useState<T | null>(null); | ||||||||
| const [loading, setLoading] = useState<boolean>(true); | ||||||||
| const [error, setError] = useState<AxiosError | null>(null); | ||||||||
|
|
||||||||
| const fetchData = useCallback(async () => { | ||||||||
| setLoading(true); | ||||||||
|
Owner
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.
Suggested change
์ด๋ฏธ ๋ก๋ฉ ์ค์ธ ๊ฒฝ์ฐ ์ค๋ณต ํธ์ถ ๋ฐฉ์งํ๊ธฐ ์ํด ์ด๋ฐ ์ฒ๋ฆฌ๊ฐ ์์ผ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
Collaborator
Author
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. @najitwo ์์ธ์ง?๋ชจ๋ฅด๊ฒ ๋๋ฐ gpt ํํ
๋ฆฌํํ ๋ง ํด๋ฌ๋ผ๊ณ ํ๋ฉด ์ค๋ฅผ ์์ ๋๋ผ๊ตฌ์...? |
||||||||
|
|
||||||||
| try { | ||||||||
| const config = { | ||||||||
| method: options.method, | ||||||||
| url, | ||||||||
| params: options.params, | ||||||||
| data: options.body, | ||||||||
| }; | ||||||||
| const response: AxiosResponse<T> = await axiosInstance.request(config); | ||||||||
| setData(response.data); | ||||||||
| } catch (err) { | ||||||||
| setError(err as AxiosError); | ||||||||
| } finally { | ||||||||
| setLoading(false); | ||||||||
| } | ||||||||
| }, [url, options]); | ||||||||
|
|
||||||||
| useEffect(() => { | ||||||||
| fetchData(); | ||||||||
| }, [fetchData]); | ||||||||
|
|
||||||||
| return { data, loading, error, refetch: fetchData }; | ||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { useState, useEffect } from 'react'; | ||
|
|
||
| interface WindowSize { | ||
| width: number; | ||
| height: number; | ||
|
Owner
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. resizeํ ๋ height ๊ฐ๋ ํ์ํ๊ฐ์? ๐ค
Collaborator
Author
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. @najitwo css media ๋๋น ๊ด์ ์์๋ ํ์์๊ธดํฉ๋๋ค ใ
ใ
|
||
| isMobile: boolean; | ||
| } | ||
|
|
||
| export default function useWindowSize(): WindowSize { | ||
| const [windowSize, setWindowSize] = useState<WindowSize>({ | ||
| width: 0, | ||
| height: 0, | ||
| isMobile: true, | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| function handleResize() { | ||
| setWindowSize({ | ||
| width: window.innerWidth, | ||
| height: window.innerHeight, | ||
| isMobile: window.innerWidth <= 768, | ||
| }); | ||
| } | ||
|
|
||
| window.addEventListener('resize', handleResize); | ||
|
|
||
| handleResize(); | ||
|
|
||
| return () => window.removeEventListener('resize', handleResize); | ||
| }, []); | ||
|
|
||
| return windowSize; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| interface Dashboard { | ||
| id: number; | ||
| title: string; | ||
| color: string; | ||
| userId: number; | ||
| createdAt: string; | ||
| updatedAt?: string; | ||
| createdByMe: boolean; | ||
| } | ||
|
|
||
| interface GetDashboardsRequestParams { | ||
| navigationMethod: 'infiniteScroll' | 'pagination'; | ||
| cursorId?: number; | ||
| page?: number; | ||
| size?: number; | ||
| } | ||
|
|
||
| interface GetDashboardsResponse { | ||
| dashboards: Dashboard[]; | ||
| totalCount: number; | ||
| cursorId: number | null; | ||
| } |
|
Collaborator
Author
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. ํ .. user ์ชฝ์ ์ฌ๊ธฐ์ ๊ธฐ์ ์ฐ๋๋ฐ ๊ณตํต ํ์
์ผ๋ก ๋นผ์ ๊ฐ์ ธ๋ค ์จ๋ ์ข์๊ฒ๊ฐ์์ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export interface User { | ||
| id: number; | ||
| email: string; | ||
| nickname: string; | ||
| profileImageUrl: string | null; | ||
| createdAt: string; | ||
| updatedAt?: string; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
| import { BASE_URL } from '@/constants/urls'; | ||
|
|
||
| const axiosInstance: AxiosInstance = axios.create({ | ||
| baseURL: BASE_URL, | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| timeout: 10000, | ||
| }); | ||
|
|
||
| axiosInstance.interceptors.request.use( | ||
| (config) => { | ||
| const token = 'your-token-here'; // TODO: Add token | ||
| if (token) { | ||
| config.headers['Authorization'] = `Bearer ${token}`; | ||
| } | ||
| return config; | ||
| }, | ||
| (error) => { | ||
| return Promise.reject(error); | ||
| } | ||
| ); | ||
|
|
||
| export const apiCall = async <T>( | ||
| config: AxiosRequestConfig | ||
| ): Promise<AxiosResponse<T>> => { | ||
| return axiosInstance.request<T>(config); | ||
|
Owner
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. ์ฌ๊ธฐ์ ์๋ฌ ์ฒ๋ฆฌ ๋ก์ง์ด ์์ผ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!
Collaborator
Author
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. ์ด์น๊ตฌ๋ ์์ง ๋ฏธ์์ฑ...์ด๊ธดํด์ |
||
| }; | ||
|
|
||
| export default axiosInstance; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
|
|
||
| body { | ||
| font-family: var(--font-pretendard), sans-serif; | ||
| height: 100vh; | ||
| } | ||
|
|
||
| ul, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,11 @@ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { | |
| export default function Button({ | ||
| className = '', | ||
| children, | ||
| type = 'button', | ||
|
Collaborator
Author
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. ๊ณตํต์ผ๋ก ์ฐ๋๊ฑฐ์ button type default๊ฐ ์ถ๊ฐํด๋จ๋๋ฐ ๋ค๋ฅธ ์๊ฒฌ์์ผ์๋ฉด ๋ง์๋ถํ๋๋ฆฝ๋๋ค~ |
||
| ...props | ||
| }: PropsWithChildren<ButtonProps>) { | ||
| return ( | ||
| <button className={`${styles.button} ${className}`} {...props}> | ||
| <button type={type} className={`${styles.button} ${className}`} {...props}> | ||
| {children} | ||
| </button> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| .header { | ||
| color: skyblue; | ||
| border-bottom: 1px solid var(--gray-300); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,20 @@ | ||
| 'use client'; | ||
| import { usePathname } from 'next/navigation'; | ||
| import styles from './Header.module.css'; | ||
| import type { User } from '@/app/(with-header-sidebar)/mydashboard/types/user'; | ||
|
|
||
| const user: User = { | ||
| id: 1, | ||
| email: '[email protected]', | ||
| nickname: 'heejin', | ||
| profileImageUrl: null, | ||
| createdAt: '2024-11-15T14:29:07.482Z', | ||
| }; | ||
|
|
||
| export default function Header() { | ||
| const pathname = usePathname(); | ||
|
|
||
| return <header className={styles.header}>ํค๋ {pathname}</header>; | ||
| const { nickname, profileImageUrl } = user; | ||
|
|
||
| return <header className={styles.header}>๋ด ๋์๋ณด๋</header>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { ReactNode } from 'react'; | ||
| import styles from './MainContainer.module.css'; | ||
| import Header from './Header'; | ||
|
|
||
| export default function MainContainer({ children }: { children: ReactNode }) { | ||
| return ( | ||
| <> | ||
| <Header /> | ||
| <main>{children}</main> | ||
| </> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| .sideBar { | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .button { | ||
| background-color: transparent !important; | ||
| } | ||
|
|
||
| .active { | ||
| color: salmon; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,23 +3,52 @@ | |
| import Link from 'next/link'; | ||
| import { usePathname } from 'next/navigation'; | ||
| import styles from './SideBar.module.css'; | ||
| import Image from 'next/image'; | ||
| import Button from './Button'; | ||
| import useWindowSize from '@/app/(with-header-sidebar)/mydashboard/hooks/useWindowSize'; | ||
|
|
||
| export default function SideBar() { | ||
| const pathname = usePathname(); | ||
| const { isMobile } = useWindowSize(); | ||
|
|
||
| return ( | ||
| <div> | ||
| <div className={styles.sideBar}> | ||
| <Button aria-label="ํํ์ด์ง ์ด๋" className={styles.button}> | ||
|
Collaborator
Author
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. ์ฌ๊ธฐ์ ๋ฒํผ classname์ ๋๊ฒจ์คฌ๋๋ฐ button์ปดํฌ๋ํธ css๊ฐ ๋์ค์ ๊ทธ๋ ค์ง๋๋ผ๊ณ ์..?
Owner
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.
|
||
| {isMobile ? ( | ||
| <Image | ||
| src="/images/logo_small.svg" | ||
| alt="๋ก๊ณ ํํ์ด์ง์ด๋" | ||
| width={24} | ||
| height={27} | ||
| /> | ||
| ) : ( | ||
| <Image | ||
| src="/images/logo_large.svg" | ||
| alt="๋ก๊ณ ํํ์ด์ง์ด๋" | ||
| width={109} | ||
| height={33} | ||
| /> | ||
| )} | ||
| </Button> | ||
| <Button aria-label="๋์๋ณด๋ ์ถ๊ฐํ๊ธฐ" className={styles.button}> | ||
| <Image | ||
| src="/icons/add_box.svg" | ||
| alt="๋์๋ณด๋ ์ถ๊ฐํ๊ธฐ" | ||
| width={20} | ||
| height={20} | ||
| /> | ||
| </Button> | ||
| <Link | ||
| href={'/dashboard/1'} | ||
| className={`link ${pathname === '/dashboard/1' ? styles.active : ''}`} | ||
| > | ||
| ๋์๋ณด๋1 | ||
| O | ||
| </Link> | ||
| <Link | ||
| href={'/dashboard/2'} | ||
| className={`link ${pathname === '/dashboard/2' ? styles.active : ''}`} | ||
| > | ||
| ๋์๋ณด๋2 | ||
| O | ||
| </Link> | ||
| </div> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| const BASE_URL = 'https://sp-taskify-api.vercel.app/10-1'; | ||
| export const BASE_URL = 'https://sp-taskify-api.vercel.app/10-1'; | ||
|
Collaborator
Author
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. ์๊ฑฐ axiosInstance์์ ๊ฐ์ ธ๋ค ์ฐ๋ ค๊ตฌ export ์ถ๊ฐํ์ด์..! |
||
|
|
||
| export const AUTH_URL = `${BASE_URL}/auth`; | ||
| export const CARD_URL = `${BASE_URL}/cards`; | ||
|
|
||
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.
์๋ ์์ง ๊ฐ์ ธ๋ค ์ฐ๋๊ณณ์ ์๋๋ฐ ๋์ค์ ์ฐ๋ ค๊ณ ? ์ถ๊ฐ๋ง ํด๋จ์ต๋๋ค