|
1 | 1 | import React from 'react'; |
2 | | -import { useNavigate } from 'react-router-dom'; |
3 | | -import { useRedirectPage } from '../../hooks/useRedirectPage'; |
4 | 2 | import styled from 'styled-components'; |
5 | 3 |
|
| 4 | +import ButtonText from './elements/ButtonText'; |
| 5 | +import Button from './elements/Button'; |
| 6 | + |
6 | 7 | function ButtonContainer({ isMyPage, myUid, isLoggedUser }) { |
7 | | - const navigate = useNavigate(); |
8 | | - const [setPage] = useRedirectPage(); |
| 8 | + // 버튼 components |
| 9 | + const buttonToMyTruck = <ButtonText goTo={`/${myUid}`} text="내 붕어빵 트럭 가기" type="text" />; |
| 10 | + const buttonToCustomFish = <Button goTo={`/customFish/`} text="붕어빵 만들기" />; |
| 11 | + const buttonToMyList = <Button goTo={`/list/${myUid}`} text="내가 받은 붕어빵 확인" />; |
| 12 | + const buttonToMyLogin = <ButtonText goTo="/" text="로그인 하러 가기" type="text" />; |
9 | 13 |
|
10 | 14 | return ( |
11 | 15 | <ButtonConatinerWrap> |
12 | | - {isMyPage && ( |
13 | | - <button onClick={setPage.bind(this, `/list/${myUid}`)}> |
14 | | - <img src="./assets/images/member/button.png" alt="내가 받은 붕어빵 확인 버튼" /> |
15 | | - <span> 내가 받은 붕어빵 확인</span> |
16 | | - </button> |
17 | | - )} |
| 16 | + {isMyPage && <>{buttonToMyList}</>} |
18 | 17 |
|
19 | 18 | {!isLoggedUser && ( |
20 | 19 | <> |
21 | | - <button onClick={setPage.bind(this, `/customFish/`)}> |
22 | | - <img src="./assets/images/member/button.png" alt="붕어빵 만들기 버튼" /> |
23 | | - <span>붕어빵 만들기</span> |
24 | | - </button> |
25 | | - <button onClick={setPage.bind(this, `/`)} className="buttonLink"> |
26 | | - <span>로그인 하러 가기</span> |
27 | | - </button> |
| 20 | + {buttonToCustomFish} |
| 21 | + {buttonToMyLogin} |
28 | 22 | </> |
29 | 23 | )} |
30 | 24 |
|
31 | 25 | {!isMyPage && isLoggedUser && ( |
32 | 26 | <> |
33 | | - <button onClick={setPage.bind(this, `/customFish/`)}> |
34 | | - <img src="./assets/images/member/button.png" alt="붕어빵 만들기 버튼" /> |
35 | | - <span>붕어빵 만들기</span> |
36 | | - </button> |
37 | | - <button |
38 | | - onClick={() => { |
39 | | - navigate(`/${myUid}`, { state: { loggedIn: true } }); |
40 | | - }} |
41 | | - className="buttonLink" |
42 | | - > |
43 | | - <span>내 붕어빵 트럭 가기</span> |
44 | | - </button> |
| 27 | + {buttonToCustomFish} |
| 28 | + {buttonToMyTruck} |
45 | 29 | </> |
46 | 30 | )} |
47 | 31 | </ButtonConatinerWrap> |
48 | 32 | ); |
49 | 33 | } |
50 | 34 |
|
51 | | -export default ButtonContainer; |
| 35 | +export default React.memo(ButtonContainer); |
52 | 36 |
|
53 | 37 | // 버튼 박스 |
54 | | -const ButtonConatinerWrap = styled.section` |
55 | | - button { |
56 | | - width: 100%; |
57 | | - height: 70px; |
58 | | - padding: 0; |
59 | | - position: relative; |
60 | | - cursor: pointer; |
61 | | - font-family: 'kotra'; |
62 | | - font-size: 24px; |
63 | | - line-height: 28px; |
64 | | - /* font-weight: 700; */ |
65 | | - background-color: transparent; |
66 | | - border: none; |
67 | | - color: #ffffff; |
68 | | - transition: all 0.2s; |
69 | | -
|
70 | | - img { |
71 | | - width: 100%; |
72 | | - position: absolute; |
73 | | - top: 50%; |
74 | | - left: 50%; |
75 | | - transform: translate(-50%, -50%); |
76 | | - } |
77 | | -
|
78 | | - span { |
79 | | - position: absolute; |
80 | | - top: 50%; |
81 | | - left: 50%; |
82 | | - transform: translate(-50%, -50%); |
83 | | - white-space: nowrap; |
84 | | - } |
85 | | -
|
86 | | - &:hover { |
87 | | - transform: translateY(-2px); |
88 | | - } |
89 | | - } |
90 | | -
|
91 | | - .buttonLink { |
92 | | - height: 70px; |
93 | | - background: transparent; |
94 | | - color: #73390b; |
95 | | -
|
96 | | - span { |
97 | | - display: inline-block; |
98 | | - line-height: 28px; |
99 | | - border-bottom: 2px solid #73390b; |
100 | | -
|
101 | | - white-space: nowrap; |
102 | | - } |
103 | | -
|
104 | | - &:hover { |
105 | | - transform: translateY(-1px); |
106 | | - opacity: 0.8; |
107 | | - box-shadow: none; |
108 | | - } |
109 | | - } |
110 | | -`; |
| 38 | +const ButtonConatinerWrap = styled.section``; |
0 commit comments