-
Notifications
You must be signed in to change notification settings - Fork 0
refactor:TopBar #30
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
Open
jongbin26
wants to merge
12
commits into
main
Choose a base branch
from
refactor/top-bar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
refactor:TopBar #30
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0ca32ab
refactor: main 반영
jongbin26 73edf6a
refactor: TopBar 컴포넌트 분리
jongbin26 e9870f9
fix: S 스타일, VStack 적용 및 default Input 파일 설정;
jongbin26 97f85f4
fix: S 스타일 적용 및 HStack 적용"
jongbin26 88d679a
fix: PR 스타일 수정 반영
jongbin26 e1624ca
fix: fontSize 수정 및 HStack 적용
jongbin26 bc8fbff
fix: 미사용 style 삭제
jongbin26 3befe86
fix: constants 폴더 생성 및 비밀번호 최소 길이 상수 사용
jongbin26 10ad7ed
fix: 중복 코드 수정 및 비밀번호 최소 길이 상수 사용"
jongbin26 d475303
fix: TopBarItem 경로 상수 선언
jongbin26 813a946
fix: shopUpdated legacy 삭제
jongbin26 0c09322
merge: main 병합 충돌 해결
jongbin26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/components/TopBar/components/ChangePasswordModalChildren.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import Input from '../../Input/Input'; | ||
| import { forwardRef } from 'react'; | ||
|
|
||
| const ChangePasswordModalChildren = forwardRef( | ||
| ( | ||
| { nextPasswordRef, changePasswordFocus, checkedNextPasswordRef, checkedChangePasswordFocus }, | ||
| ref | ||
| ) => { | ||
| return ( | ||
| <div style={{ width: '100%', display: 'flex', flexDirection: 'column', gap: 10 }}> | ||
jongbin26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Input | ||
| type={'password'} | ||
| ref={nextPasswordRef} | ||
| isFocused={changePasswordFocus} | ||
| initialPlaceholder={'변경할 비밀번호'} | ||
| /> | ||
| <Input | ||
| type={'password'} | ||
| ref={checkedNextPasswordRef} | ||
| isFocused={checkedChangePasswordFocus} | ||
| initialPlaceholder={'비밀번호 재입력'} | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| export default ChangePasswordModalChildren; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import styled from 'styled-components'; | ||
jongbin26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import { useNavigate } from 'react-router-dom'; | ||
| import logo from '../../../assets/logo.svg'; | ||
| import typo from '../../../assets/typo.svg'; | ||
| const TopBarLeft = () => { | ||
| const navigate = useNavigate(); | ||
| return ( | ||
| <Container onClick={() => navigate('/')}> | ||
| <ImageWrapper> | ||
jongbin26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <LogoImage src={logo} /> | ||
| </ImageWrapper> | ||
| <ImageWrapper> | ||
| <TypoImage src={typo} /> | ||
| </ImageWrapper> | ||
| </Container> | ||
jongbin26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| }; | ||
| export default TopBarLeft; | ||
| const Container = styled.div` | ||
jongbin26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| display: flex; | ||
| flex-direction: row; | ||
| gap: 10px; | ||
| cursor: pointer; | ||
| `; | ||
| const ImageWrapper = styled.div` | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| `; | ||
| const LogoImage = styled.img` | ||
| width: 32px; | ||
| height: 32px; | ||
| `; | ||
| const TypoImage = styled.img` | ||
| width: 55px; | ||
| height: 32px; | ||
| `; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import styled, { css } from 'styled-components'; | ||
| import { useState, useEffect } from 'react'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import useLoginState from '../../../hooks/useLoginState'; | ||
| import UserMenuConainer from './UserMenuContainer'; | ||
|
|
||
| const TopBarItems = [ | ||
| { | ||
| name: '문제 목록', | ||
| route: '/problem', | ||
| }, | ||
| { | ||
| name: '구성원', | ||
| route: '/member', | ||
jongbin26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| { | ||
| name: '상점', | ||
| route: '/shop', | ||
| }, | ||
| ]; | ||
|
|
||
| const TopBarRight = () => { | ||
| const [selectedItem, _setSelectedItem] = useState(window.location.pathname); | ||
| const [shopUpdated, setShopUpdated] = useState(true); | ||
| const { isLoggedIn } = useLoginState(); | ||
| const navigate = useNavigate(); | ||
|
|
||
| useEffect(() => { | ||
| const shopChecked = localStorage.getItem('shopChecked'); | ||
| if (shopChecked === null) { | ||
| // shopChecked 항목이 없으면 false로 초기화 | ||
| localStorage.setItem('shopChecked', 'false'); | ||
| setShopUpdated(true); | ||
| } | ||
| setShopUpdated(shopChecked === 'false'); | ||
| }, []); | ||
|
|
||
| function goRoute(route) { | ||
| if (route === selectedItem) return; | ||
| window.scrollTo(0, 0); | ||
| if (route === '/shop') { | ||
| localStorage.setItem('shopChecked', 'true'); | ||
| setShopUpdated(false); | ||
| } | ||
| navigate(route); | ||
| } | ||
|
|
||
| return ( | ||
| <Container> | ||
| {TopBarItems.map((item, index) => ( | ||
| <TopBarItem | ||
| key={index} | ||
| selected={selectedItem === item.route} | ||
| onClick={() => goRoute(item.route)} | ||
| > | ||
| {item.name} | ||
| {item.route === '/shop' && shopUpdated && ( | ||
| <span style={{ color: 'red', marginLeft: '5px' }}>•</span> | ||
jongbin26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| )} | ||
| </TopBarItem> | ||
| ))} | ||
| {isLoggedIn ? ( | ||
| <UserMenuConainer /> | ||
| ) : ( | ||
| <TopBarButton active={!isLoggedIn} onClick={() => navigate('/login')}> | ||
| 로그인 | ||
| </TopBarButton> | ||
| )} | ||
| </Container> | ||
| ); | ||
| }; | ||
| export default TopBarRight; | ||
| const Container = styled.div` | ||
jongbin26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| display: flex; | ||
| flex-direction: row; | ||
| gap: 40px; | ||
| `; | ||
|
|
||
| const TopBarItem = styled.div` | ||
| display: flex; | ||
| align-items: center; | ||
| font-size: 16px; | ||
| font-weight: 500; | ||
| color: ${props => props.theme.subText}; | ||
| cursor: pointer; | ||
| user-select: none; | ||
| &:hover { | ||
| color: ${props => props.theme.titleText}; | ||
| } | ||
| ${props => | ||
| props.selected && | ||
| css` | ||
| color: ${props => props.theme.primary}; | ||
| &:hover { | ||
| color: ${props => props.theme.primary}; | ||
| } | ||
| `} | ||
| `; | ||
|
|
||
| const TopBarButton = styled.div` | ||
| padding: 12px; | ||
| border-radius: 12px; | ||
| background-color: ${props => props.theme.primary}; | ||
|
|
||
| color: #ffffff; | ||
jongbin26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| font-size: 12px; | ||
| font-weight: 500; | ||
| cursor: pointer; | ||
|
|
||
| &:hover { | ||
| filter: brightness(0.9); | ||
| } | ||
| `; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import Button from '../../Buttons'; | ||
| const UserMenuChildren = ({ | ||
| showChangePasswordModal, | ||
| showProfileChangeModal, | ||
| hideUserMenu, | ||
| showLogoutModal, | ||
| }) => { | ||
| return ( | ||
| <> | ||
| <Button | ||
| onClick={() => { | ||
| showChangePasswordModal(); | ||
| }} | ||
| > | ||
| 비밀번호 변경 | ||
| </Button> | ||
| <Button | ||
| onClick={() => { | ||
| showProfileChangeModal(); | ||
| }} | ||
| > | ||
| 프로필 사진 변경 | ||
| </Button> | ||
| <Button | ||
| color={'red'} | ||
| onClick={() => { | ||
| hideUserMenu(); | ||
| showLogoutModal(); | ||
| }} | ||
| > | ||
| 로그아웃 | ||
| </Button> | ||
| </> | ||
| ); | ||
| }; | ||
| export default UserMenuChildren; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { useState, useRef } from 'react'; | ||
| import useUserState from '../../../hooks/useUserState'; | ||
| import useLoginState from '../../../hooks/useLoginState'; | ||
|
|
||
| import { Message } from '../../Message'; | ||
| import useModal from '../../../hooks/useModal'; | ||
| import useContainer from '../../../hooks/useContainer'; | ||
|
|
||
| import { checkPasswordValidate, renderUserImage, uploadImage } from '../util/util'; | ||
jongbin26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import ChangePasswordModalChildren from '../components/ChangePasswordModalChildren'; | ||
| import ProfileChangeModalChildren from '../components/ProfileChangeModalChildren'; | ||
| import UserMenuChildren from '../components/UserMenuChildren'; | ||
|
|
||
| const UserMenuConainer = () => { | ||
| const [messageText, setMessageText] = useState(''); | ||
| const [selectedFile, setselectedFile] = useState(null); | ||
| const [changePasswordFocus, setChangePasswordFocus] = useState(false); | ||
| const [checkedChangePasswordFocus, setCheckedChangePasswordFocus] = useState(false); | ||
|
|
||
| const nextPasswordRef = useRef(); | ||
| const checkedNextPasswordRef = useRef(); | ||
|
|
||
| const userMenu = useContainer(); | ||
| const { user, setUserInfo } = useUserState(); | ||
| const { initLoginStatus } = useLoginState(); | ||
|
|
||
| const logoutModal = useModal({ | ||
| description: '정말 로그아웃하시겠어요?', | ||
| cancelText: '취소', | ||
| okText: '확인', | ||
| closable: true, | ||
| onOk: () => { | ||
| initLoginStatus(); | ||
| }, | ||
| }); | ||
|
|
||
| const profileChangeModal = useModal({ | ||
| description: '변경할 이미지를 올려주세요', | ||
| cancelText: '취소', | ||
| okText: '확인', | ||
| closable: true, | ||
| onOk: () => | ||
| uploadImage(selectedFile, setUserInfo, setselectedFile, setMessageText, toastMessage), | ||
| }); | ||
|
|
||
| const changePasswordModal = useModal({ | ||
| cancelText: '취소', | ||
| closable: true, | ||
| onOk: () => | ||
| checkPasswordValidate( | ||
| nextPasswordRef, | ||
| checkedNextPasswordRef, | ||
| setChangePasswordFocus, | ||
| setCheckedChangePasswordFocus, | ||
| setMessageText, | ||
| changePasswordModal, | ||
| toastMessage | ||
| ), | ||
| }); | ||
| const toastMessage = Message(); | ||
| return ( | ||
| <> | ||
| {toastMessage.render({ | ||
| children: ( | ||
| <div style={{ fontSize: 15, fontWeight: 400 }}> ✅ {messageText}</div> | ||
jongbin26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ), | ||
| })} | ||
| {profileChangeModal.render({ | ||
| children: ( | ||
| <ProfileChangeModalChildren | ||
| selectedFile={selectedFile} | ||
| setselectedFile={setselectedFile} | ||
| /> | ||
| ), | ||
| })} | ||
| {changePasswordModal.render({ | ||
| children: ( | ||
| <ChangePasswordModalChildren | ||
| nextPasswordRef={nextPasswordRef} | ||
| changePasswordFocus={changePasswordFocus} | ||
| checkedNextPasswordRef={checkedNextPasswordRef} | ||
| checkedChangePasswordFocus={checkedChangePasswordFocus} | ||
| /> | ||
| ), | ||
| })} | ||
| {logoutModal.render()} | ||
| <div style={{ position: 'absolute', right: 0, margin: 10, marginTop: 64 }}> | ||
| {userMenu.render({ | ||
| children: ( | ||
| <UserMenuChildren | ||
| showChangePasswordModal={changePasswordModal.show} | ||
| showProfileChangeModal={profileChangeModal.show} | ||
| hideUserMenu={userMenu.hide} | ||
| showLogoutModal={logoutModal.show} | ||
| /> | ||
| ), | ||
| })} | ||
| </div> | ||
| {renderUserImage(user, userMenu)} | ||
| </> | ||
| ); | ||
| }; | ||
| export default UserMenuConainer; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.