/* Copyright 2021, vite-plugin-book by Mirone. */ import { createContext, Dispatch, FC, SetStateAction, useContext, useState } from 'react'; import { nope } from '../utils/helper'; import { RouteBaseCtx } from './RouteBaseProvider'; export const FileCtx = createContext(''); export const SetFileCtx = createContext>>(nope); export const UrlCtx = createContext(''); export const SetUrlCtx = createContext>>(nope); export const LoadingCtx = createContext(false); export const SetLoadingCtx = createContext>>(nope); export const ChangedCtx = createContext(false); export const SetChangedCtx = createContext>>(nope); export const FileProvider: FC = ({ children }) => { const base = useContext(RouteBaseCtx); const pureBase = window.location.pathname.replace(base, ''); const [file, setFile] = useState(''); const [url, setUrl] = useState(pureBase.length === 0 ? '/' : pureBase); const [changed, setChanged] = useState(false); const [loading, setLoading] = useState(false); return ( {children} ); };