* 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,54 @@
import type { ComponentChildren } from 'preact'
import { createContext } from 'preact'
import { getCurrentUrl } from 'preact-router'
import { useCallback, useContext, useEffect, useState } from 'preact/hooks'
import { Analytics } from '../Analytics'
import type { VersionId } from '../services'
import { VersionIds } from '../services'
import { Store } from '../Store'
import { getSearchParams, setSeachParams } from '../Utils'
const VERSION_PARAM = 'version'
interface Version {
version: VersionId,
changeVersion: (version: VersionId) => unknown,
}
const Version = createContext<Version>({
version: '1.18',
changeVersion: () => {},
})
export function useVersion() {
return useContext(Version)
}
export function VersionProvider({ children }: { children: ComponentChildren }) {
const [version, setVersion] = useState<VersionId>(Store.getVersion())
const searchParams = getSearchParams(getCurrentUrl())
const targetVersion = searchParams.get(VERSION_PARAM)
useEffect(() => {
if (VersionIds.includes(targetVersion as VersionId) && version !== targetVersion) {
setVersion(targetVersion as VersionId)
}
}, [version, targetVersion])
const changeVersion = useCallback((version: VersionId) => {
if (getSearchParams(getCurrentUrl()).has(VERSION_PARAM)) {
setSeachParams({ version })
}
Analytics.setVersion(version)
Store.setVersion(version)
setVersion(version)
}, [])
const value: Version = {
version,
changeVersion,
}
return <Version.Provider value={value}>
{children}
</Version.Provider>
}