Skip to content
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
14 changes: 12 additions & 2 deletions src/app/(with-header-sidebar)/layout.module.css
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;
}
13 changes: 7 additions & 6 deletions src/app/(with-header-sidebar)/layout.tsx
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>
);
}
57 changes: 57 additions & 0 deletions src/app/(with-header-sidebar)/mydashboard/hooks/useApi.ts
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

์–˜๋Š” ์•„์ง ๊ฐ€์ ธ๋‹ค ์“ฐ๋Š”๊ณณ์€ ์—†๋Š”๋ฐ ๋‚˜์ค‘์— ์“ฐ๋ ค๊ณ ? ์ถ”๊ฐ€๋งŒ ํ•ด๋†จ์Šต๋‹ˆ๋‹ค

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);
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
setLoading(true);
if (loading) return;
setLoading(true);

์ด๋ฏธ ๋กœ๋”ฉ ์ค‘์ธ ๊ฒฝ์šฐ ์ค‘๋ณต ํ˜ธ์ถœ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ์ด๋Ÿฐ ์ฒ˜๋ฆฌ๊ฐ€ ์žˆ์œผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@najitwo ์™œ์ธ์ง€?๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ gpt ํ•œํ…Œ ๋ฆฌํŽ™ํ† ๋ง ํ•ด๋‹ฌ๋ผ๊ณ ํ•˜๋ฉด ์Ÿค๋ฅผ ์—†์• ๋”๋ผ๊ตฌ์š”...?
useAPi custom hook ์ฐพ์•„๋ด๋„ loading ์ค‘์ด๋ฉด returnํ•˜๋Š” ์ฝ”๋“œ๋Š” ์—†์–ด์„œ ๋จผ๊ฐ€ ์ด์œ ๊ฐ€ ์žˆ์ง€ ์•Š์„๊นŒ ์‹ถ๊ธดํ•œ๋ฐ
์š”๊ฑฐ TODO ์ฃผ์„์œผ๋กœ ํ•ด๋†“๊ณ  ๊ณ ๋ ค์‚ฌํ•ญ์œผ๋กœ ๋„ฃ์–ด๋‘๊ฒ ์Šต๋‹ˆ๋‹ค! ๐Ÿ‘


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 };
}
33 changes: 33 additions & 0 deletions src/app/(with-header-sidebar)/mydashboard/hooks/useWindowSize.ts
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;
Copy link
Owner

Choose a reason for hiding this comment

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

resizeํ• ๋•Œ height ๊ฐ’๋„ ํ•„์š”ํ•œ๊ฐ€์š”? ๐Ÿค”

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@najitwo css media ๋„ˆ๋น„ ๊ด€์ ์—์„œ๋Š” ํ•„์š”์—†๊ธดํ•ฉ๋‹ˆ๋‹ค ใ…‹ใ…‹
๊ทผ๋ฐ ์ด๋ฆ„์ด? useWindowSize๋‹ˆ๊นŒ ๋†’์ด๋„ ๊ปด์„œ...?

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;
}
22 changes: 22 additions & 0 deletions src/app/(with-header-sidebar)/mydashboard/types/dashboards.ts
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;
}
8 changes: 8 additions & 0 deletions src/app/(with-header-sidebar)/mydashboard/types/user.ts
Copy link
Collaborator Author

@devmanta devmanta Nov 16, 2024

Choose a reason for hiding this comment

The 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;
}
31 changes: 31 additions & 0 deletions src/app/(with-header-sidebar)/mydashboard/utils/axiosInstance.ts
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);
Copy link
Owner

Choose a reason for hiding this comment

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

์—ฌ๊ธฐ์— ์—๋Ÿฌ ์ฒ˜๋ฆฌ ๋กœ์ง์ด ์žˆ์œผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

์ด์นœ๊ตฌ๋Š” ์•„์ง ๋ฏธ์™„์„ฑ...์ด๊ธดํ•ด์„œ
์—๋Ÿฌ์ฒ˜๋ฆฌ ๊ณ ๋ คํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค~! ๐Ÿ™‡๐Ÿปโ€โ™€๏ธ (์•„๋‹˜ ์—†์•จ์ˆ˜๋„...?)

};

export default axiosInstance;
1 change: 1 addition & 0 deletions src/app/reset.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

body {
font-family: var(--font-pretendard), sans-serif;
height: 100vh;
}

ul,
Expand Down
3 changes: 2 additions & 1 deletion src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
export default function Button({
className = '',
children,
type = 'button',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

๊ณตํ†ต์œผ๋กœ ์“ฐ๋Š”๊ฑฐ์— button type default๊ฐ’ ์ถ”๊ฐ€ํ•ด๋†จ๋Š”๋ฐ ๋‹ค๋ฅธ ์˜๊ฒฌ์žˆ์œผ์‹œ๋ฉด ๋ง์”€๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค~
์ผ๋ฐ˜์ ์œผ๋กœ default๋Š” submit์ธ๋ฐ button์ด ์‚ฌ์šฉ๋นˆ๋„๊ฐ€ ํ›จ์”ฌ ๋†’์•„์„œ button์œผ๋กœ default ๋„ฃ์—ˆ์Šต๋‹ˆ๋‹ค

...props
}: PropsWithChildren<ButtonProps>) {
return (
<button className={`${styles.button} ${className}`} {...props}>
<button type={type} className={`${styles.button} ${className}`} {...props}>
{children}
</button>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.header {
color: skyblue;
border-bottom: 1px solid var(--gray-300);
}
13 changes: 12 additions & 1 deletion src/components/Header.tsx
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>;
}
Empty file.
12 changes: 12 additions & 0 deletions src/components/MainContainer.tsx
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>
</>
);
}
10 changes: 10 additions & 0 deletions src/components/SideBar.module.css
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;
}
35 changes: 32 additions & 3 deletions src/components/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

์—ฌ๊ธฐ์„œ ๋ฒ„ํŠผ classname์„ ๋„˜๊ฒจ์คฌ๋Š”๋ฐ button์ปดํฌ๋„ŒํŠธ css๊ฐ€ ๋‚˜์ค‘์— ๊ทธ๋ ค์ง€๋”๋ผ๊ณ ์š”..?
๊ทธ๋ž˜์„œ !important ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค ์ผ๋‹จ์€..?
ํ˜น์‹œ ๋ฐฉ๋ฒ•์•„์‹œ๋Š”๋ถ„....?

Copy link
Owner

Choose a reason for hiding this comment

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

import styles from './SideBar.module.css';
์„ ์–ธ์„ ๊ฐ€์žฅ ์•„๋ž˜์ชฝ์— ์„ ์–ธํ•˜๋Š” ๊ฒƒ์„ ์ƒํ™œํ™”ํ•ฉ์‹œ๋‹ค ๐Ÿคฃ

{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>
);
Expand Down
2 changes: 1 addition & 1 deletion src/constants/urls.ts
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';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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`;
Expand Down
Loading