-
Notifications
You must be signed in to change notification settings - Fork 44
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 #445
The head ref may contain hidden characters: "part3-\uAE40\uBBF8\uC18C-week14"
[김미소] week14 #445
Changes from all commits
d6de20f
569075d
97ad057
c28130d
2259ce3
3a2d697
9268e71
eba660c
bcc432c
248039b
8c0d0a9
0ab9e90
ff1514b
59de712
ba0dc40
bd9b2e6
184bce6
0453cae
61fd9d4
73d070d
87bd07a
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 |
---|---|---|
|
@@ -3,6 +3,11 @@ | |
"next/babel" | ||
], | ||
"plugins": [ | ||
"babel-plugin-styled-components" | ||
[ | ||
"styled-components", | ||
{ | ||
"ssr": true | ||
} | ||
] | ||
] | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,66 +1,74 @@ | ||||||
import { useEffect, useState } from "react"; | ||||||
import axios from "@/lib/axios"; | ||||||
import { Email, HeaderControl, HeaderInner, HeaderLogo, HeaderUserInfo, HeaderWrap } from "./headerStyle"; | ||||||
import { useRouter } from "next/router"; | ||||||
import { Profile } from "@/styles/commonStyle"; | ||||||
import LinkButton from "./atoms/LinkButton"; | ||||||
import Link from "next/link"; | ||||||
import Image from "next/image"; | ||||||
import { useContext, useEffect, useState } from 'react'; | ||||||
import { Email, HeaderControl, HeaderInner, HeaderLogo, HeaderWrap } from './headerStyle'; | ||||||
import { Profile } from '@/styles/commonStyle'; | ||||||
import { AuthContext } from '@/lib/auto.context'; | ||||||
import { joinInstance } from '@/lib/axios'; | ||||||
import LinkButton from './atoms/LinkButton'; | ||||||
import Button from './atoms/Button'; | ||||||
import Link from 'next/link'; | ||||||
import Image from 'next/image'; | ||||||
import { useRouter } from 'next/router'; | ||||||
|
||||||
const logo = '/assets/logo/logo.svg'; | ||||||
const LOGO_IMAGE = '/assets/logo/logo.svg'; | ||||||
|
||||||
export interface IHeaderUser { | ||||||
id:number, | ||||||
email:string, | ||||||
name?:string, | ||||||
image_source?:string, | ||||||
created_at?:string, | ||||||
auth_id:string | ||||||
id: number; | ||||||
email: string; | ||||||
name?: string; | ||||||
image_source?: string; | ||||||
created_at?: string; | ||||||
auth_id: string; | ||||||
} | ||||||
|
||||||
export interface IHeaderUserLoginInfoApi { | ||||||
userInfo?: { | ||||||
data: IHeaderUser[]; | ||||||
}; | ||||||
} | ||||||
|
||||||
export async function getStaticProps() { | ||||||
const res = await axios.get(``); | ||||||
const userInfo = res.data; | ||||||
const hidePages = ['/signin', '/signup']; | ||||||
const noHeaderFixed = ['/folder']; | ||||||
|
||||||
return { | ||||||
props:{ | ||||||
userInfo, | ||||||
} | ||||||
} | ||||||
} | ||||||
function Header() { | ||||||
const router = useRouter(); | ||||||
const { pathname } = router; | ||||||
const { isLoggedIn, handleLogout } = useContext(AuthContext); | ||||||
const [isfixed, setIsFixed] = useState(true); | ||||||
const [isHideHeader, setIsHideHeader] = useState(true); | ||||||
const [userInfo, setUserInfo] = useState<IHeaderUser | null>(); | ||||||
|
||||||
function Header({userInfo}:IHeaderUserLoginInfoApi) { | ||||||
const {pathname} = useRouter(); | ||||||
const [fixed, setFixed] = useState(true); | ||||||
const handleUserInfo = async () => { | ||||||
const res = await joinInstance.get(`/sample/user`); | ||||||
setUserInfo(JSON.parse(JSON.stringify(res.data))); | ||||||
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
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. 보통
|
||||||
}; | ||||||
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. 혹시
|
||||||
|
||||||
useEffect(() => { | ||||||
if (pathname === '/folder') { | ||||||
setFixed(false); | ||||||
} | ||||||
handleUserInfo(); | ||||||
setIsHideHeader(hidePages.includes(pathname)); | ||||||
setIsFixed(noHeaderFixed.includes(pathname)); | ||||||
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.
|
setIsHideHeader(hidePages.includes(pathname)); | |
setIsHideHeader(hidePages.some(page => pathname.startsWith(page))); |
경로의 포함 여부를 체크할 때 includes
메서드는 문자열의 부분 일치를 검사하므로, 정확한 경로 매칭이 필요하다면 startsWith
를 사용하는 것이 더 좋습니다. startsWith
는 문자열이 특정 문자열로 시작하는지 확인할 수 있어서 의도한 대로 정확한 경로를 확인할 수 있습니다.
includes
란?: 문자열이 특정 문자열을 포함하고 있는지를 검사합니다. 부분 일치를 확인할 때 사용됩니다.
const pathname = '/signin/extra';
console.log(pathname.includes('/signin'));
// true
startsWith
란?: 문자열이 특정 문자열로 시작하는지를 검사합니다. 정확한 시작을 확인할 때 사용됩니다.
const pathname = '/signin/extra';
console.log(pathname.startsWith('/signin'));
// true
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.
오호. 조건부 렌더링을 통해서 레이아웃을 감추고 있군요?
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.
굳굳 ! Guard Clause
패턴을 사용하셨군요 👍
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,30 +2,22 @@ import { ButtonHTMLAttributes } from 'react'; | |||||||||||||||||||||
import { ButtonModule } from './buttonStyle'; | ||||||||||||||||||||||
interface IButtonModule { | ||||||||||||||||||||||
children: React.ReactNode; | ||||||||||||||||||||||
$btnClass: string; | ||||||||||||||||||||||
$btnClass?: string; | ||||||||||||||||||||||
$BeforButtonIcon?: string; | ||||||||||||||||||||||
$id?: string; | ||||||||||||||||||||||
$afterButtonIcon?: string; | ||||||||||||||||||||||
$type?: ButtonHTMLAttributes<HTMLButtonElement>['type']; | ||||||||||||||||||||||
onclick?: () => void; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
export default function Button({ | ||||||||||||||||||||||
children, | ||||||||||||||||||||||
$btnClass, | ||||||||||||||||||||||
$type = 'button', | ||||||||||||||||||||||
$BeforButtonIcon = '', | ||||||||||||||||||||||
$afterButtonIcon = '', | ||||||||||||||||||||||
onclick, | ||||||||||||||||||||||
}: IButtonModule) { | ||||||||||||||||||||||
export default function Button({ children, $btnClass, $type = 'button', $BeforButtonIcon = '', $afterButtonIcon = '', onclick }: IButtonModule) { | ||||||||||||||||||||||
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. React에서 제공하는 HTML 타입을 사용해보시는건 어떨까요?다음과 같이 리액트에서 제공하는 Attributes를 사용할 수도 있습니다: import cn from 'classnames';
import { ButtonHTMLAttributes } from 'react';
interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary' | 'none';
}
export default function MelonButton({ className, variant, ...rest }: Props) { 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
|
||||||||||||||||||||||
return ( | ||||||||||||||||||||||
<ButtonModule | ||||||||||||||||||||||
className={$btnClass} | ||||||||||||||||||||||
type={$type} | ||||||||||||||||||||||
$BeforButtonIcon={$BeforButtonIcon} | ||||||||||||||||||||||
$afterButtonIcon={$afterButtonIcon} | ||||||||||||||||||||||
onClick={onclick} | ||||||||||||||||||||||
> | ||||||||||||||||||||||
onClick={onclick}> | ||||||||||||||||||||||
{children} | ||||||||||||||||||||||
</ButtonModule> | ||||||||||||||||||||||
); | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,25 @@ | ||
import { IModal } from '../../modal/interface'; | ||
import { IModal } from '@/src/constant/modal'; | ||
import { CheckBoxWrap } from './checkBoxStyle'; | ||
|
||
interface ICheckBoxData { | ||
$data: IModal['$modalData']; | ||
} | ||
|
||
function CheckBox({ $data }: ICheckBoxData) { | ||
if ($data?.data) { | ||
return ( | ||
<CheckBoxWrap className="chk--list-type1"> | ||
{$data && | ||
$data.data.map((list: any) => ( | ||
<div className="inner" key={list.id}> | ||
<input type="checkbox" id={list.id} /> | ||
<label htmlFor={list.id}> | ||
<strong>{list.name}</strong> | ||
<span>{list.link.count}개 링크</span> | ||
</label> | ||
</div> | ||
))} | ||
</CheckBoxWrap> | ||
); | ||
} else { | ||
return ( | ||
<div> | ||
<input type="text" /> | ||
<label htmlFor=""></label> | ||
</div> | ||
); | ||
} | ||
function CheckBox({ $data }: IModal<any>['modalData']) { | ||
return ( | ||
<CheckBoxWrap className='chk--list-type1'> | ||
{$data && | ||
$data?.map((list: any) => ( | ||
<div | ||
className='inner' | ||
key={list.id}> | ||
<input | ||
type='checkbox' | ||
id={list.id} | ||
/> | ||
<label htmlFor={list.id}> | ||
<strong>{list.name}</strong> | ||
<span>{list.link.count}개 링크</span> | ||
</label> | ||
</div> | ||
))} | ||
</CheckBoxWrap> | ||
); | ||
} | ||
export default CheckBox; |
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.
오호 ! 프리티어를 적용하셨군요? 😊👍
코드가 정렬된 모습이 보기 좋습니다 !!