-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from k-impossible/feat/nav
[FE] Nav 전역 상태 완료
- Loading branch information
Showing
19 changed files
with
212 additions
and
57 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,30 @@ | ||
import { Chapter, UserChapter } from '../../interfaces/Chapter.interface'; | ||
|
||
export const chapterData: Array<Chapter> = [ | ||
{ | ||
title: '인사 나누기', | ||
chapterId: 1, | ||
chapterWords: [1, 2, 3] | ||
}, | ||
{ | ||
title: '활동에 대해 말하기', | ||
chapterId: 2, | ||
chapterWords: [4, 5, 6] | ||
} | ||
]; | ||
|
||
export const userChapterData: UserChapter = { | ||
chapterList: [ | ||
{ | ||
chapterId: 1, | ||
chapterStatus: true, | ||
progress: [1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1] | ||
}, | ||
{ | ||
chapterId: 2, | ||
chapterStatus: false, | ||
progress: [1, 1, 1, 1, 1, 1, 2, 2, 0, 0, 0, 0] | ||
} | ||
], | ||
learningChapterId: 2 | ||
}; |
Empty file.
Empty file.
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
Empty file.
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 |
---|---|---|
@@ -1,35 +1,33 @@ | ||
import { Box, List, ListItemButton, ListItemText, Avatar } from '@mui/material'; | ||
import DoneIcon from '@mui/icons-material/Done'; | ||
import { grey } from '@mui/material/colors'; | ||
import { Box, List } from '@mui/material'; | ||
import { Chapter } from '../../interfaces/Chapter.interface'; | ||
import NavItem from './NavItem'; | ||
|
||
interface NavProps { | ||
chapterList?: Array<Chapter>; | ||
location: string; | ||
} | ||
|
||
export default function Nav(props: NavProps) { | ||
const chapterList = props.chapterList; | ||
const location = props.location; | ||
|
||
function Nav() { | ||
return ( | ||
<Box | ||
sx={{ | ||
width: '100%', | ||
maxWidth: 300, | ||
height: '100vh', | ||
borderRight: 1, | ||
borderColor: grey[300] | ||
overflowY: 'scroll', | ||
padding: 0 | ||
}} | ||
> | ||
<List> | ||
<ListItemButton sx={{ borderBottom: 1, borderColor: grey[200] }}> | ||
<ListItemText | ||
primary="Chapter 1" | ||
primaryTypographyProps={{ style: { overflowWrap: 'break-word' } }} | ||
secondary="인사 나누기" | ||
/> | ||
<Avatar sx={{ bgcolor: 'success.light' }}> | ||
<DoneIcon /> | ||
</Avatar> | ||
</ListItemButton> | ||
<ListItemButton sx={{ borderBottom: 1, borderColor: grey[200] }}> | ||
<ListItemText primary="Chapter 2" secondary="활동에 대해 말하기" /> | ||
</ListItemButton> | ||
<List sx={{ padding: 0 }}> | ||
{location === '/' | ||
? chapterList?.map((el) => ( | ||
<NavItem key={el.chapterId} chapter={el} /> | ||
)) | ||
: null} | ||
</List> | ||
</Box> | ||
); | ||
} | ||
|
||
export default Nav; |
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,47 @@ | ||
import { Chapter } from '../../interfaces/Chapter.interface'; | ||
import DoneIcon from '@mui/icons-material/Done'; | ||
import { grey } from '@mui/material/colors'; | ||
import { ListItemButton, ListItemText, Avatar } from '@mui/material'; | ||
import React from 'react'; | ||
import { useAppSelector, useAppDispatch } from '../../redux/hooks'; | ||
import { setChapter } from '../../redux/slices/chapter'; | ||
|
||
interface NavItemProps { | ||
chapter?: Chapter; | ||
} | ||
|
||
export default function NavItem(props: NavItemProps) { | ||
const chapter = props.chapter; | ||
const chapterBigTitle = `Chapter ${chapter ? chapter.chapterId : 0}`; | ||
const selectedChapter = useAppSelector((state) => state.chapter); | ||
const dispatch = useAppDispatch(); | ||
|
||
const handleSelectChapter = () => { | ||
dispatch(setChapter(chapter!)); | ||
}; | ||
return ( | ||
<React.Fragment> | ||
{chapter ? ( | ||
<ListItemButton | ||
onClick={handleSelectChapter} | ||
sx={{ | ||
borderBottom: 1, | ||
borderBottomColor: grey[200], | ||
borderLeft: 8, | ||
borderLeftColor: | ||
chapter.chapterId === selectedChapter.chapterId | ||
? 'primary.main' | ||
: '#1976d200' | ||
}} | ||
> | ||
<ListItemText primary={chapterBigTitle} secondary={chapter.title} /> | ||
{chapter.chapterStatus ? ( | ||
<Avatar sx={{ bgcolor: 'success.main' }}> | ||
<DoneIcon /> | ||
</Avatar> | ||
) : null} | ||
</ListItemButton> | ||
) : null} | ||
</React.Fragment> | ||
); | ||
} |
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,19 @@ | ||
export interface Chapter { | ||
chapterId: number; | ||
title: string; | ||
chapterWords: Array<number>; | ||
chapterStatus?: boolean; | ||
learningChapterId?: number; | ||
progress?: number[]; | ||
} | ||
|
||
export interface UserChapterListItem { | ||
chapterId: number; | ||
chapterStatus: boolean; | ||
progress: number[]; | ||
} | ||
|
||
export interface UserChapter { | ||
chapterList: Array<UserChapterListItem>; | ||
learningChapterId: number; | ||
} |
Empty file.
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 |
---|---|---|
@@ -1,13 +1,53 @@ | ||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import Enter from '../../components/Enter/Enter'; | ||
import Nav from '../../components/Nav/Nav'; | ||
function MainPage() { | ||
import { chapterData, userChapterData } from '../../common/data/chapterData'; | ||
import { Chapter, UserChapter } from '../../interfaces/Chapter.interface'; | ||
import { useLocation } from 'react-router-dom'; | ||
import { useAppDispatch } from '../../redux/hooks'; | ||
import { setChapter } from '../../redux/slices/chapter'; | ||
export default function MainPage() { | ||
const [chapterList, setChapterList] = useState<Chapter[]>([]); | ||
// const [userChapter, setUserChapter] = useState<UserChapter>(); | ||
const location = useLocation().pathname; | ||
const dispatch = useAppDispatch(); | ||
|
||
useEffect(() => { | ||
// 회원정보가 있는 유저일 경우 | ||
// 챕터 완료 상태 변경 | ||
const changeStatusList = chapterData.map((chapter) => { | ||
const sameChapter = userChapterData?.chapterList.find( | ||
(userChapter) => userChapter.chapterId === chapter.chapterId | ||
); | ||
|
||
if (sameChapter?.chapterStatus) { | ||
return { | ||
...chapter, | ||
chapterStatus: true, | ||
learningChapterId: userChapterData.learningChapterId, | ||
progress: sameChapter?.progress | ||
}; | ||
} else { | ||
return { | ||
...chapter, | ||
chapterStatus: false, | ||
learningChapterId: userChapterData.learningChapterId, | ||
progress: sameChapter?.progress | ||
}; | ||
} | ||
}); | ||
setChapterList(changeStatusList); | ||
dispatch(setChapter(changeStatusList[0])); | ||
// setUserChapter(userChapterData); | ||
|
||
// TODO: 회원정보가 없는 유저일 경우 | ||
// localStorage Get Set | ||
}, []); | ||
|
||
return ( | ||
<React.Fragment> | ||
<Nav /> | ||
<Nav chapterList={chapterList} location={location} /> | ||
<Enter /> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
export default MainPage; |
Empty file.
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,29 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
import { RootState } from '../store'; | ||
import { Chapter } from '../../interfaces/Chapter.interface'; | ||
|
||
const initialState: Chapter = { | ||
title: '인사 나누기', | ||
chapterId: 1, | ||
chapterWords: [1, 2, 3], | ||
chapterStatus: false, | ||
learningChapterId: 1, | ||
progress: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | ||
}; | ||
|
||
export const chapterSlice = createSlice({ | ||
name: 'chapter', | ||
initialState, | ||
reducers: { | ||
setChapter: (state, action: { payload: Chapter }) => { | ||
state = action.payload; | ||
return state; | ||
} | ||
} | ||
}); | ||
|
||
export const { setChapter } = chapterSlice.actions; | ||
|
||
export const selectChapter = (state: RootState) => state.chapter; | ||
|
||
export default chapterSlice.reducer; |
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
Empty file.
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