forked from codesquad-members-2023/issue-tracker-max
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ssues-crud [FE] 이슈 및 코멘트 CRUD
- Loading branch information
Showing
41 changed files
with
1,073 additions
and
706 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { ReactNode, createContext, useEffect, useState } from 'react'; | ||
import { User } from '../../type/User.type'; | ||
import { Theme, ThemeProvider, css } from '@emotion/react'; | ||
import { themes } from '../../styles/styles'; | ||
|
||
type UserProviderProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
export const UserContext = createContext<{ | ||
user?: User; | ||
setUser?: React.Dispatch<React.SetStateAction<User>>; | ||
darkMode?: boolean; | ||
onToggleTheme?: () => void; | ||
} | null>(null); | ||
|
||
export default function UserProvider({ children }: UserProviderProps) { | ||
const [user, setUser] = useState<User>(() => { | ||
return { | ||
accessToken: localStorage.getItem('accessToken') || '', | ||
refreshToken: localStorage.getItem('refreshToken') || '', | ||
member: { | ||
id: Number(localStorage.getItem('id')) || 0, | ||
name: localStorage.getItem('name') || '', | ||
imageUrl: localStorage.getItem('imageUrl') || '', | ||
}, | ||
}; | ||
}); | ||
const [darkMode, setDarkMode] = useState(() => { | ||
const storedDarkMode = localStorage.getItem('darkMode'); | ||
return storedDarkMode ? JSON.parse(storedDarkMode) : false; | ||
}); | ||
|
||
useEffect(() => { | ||
setUser({ | ||
accessToken: localStorage.getItem('accessToken') || '', | ||
refreshToken: localStorage.getItem('refreshToken') || '', | ||
member: { | ||
id: Number(localStorage.getItem('id')) || 0, | ||
name: localStorage.getItem('name') || '', | ||
imageUrl: localStorage.getItem('imageUrl') || '', | ||
}, | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
localStorage.setItem('darkMode', String(darkMode)); | ||
}, [darkMode]); | ||
|
||
const onToggleTheme = () => { | ||
setDarkMode((prevMode: boolean) => !prevMode); | ||
}; | ||
|
||
const theme = darkMode ? themes.dark : themes.light; | ||
|
||
return ( | ||
<UserContext.Provider value={{ user, setUser, darkMode, onToggleTheme }}> | ||
<ThemeProvider theme={theme}> | ||
<div css={body(theme)}>{children}</div> | ||
</ThemeProvider> | ||
</UserContext.Provider> | ||
); | ||
} | ||
|
||
const body = (theme: Theme) => css` | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
height: 100%; | ||
flex-grow: 1; | ||
overflow: auto; | ||
background-color: ${theme.neutral.surfaceDefault}; | ||
& svg path { | ||
stroke: ${theme.neutral.textDefault}; | ||
} | ||
`; |
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
Oops, something went wrong.