@@ -5,16 +5,18 @@ export const AppContext = React.createContext(null)
55
66export function AppProvider ( { children, ...rest } ) {
77 let currentTheme = "light" ;
8- chrome . storage . local . get ( 'theme' , ( thm ) => currentTheme = thm . theme ) ;
9- const [ history , setHistory ] = useState ( [ ] )
10- const [ theme , setTheme ] = useState ( currentTheme )
8+ const [ history , setHistory ] = useState ( [ ] )
9+ const [ theme , setTheme ] = useState ( currentTheme )
1110
12- useEffect ( ( ) => {
13- document . body . classList . add ( currentTheme ) ;
14- } , [ ] )
11+ useEffect ( ( ) => {
12+ chrome . storage . local . get ( 'theme' , ( thm ) => {
13+ setTheme ( thm . theme ? thm . theme : currentTheme )
14+ document . body . classList . add ( thm . theme ? thm . theme : currentTheme ) ;
15+ } ) ;
16+ } , [ ] )
1517
16- const loadHistory = ( string = "" , nResults = 10 ) => {
17- chrome . history . search ( { text : string , startTime : 0 , maxResults : nResults } , ( history ) => {
18+ const loadHistory = ( string = "" , nResults = 10 ) => {
19+ chrome . history . search ( { text : string , startTime : 0 , maxResults : nResults } , ( history ) => {
1820 setHistory ( history )
1921 } )
2022 }
@@ -23,11 +25,11 @@ export function AppProvider({ children, ...rest }) {
2325 let newTheme = theme === "light" ? "dark" : "light"
2426 document . body . classList . add ( newTheme ) ;
2527 document . body . classList . remove ( theme ) ;
26- chrome . storage . local . set ( { 'theme' : newTheme } ) ;
28+ chrome . storage . local . set ( { 'theme' : newTheme } ) ;
2729 setTheme ( newTheme )
2830 }
2931
30- const options = {
32+ const options = {
3133 history,
3234 loadHistory,
3335 theme,
@@ -38,9 +40,9 @@ export function AppProvider({ children, ...rest }) {
3840 { children }
3941 </ AppContext . Provider >
4042 )
41- }
43+ }
4244
43- export function useApp ( ) {
45+ export function useApp ( ) {
4446 const value = useContext ( AppContext )
4547 return value
4648}
0 commit comments