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

[김법균] Week14 #458

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4ff3eac
feat: Create Button Component
bk-git-hub May 8, 2024
afc85a4
style: Fix incorrect syntax in css
bk-git-hub May 8, 2024
51cd32b
feat: Add Header component
bk-git-hub May 8, 2024
4b13e67
feat: Render Header component as common component
bk-git-hub May 8, 2024
80657d1
chore: Remove initial codes in Home Component
bk-git-hub May 8, 2024
5a20445
chore: Change Logo image to Link Component
bk-git-hub May 8, 2024
71fc42e
style: Apply reset.css in _app.tsx
bk-git-hub May 8, 2024
c06e1ef
style: Initialize global.css
bk-git-hub May 8, 2024
7450edd
feat: Add Footer Component
bk-git-hub May 8, 2024
d494e1c
feat: Add main heading to homepage
bk-git-hub May 9, 2024
6524c10
feat: Add AddlinkButton in homepage
bk-git-hub May 9, 2024
2e998f1
feat: Add main example page image in homepage
bk-git-hub May 9, 2024
df4176b
feat: Add feature cards in homepage
bk-git-hub May 9, 2024
9543365
style: Adjust Sign in button style
bk-git-hub May 9, 2024
d85cd76
feat: Add link feature using useRouter from homepage to signup page
bk-git-hub May 9, 2024
54a6d86
feat: Add optional rendering of header and footer in app.tsx
bk-git-hub May 9, 2024
38f02df
style: Add global color variable and font
bk-git-hub May 9, 2024
0ef3b30
feat: Add header for sign up page
bk-git-hub May 9, 2024
abf2956
refactor: Extract authHeader from authPage into a seperate component
bk-git-hub May 9, 2024
235a8a2
feat: Add sign up form in sign up page
bk-git-hub May 9, 2024
9c7af94
feat: Add social link bar in sign up page
bk-git-hub May 9, 2024
0a80ad0
feat: Add routing feature to AuthHeader component
bk-git-hub May 9, 2024
c661db3
refactor: Change SignUpForm stylesheet to AuthForm
bk-git-hub May 9, 2024
25948dd
feat: Create sign in page
bk-git-hub May 9, 2024
572c3a1
feat: Add type prop for Button component
bk-git-hub May 9, 2024
ea1481f
install libraries..
bk-git-hub May 11, 2024
ff659cd
feat: Add disable feature in Button component
bk-git-hub May 11, 2024
be585da
refactor: Refactor sign in form using react-hook-form
bk-git-hub May 11, 2024
7adf8d7
refactor: Use react-hook-form to handle sign up form
bk-git-hub May 11, 2024
bb1eb95
chore: Remove AuthInput component
bk-git-hub May 13, 2024
318d23e
intall axios
bk-git-hub May 13, 2024
ae1190f
feat: Create axios instance
bk-git-hub May 13, 2024
ebec153
feat: Create ShowTextToggle component
bk-git-hub May 13, 2024
92f5aea
feat: Add toggle button and error trigger to sign up page
bk-git-hub May 13, 2024
c55266b
feat: Add password toggle feature to sign in page
bk-git-hub May 13, 2024
a21a6b4
feat: Trigger validation at onBlur
bk-git-hub May 13, 2024
006447c
chore: Change button type to 'button'
bk-git-hub May 13, 2024
13d1c7a
chore: Fix base url
bk-git-hub May 13, 2024
8ca6d8d
feat: Add api request to onSubmit function and handle request
bk-git-hub May 13, 2024
db72aea
chore: Remove console.log in onSubmit
bk-git-hub May 13, 2024
1702d39
feat: Create Account Component for header display
bk-git-hub May 13, 2024
bbc6fc3
feat: Use context api to share userInfo state
bk-git-hub May 13, 2024
70edc32
feat: Add sign in feature and move to folder page and update userInfo
bk-git-hub May 13, 2024
24f16bb
feat: Create folder page
bk-git-hub May 13, 2024
4e99ba4
feat: Add sign up api feature to sign up page
bk-git-hub May 13, 2024
facb247
feat: Add routing to folder page when userInfo exists
bk-git-hub May 13, 2024
12e3cb5
feat: Add temporary loading feature for header(needs to be fixed)
bk-git-hub May 16, 2024
84fe27d
feat: Add SearchBar Component
bk-git-hub May 16, 2024
43417d3
feat: Add FolderToolBar Component
bk-git-hub May 16, 2024
fd4f1bb
feat: Add LinkCard & Link
bk-git-hub May 16, 2024
50cef44
feat: Add Modal feature in folder page
bk-git-hub May 16, 2024
4df5259
style: Add hover style to toggle button
bk-git-hub May 16, 2024
1cdb459
fix: Fix image error in share modal
bk-git-hub May 16, 2024
1d56499
fix: Change eslintrc and add script for Kakao Talk share
bk-git-hub May 17, 2024
23340a5
chore: Change share url to local host for feature test
bk-git-hub May 17, 2024
4df9304
feat: Create SharedPage component
bk-git-hub May 17, 2024
b740fc5
Merge branch 'part3-김법균' into part3-김법균
bk-git-hub May 24, 2024
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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "next/core-web-vitals"
"extends": "next"
}
22 changes: 22 additions & 0 deletions components/Account/Account.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.account {
display: flex;
align-items: center;
gap: 6px;
}
.userProfileImg {
width: 28px;
aspect-ratio: 1/1;
border-radius: 50%;
}

.userEmail {
width: fit-content;
font-size: 14px;
@media (max-width: 767px) {
position: absolute;
width: 1px;
height: 1px;
clip: rect(0 0 0 0);
overflow: hidden;
}
}
20 changes: 20 additions & 0 deletions components/Account/Account.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import styles from './Account.module.scss';

interface AccountProps {
profileImgSource?: string;
userEmail: string;
Comment on lines +4 to +5
Copy link
Collaborator

Choose a reason for hiding this comment

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

@bk-git-hub

prop으로 전달받는 요소의 경우, 우리 프로젝트에서 전반적으로 사용되는 유저 데이터가 존재하나요?
그렇다면 유저 데이터에 대한 타입을 선언해서 그냥 유저 정보를 다 받아오도록 하는게 더 좋지 않을까 생각이 되어요.

type User = {
  profileImgSrc?: string
  email: string
  name: string
  ...
}

interface AccountProps {
  user: User
}

}

const Account = ({ profileImgSource, userEmail }: AccountProps) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@bk-git-hub

account라기 보단 user-profile이라는 콤포넌트가 더 적합한 이름으로 보이는데 어떻게 생각하시나요?

return (
<div className={styles.account}>
<img
src={profileImgSource}
alt='User Profile'
className={styles.userProfileImg}
/>
<span className={styles.userEmail}>{userEmail}</span>
</div>
);
};
export default Account;
116 changes: 116 additions & 0 deletions components/FolderToolBar/FolderToolBar.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
.folderToolBarContainer {
display: flex;
flex-direction: column;
gap: 24px;
width: 1060px;

.folderToolButtons {
display: flex;
width: 100%;
justify-content: space-between;
align-items: center;

.folderNameButtons {
display: flex;
flex-wrap: wrap;
width: 80%;
gap: 8px;
}
}

.folderNameDisplay {
font-size: 24px;
letter-spacing: -0.2px;
font-weight: 600;
}

.folderNameBar {
display: flex;
justify-content: space-between;
align-items: center;

.utilButtons {
display: flex;
gap: 12px;
}
}

@media (max-width: 1124px) {
width: 706px;
}

@media (max-width: 767px) {
width: 325px;

.folderNameBar {
flex-direction: column;
align-items: flex-start;
gap: 12px;
}
}
}

.folderNameButton {
background-color: #fff;
border: 1px solid #6d6afe;
padding: 8px 12px;
border-radius: 5px;
height: 36px;

&:hover {
background-color: #e7effb;
}
}

.focusedButton {
background-color: #6d6afe;
color: #fff;
&:hover {
background-color: #6d6afe;
}
}

.utilButton {
position: relative;
display: flex;
gap: 4px;
color: #9fa6b2;
font-size: 14px;
font-weight: 600;
}
.utilButtonIcon {
position: relative;
width: 18px;
height: 18px;
}

.folderAddButton {
display: flex;
font-weight: 500;
gap: 4px;
color: #6d6afe;

.addIconWhite {
display: none;
}

@media (max-width: 767px) {
position: fixed;
bottom: 101px;
padding: 8px 24px;
left: 50%;
transform: translateX(-50%);
border-radius: 20px;
background-color: #6d6afe;
color: #fff;
z-index: 1;

.addIcon {
display: none;
}

.addIconWhite {
display: block;
}
}
}
87 changes: 87 additions & 0 deletions components/FolderToolBar/FolderToolBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import FolderToolBarButton from './FolderToolBarButton';
import styles from './FolderToolBar.module.scss';
import UtilButton from './UtilButton';
import { UTIL_BUTTONS_PROPS } from './constants';
import { FolderObj } from '@/utils/interfaces';

const addIcon = '/assets/images/add_icon.svg';
const addIconWhite = '/assets/images/add_icon_white.svg';
interface FolderToolBarProps {
folders?: FolderObj[];
currentFolderId?: number;
folderNameOnClick: (id: number) => void;
onFolderNameChangeClick: () => void;
onFolderAddClick: () => void;
onFolderDeleteClick: () => void;
onShare: () => void;
}

export default function FolderToolBar({
folders,
currentFolderId,
folderNameOnClick,
onFolderAddClick,
onFolderNameChangeClick,
onFolderDeleteClick,
onShare,
}: FolderToolBarProps) {
const currentFolder = folders?.find(
(folder) => folder.id === currentFolderId
);
const currentFolderName = currentFolder?.name;
UTIL_BUTTONS_PROPS.share.onClick = onShare;
UTIL_BUTTONS_PROPS.changeName.onClick = onFolderNameChangeClick;
UTIL_BUTTONS_PROPS.delete.onClick = onFolderDeleteClick;

return (
<div className={styles.folderToolBarContainer}>
<div className={styles.folderToolButtons}>
<ul className={styles.folderNameButtons}>
{folders?.map((item) => (
<li key={item.id}>
<FolderToolBarButton
onClick={folderNameOnClick}
id={item.id}
isFocused={item.id === currentFolderId}
>
{item.name}
</FolderToolBarButton>
</li>
))}
</ul>

<button className={styles.folderAddButton} onClick={onFolderAddClick}>
<span>폴더 추가</span>
<img
src={addIcon}
alt='폴더 추가 아이콘'
className={styles.addIcon}
/>
<img
src={addIconWhite}
alt='폴더 추가 아이콘'
className={styles.addIconWhite}
/>
</button>
</div>
<div className={styles.folderNameBar}>
<span className={styles.folderNameDisplay}>{currentFolderName}</span>
<ul className={styles.utilButtons}>
{Object.entries(UTIL_BUTTONS_PROPS).map(([key, btn]) => (
<li key={btn.id}>
{currentFolderId !== -1 && (
<UtilButton
imgSrc={btn.imgSrc}
alt={btn.alt}
onClick={btn.onClick}
>
{btn.btnText}
</UtilButton>
)}
</li>
))}
</ul>
</div>
</div>
);
}
29 changes: 29 additions & 0 deletions components/FolderToolBar/FolderToolBarButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styles from './FolderToolBar.module.scss';

interface FolderToolBarButtonProps {
id: number;
children: React.ReactNode;
onClick: (id: number) => void;
isFocused: boolean;
}

export default function FolderToolBarButton({
id,
children,
onClick,
isFocused,
}: FolderToolBarButtonProps) {
const handleClick = () => {
onClick(id);
};
return (
<button
onClick={handleClick}
className={`${styles.folderNameButton} ${
isFocused && styles.focusedButton
}`}
>
{children}
</button>
);
}
25 changes: 25 additions & 0 deletions components/FolderToolBar/UtilButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import styles from './FolderToolBar.module.scss';
import Image from 'next/image';

interface UtilButtonProps {
imgSrc: string;
children: React.ReactNode;
onClick: () => void;
alt: string;
}

export default function UtilButton({
Copy link
Collaborator

Choose a reason for hiding this comment

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

@bk-git-hub

이 버튼의 존재 의의가 무엇인가요?
위에 재활용 가능한 버튼을 잘 만든다면 이 버튼을 굳이 만들 필요가 없어보여요

imgSrc,
children,
onClick,
alt,
}: UtilButtonProps) {
return (
<button className={styles.utilButton} onClick={onClick}>
<div className={styles.utilButtonIcon}>
<Image src={imgSrc} alt={alt} fill />
</div>
{children}
</button>
);
}
37 changes: 37 additions & 0 deletions components/FolderToolBar/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const shareIcon = '/assets/images/share_icon.svg';
const penIcon = '/assets/images/pen_icon.svg';
const deleteIcon = '/assets/images/delete_icon.svg';

interface UtilButtonProp {
imgSrc: string;
btnText: string;
alt: string;
id: number;
onClick: () => void;
}

const noop = () => {};

export const UTIL_BUTTONS_PROPS: { [key: string]: UtilButtonProp } = {
share: {
imgSrc: shareIcon,
btnText: '공유',
alt: '공유 아이콘',
id: 1,
onClick: noop,
},
changeName: {
imgSrc: penIcon,
btnText: '이름 변경',
alt: '이름 변경 아이콘',
id: 2,
onClick: noop,
},
delete: {
imgSrc: deleteIcon,
btnText: '삭제',
alt: '삭제 아이콘',
id: 3,
onClick: noop,
},
};
37 changes: 34 additions & 3 deletions components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,48 @@ import Button from '../Button/Button';
import Image from 'next/image';
import styles from './Header.module.css';
import Link from 'next/link';

import Account from '@/components/Account/Account';
import { useUserInfo } from '@/contexts/UserInfoContext';
import { axiosInstance } from '@/utils/axiosInstance';
import { useEffect } from 'react';
export default function Header() {
const { userInfo, setUserInfo } = useUserInfo();
Copy link
Collaborator

Choose a reason for hiding this comment

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

@bk-git-hub

useUserInfo는 그냥 우리 어플리케이션에 저장된 사용자 전부에 대한 관리를 하는 모듈로 보입니다.
로그인 된 사용자에 대한 관리라면 useAuth라는 형태로 사용하는게 더 좋을것 같구요

useAuth에서 로그인 된 사용자 정보를 관리하고 있게 한다면, 이 사용자 정보를 변경할 수 있는 setUserInfo를 제공해주는건 되게 좋지 않아보입니다.

useAuth에서 제공해야 하는 요소들은

  1. 로그인 된 사용자 정보
  2. 로그인 기능
  3. 로그아웃 기능

만 제공해주어야 할 거구요
이 훅에서 제공하는 로그인 기능과 로그아웃 기능 을 통해 로그인된 사용자 정보를 업데이트를 할 수 있도록 추상화를 해주세요

const loadUser = async () => {
const accessToken = localStorage.getItem('accessToken');
if (accessToken) {
const response = await axiosInstance.get('/users', {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
setUserInfo(response.data.data[0]);
}
};
Comment on lines +12 to +22
Copy link
Collaborator

Choose a reason for hiding this comment

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

@bk-git-hub

이 로직도 header에서 처리되기보단 로그인 된 사용자 정보를 관리하는 곳에서 처리가 되어야 하겠죠


useEffect(() => {
loadUser();
}, []);

return (
<>
<header className={styles.headerContainer}>
<div className={styles.headerBar}>
<Link className={styles.logoImageContainer} href={`/`}>
<Image src='/assets/images/logo.svg' alt='Logo' fill />
</Link>
<Link href={'/signin'}>
<Button className={styles.signInButton}>로그인</Button>
</Link>

{userInfo ? (
<Account
profileImgSource={userInfo.image_source}
userEmail={userInfo.email}
/>
) : (
<Link href={'/signin'}>
<Button className={styles.signInButton}>로그인</Button>
</Link>
)}

</div>
</header>
</>
Expand Down
Loading
Loading