Skip to content

Commit f1b361b

Browse files
committed
Merge branch 'develop' of https://github.com/prgrms-web-devcourse-final-project/WEB1_1_DDang_FE into 43-design/design-social-page
2 parents bb4a1e0 + ef106e5 commit f1b361b

File tree

5 files changed

+49
-26
lines changed

5 files changed

+49
-26
lines changed

src/modals/ModalContainer/index.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1+
import { useEffect } from 'react'
12
import * as S from './styles'
23
import { useModalStore } from '~stores/modalStore'
34

45
export default function ModalContainer() {
5-
const { modalList } = useModalStore()
6+
const { modalList, popModal } = useModalStore()
7+
8+
useEffect(() => {
9+
if (modalList.length > 0) {
10+
window.history.pushState({ modal: true }, '', window.location.href)
11+
}
12+
13+
const handlePopState = (e: PopStateEvent) => {
14+
if (e.state && e.state.modal) {
15+
popModal()
16+
}
17+
}
18+
19+
window.addEventListener('popstate', handlePopState)
20+
return () => window.removeEventListener('popstate', handlePopState)
21+
}, [modalList, popModal])
622

723
return <>{modalList.length ? <S.ModalWrapper>{...modalList}</S.ModalWrapper> : null}</>
824
}

src/pages/MyPage/SettingModal/index.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@ import { PrevButton } from '~components/Button/PrevButton/styles'
33
import { Typo17 } from '~components/Typo'
44
import ToggleArea from '~components/ToggleArea'
55
import ToggleBox from '~components/ToggleBox'
6-
type SettingModalProps = {
7-
isOpen: boolean
8-
onClose: () => void
9-
}
6+
import { useModalStore } from '~stores/modalStore'
107

11-
export default function SettingModal({ isOpen, onClose }: SettingModalProps) {
12-
if (!isOpen) return null
8+
export default function SettingModal() {
9+
const { popModal } = useModalStore()
1310

1411
return (
1512
<S.SettingModalContainer>
1613
<S.Header>
17-
<S.BackButton onClick={onClose}>
14+
<S.BackButton onClick={popModal}>
1815
<PrevButton size={28} />
1916
</S.BackButton>
2017
<S.TitleWrap>

src/pages/MyPage/index.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
import { useState } from 'react'
2-
import * as S from './styles'
1+
import ProfileImage from 'assets/masterprofile.svg?react'
32
import { Helmet } from 'react-helmet-async'
43
import { IoSettingsOutline } from 'react-icons/io5'
5-
import ProfileImage from 'assets/masterprofile.svg?react'
6-
import { Typo13, Typo15, Typo24 } from '~components/Typo'
7-
import ToggleBox from '~components/ToggleBox'
84
import { useTheme } from 'styled-components'
5+
import ToggleBox from '~components/ToggleBox'
6+
import { Typo13, Typo15, Typo24 } from '~components/Typo'
97
import SettingModal from '~pages/MyPage/SettingModal'
8+
import { useModalStore } from '~stores/modalStore'
9+
import * as S from './styles'
1010

1111
export default function MyPage() {
1212
const theme = useTheme()
13-
const [onClickSetting, setOnclickSetting] = useState(false)
13+
const { pushModal } = useModalStore()
1414

1515
const onSettingsClick = () => {
16-
setOnclickSetting(true)
17-
}
18-
19-
const onCloseSettingModal = () => {
20-
setOnclickSetting(false)
16+
pushModal(<SettingModal />)
2117
}
2218

2319
return (
@@ -78,7 +74,6 @@ export default function MyPage() {
7874
</S.CustomActionButton>
7975
</S.ButtonArea>
8076
</S.MainContainer>
81-
<SettingModal isOpen={onClickSetting} onClose={onCloseSettingModal} />
8277
</S.MyPage>
8378
)
8479
}

src/pages/SocialPage/components/ChatItem/styles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const ChatItem = styled.div`
77
align-items: center;
88
gap: 12px;
99
background-color: ${({ theme }) => theme.colors.grayscale.gc_4};
10+
cursor: pointer;
1011
`
1112
export const TypoWrapper = styled.div``
1213
export const UserInfoWrapper = styled.div`

src/stores/modalStore.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,29 @@ interface ModalStore {
88
clearModal: () => void
99
}
1010

11-
export const useModalStore = create<ModalStore>(set => ({
11+
export const useModalStore = create<ModalStore>((set, get) => ({
1212
modalList: [],
13-
pushModal: modal =>
13+
pushModal: modal => {
1414
set(state => ({
1515
modalList: [...state.modalList, modal],
16-
})),
17-
popModal: () =>
16+
}))
17+
// 모달이 추가될 때 새로운 히스토리 항목 생성
18+
if (get().modalList.length > 0) {
19+
window.history.pushState({ modal: true }, '', window.location.href)
20+
}
21+
},
22+
popModal: () => {
23+
// 모달이 제거될 때 히스토리 뒤로가기
24+
if (get().modalList.length > 0) {
25+
window.history.back()
26+
}
1827
set(state => ({
1928
modalList: state.modalList.slice(0, -1),
20-
})),
21-
clearModal: () => set({ modalList: [] }),
29+
}))
30+
},
31+
clearModal: () => {
32+
set({ modalList: [] })
33+
// 모든 모달 제거 시 히스토리 초기화
34+
window.history.go(-get().modalList.length)
35+
},
2236
}))

0 commit comments

Comments
 (0)