-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO - redux dispatch 비동기작업 - input bar conflict잡기 - 질문 리스트 삭제 - 질문 삭제 - 이동 관련 순서 저장하기
- Loading branch information
Showing
20 changed files
with
391 additions
and
98 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,56 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { configureStore, combineReducers, createSlice } from '@reduxjs/toolkit'; | ||
import Modal from './Modal'; | ||
import { MODALS } from '../../utils/constant'; | ||
|
||
const modalReducer = createSlice({ | ||
name: 'modal', | ||
initialState: { | ||
[MODALS.QUESTIONLIST_SAVE_MODAL]: true, | ||
[MODALS.SELF_TRAIN_START_MODAL]: true, | ||
}, | ||
reducers: { | ||
displayModal(state, { payload: { modalName } }) { | ||
return { | ||
...state, | ||
[modalName]: true, | ||
}; | ||
}, | ||
removeModal(state, { payload: { modalName } }) { | ||
return { | ||
...state, | ||
[modalName]: false, | ||
}; | ||
}, | ||
}, | ||
}); | ||
|
||
const reducers = combineReducers({ | ||
modal: modalReducer.reducer, | ||
}); | ||
|
||
const store = configureStore({ reducer: reducers }); | ||
|
||
const withReduxMockStore = (story) => ( | ||
<Provider store={store}>{story()}</Provider> | ||
); | ||
|
||
export default { | ||
title: 'Modal', | ||
description: 'modals', | ||
decorators: [withReduxMockStore], | ||
}; | ||
|
||
const modals = (args) => <Modal {...args} />; | ||
export const QuestionListSaveModal = modals.bind({}); | ||
export const SelfTrainStartModal = modals.bind({}); | ||
|
||
QuestionListSaveModal.args = { | ||
modalName: MODALS.QUESTIONLIST_SAVE_MODAL, | ||
}; | ||
|
||
SelfTrainStartModal.args = { | ||
modalName: MODALS.SELF_TRAIN_START_MODAL, | ||
}; |
This file contains 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,68 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import PropTypes from 'prop-types'; | ||
import { useDispatch } from 'react-redux'; | ||
import { hideModal } from '../../../store/Modal/modal'; | ||
|
||
const Background = styled.div` | ||
position: fixed; | ||
left: 0; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
overflow: auto; | ||
background-color: rgba(0,0,0,0.4); | ||
z-index: 999; | ||
`; | ||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
overflow: auto; | ||
outline: none; | ||
z-index: 1000; | ||
`; | ||
|
||
const Content = styled.div` | ||
display: inline-block; | ||
border-radius: 10px; | ||
box-shadow: 0 6px 12px 0 rgba(4, 4, 161, 0.04); | ||
background-color: #ffffff; | ||
margin: 0 auto; | ||
outline: none; | ||
`; | ||
|
||
export default function ModalWrapper({ modalName, children }) { | ||
const dispatch = useDispatch(); | ||
const handleCloseModal = (e) => { | ||
if (e.target === e.currentTarget) { | ||
dispatch(hideModal(modalName)); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Background /> | ||
<Wrapper tabIndex="-1" onClick={handleCloseModal}> | ||
<Content tabIndex="0"> | ||
{children} | ||
</Content> | ||
</Wrapper> | ||
</> | ||
); | ||
} | ||
|
||
ModalWrapper.propTypes = { | ||
modalName: PropTypes.string, | ||
children: PropTypes.element, | ||
}; | ||
|
||
ModalWrapper.defaultProp = { | ||
modalName: '', | ||
}; |
This file contains 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 @@ | ||
export { default } from './ModalWrapper'; |
This file contains 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
Oops, something went wrong.