Skip to content

Commit

Permalink
[Refact] #36 header button loading
Browse files Browse the repository at this point in the history
1. 화면이 2번 렌더링 되는 것을 줄이기 위해 useEffect 제거
2. 가독성을 향상하기 위해 state 사용을 제거하고 props로 값을 넘겨주는
방식으로 구조를 변경
  • Loading branch information
sewonkimm committed May 24, 2020
1 parent 4376668 commit 64a4e04
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 35 deletions.
44 changes: 12 additions & 32 deletions app/src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,25 @@
import React, { useState, useEffect } from 'react';
import React from 'react';
import styles from './styles.scss';

export interface Props {
path: string;
}

const Header = ({ path }: Props) => {
const [select, setSelect] = useState(false);
const [logout, setLogout] = useState(false);
const [save, setSave] = useState(false);
const [back, setBack] = useState(false);
type HeaderProps = {
hasSelectBtn?: boolean,
hasLogoutBtn?: boolean,
hasSaveBtn?: boolean,
hasBackBtn?: boolean,
};

useEffect(() => {
if (path == 'folder-list') {
setSelect(true);
setLogout(true);
setSave(false);
setBack(false);
} else if (path === 'memo-list') {
setSelect(true);
setLogout(false);
setSave(false);
setBack(true);
} else if (path === 'memo-edit') {
setSelect(false);
setLogout(false);
setSave(true);
setBack(true);
}
});
const Header = ({ hasSelectBtn, hasLogoutBtn, hasSaveBtn, hasBackBtn }: HeaderProps) => {

return (
<div className={styles.header}>
<div className={styles.home_btn_div}>
<div className={styles.home_btn} />
</div>

{select ? <div className={styles.select_btn} /> : null}
{save ? <div className={styles.save_btn} /> : null}
{logout ? <div className={styles.logout_btn} /> : null}
{back ? <div className={styles.back_btn} /> : null}
{ hasSelectBtn && <div className={styles.select_btn} /> }
{ hasSaveBtn && <div className={styles.save_btn} /> }
{ hasLogoutBtn && <div className={styles.logout_btn} /> }
{ hasBackBtn && <div className={styles.back_btn} /> }
</div>
);
};
Expand Down
2 changes: 2 additions & 0 deletions app/src/components/Header/styles.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// mixin 활용해 중복되는 부분 제거

.header {
display: flex;
justify-content: start;
Expand Down
2 changes: 1 addition & 1 deletion app/src/containers/FolderListPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import FolderSetting from '../../components/FolderSetting';
const FolderListPage = () => {
return (
<>
<Header path="folder-list" />
<Header hasSelectBtn={true} hasLogoutBtn={true}/>
<FolderSetting />
<div className={styles.folder_container}>
<div className={styles.folder_list}>
Expand Down
3 changes: 2 additions & 1 deletion app/src/containers/MemoEditPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import styles from './styles.scss';
const MemoEditPage = () => {
return (
<div className={styles.edit_container}>
<Header path="memo-edit" />
<Header hasSaveBtn={true} hasBackBtn={true} />

<div className={styles.toolbar}>
<div className={styles.bold} />
<div className={styles.italic} />
Expand Down
2 changes: 1 addition & 1 deletion app/src/containers/MemoListPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import MemoSetting from '../../components/MemoSetting';
const MemoListPage = () => {
return (
<>
<Header path="memo-list" />
<Header hasSelectBtn={true} hasBackBtn={true} />
<MemoSetting />

<div className={styles.memo_list_container}>
Expand Down

0 comments on commit 64a4e04

Please sign in to comment.