* Add file save UI and drafts project

* Fix build

* Create SearchList component as abstraction

* Add project page and file tree view

* Create Locale context

* Create Theme context

* Create Version context

* Create Title context

* Create Project context

* Store current file in project context

* Fix issues when renaming file and implement deleting

* Style improvements

* Make all project strings translatable

* Fix z-index
This commit is contained in:
Misode
2022-01-18 01:02:19 +01:00
committed by GitHub
parent cd318dc795
commit c6c52ca41a
39 changed files with 958 additions and 373 deletions

View File

@@ -0,0 +1,41 @@
import type { ComponentChildren } from 'preact'
import { createContext } from 'preact'
import { useCallback, useContext, useEffect, useState } from 'preact/hooks'
import { Analytics } from '../Analytics'
import { Store } from '../Store'
interface Theme {
theme: string,
changeTheme: (theme: string) => unknown,
}
const Theme = createContext<Theme>({
theme: 'dark',
changeTheme: () => {},
})
export function useTheme() {
return useContext(Theme)
}
export function ThemeProvider({ children }: { children: ComponentChildren }) {
const [theme, setTheme] = useState(Store.getTheme())
useEffect(() => {
document.documentElement.setAttribute('data-theme', theme)
}, [theme])
const changeTheme = useCallback((theme: string) => {
Analytics.setTheme(theme)
Store.setTheme(theme)
setTheme(theme)
}, [])
const value: Theme = {
theme,
changeTheme,
}
return <Theme.Provider value={value}>
{children}
</Theme.Provider>
}