1
1
import { InformationCircleIcon } from '@heroicons/react/outline' ;
2
2
import classNames from 'classnames' ;
3
3
import { useAtomValue , useUpdateAtom } from 'jotai/utils' ;
4
- import React , { useContext } from 'react' ;
4
+ import React from 'react' ;
5
5
import { activeFileAtom , saveFileAtom } from '../../atoms/editor' ;
6
6
import { useDarkMode } from '../../context/DarkModeContext' ;
7
7
import {
8
- Language ,
9
8
LANGUAGE_LABELS ,
10
- } from '../../context/UserDataContext/properties/userLang' ;
11
- import UserDataContext from '../../context/UserDataContext/UserDataContext' ;
9
+ useSetThemeSetting ,
10
+ useSetUserLangSetting ,
11
+ useUserLangSetting ,
12
+ } from '../../context/UserDataContext/properties/simpleProperties' ;
12
13
import LogoSquare from '../LogoSquare' ;
13
14
import { fetchFileContent } from './editorUtils' ;
14
15
15
16
export const EditorTopNav = ( ) : JSX . Element => {
16
17
const activeFile = useAtomValue ( activeFileAtom ) ;
17
18
const saveFile = useUpdateAtom ( saveFileAtom ) ;
18
- const userSettings = useContext ( UserDataContext ) ;
19
19
const isDarkMode = useDarkMode ( ) ;
20
+ const userLang = useUserLangSetting ( ) ;
21
+ const setUserLang = useSetUserLangSetting ( ) ;
22
+ const setTheme = useSetThemeSetting ( ) ;
20
23
21
24
const handleReloadContent = async ( ) => {
25
+ if ( ! activeFile ) return ;
22
26
if ( confirm ( 'Reload file from Github? Your local changes will be lost.' ) ) {
23
27
const data = await fetchFileContent ( activeFile . path ) ;
24
28
// note: we can't use setMarkdown / setProblems in sequence because setProblems would override setMarkdown
@@ -101,16 +105,16 @@ export const EditorTopNav = (): JSX.Element => {
101
105
</ div >
102
106
< div className = "flex items-center" >
103
107
< nav className = "flex space-x-1" aria-label = "Tabs" >
104
- { [ 'cpp' , 'java' , 'py' ] . map ( ( tab : Language ) => (
108
+ { ( [ 'cpp' , 'java' , 'py' ] as const ) . map ( tab => (
105
109
< button
106
110
key = { tab }
107
111
className = { classNames (
108
- tab === userSettings . lang
112
+ tab === userLang
109
113
? 'bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300'
110
114
: 'text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300' ,
111
115
'px-3 py-2 font-medium text-sm rounded-md focus:outline-none transition'
112
116
) }
113
- onClick = { ( ) => userSettings . setLang ( tab ) }
117
+ onClick = { ( ) => setUserLang ( tab ) }
114
118
>
115
119
{ LANGUAGE_LABELS [ tab ] }
116
120
</ button >
@@ -132,7 +136,7 @@ export const EditorTopNav = (): JSX.Element => {
132
136
< div className = "mx-4 block border-l border-gray-200 dark:border-gray-700 h-6 self-center" />
133
137
134
138
< button
135
- onClick = { ( ) => userSettings . setTheme ( isDarkMode ? 'light' : 'dark' ) }
139
+ onClick = { ( ) => setTheme ( isDarkMode ? 'light' : 'dark' ) }
136
140
className = "-mx-1 p-1 border-2 border-transparent text-gray-400 dark:text-gray-400 rounded-full hover:text-gray-300 dark:hover:text-dark-high-emphasis focus:outline-none focus:text-gray-500 focus:bg-gray-100 dark:focus:bg-gray-700 transition"
137
141
>
138
142
{ isDarkMode ? (
0 commit comments