mirror of
https://github.com/jaywcjlove/wxmp.git
synced 2026-01-12 16:28:48 +08:00
feat: add electron app.
This commit is contained in:
47
website/src/store/Provider.tsx
Normal file
47
website/src/store/Provider.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { PreviewThemeValue, previewThemes, ThemeValue, Context, markdownString } from './context';
|
||||
import { useMdSource } from './getMdSource';
|
||||
|
||||
export const Provider: React.FC<React.PropsWithChildren> = ({ children }) => {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const paramPreviewTheme = searchParams.get('theme') as PreviewThemeValue;
|
||||
const initPreviewTheme = paramPreviewTheme || 'underscore';
|
||||
const mdurl = searchParams.get('md');
|
||||
const [markdown, setMarkdown] = React.useState<string>(mdurl ? '' : markdownString);
|
||||
const [css, setCss] = React.useState<string>(previewThemes[initPreviewTheme].value);
|
||||
const [previewTheme, setPreviewTheme] = React.useState<PreviewThemeValue>(initPreviewTheme);
|
||||
const [theme, setTheme] = React.useState<ThemeValue>('default');
|
||||
const [isLoading, setIsLoading] = React.useState<boolean>(true);
|
||||
const { data: mddata, isLoading: loading } = useMdSource(mdurl);
|
||||
useEffect(() => {
|
||||
if (paramPreviewTheme !== previewTheme) {
|
||||
searchParams.set('theme', previewTheme);
|
||||
setSearchParams(searchParams);
|
||||
}
|
||||
}, [paramPreviewTheme, previewTheme, searchParams, setSearchParams]);
|
||||
useEffect(() => {
|
||||
if (mdurl) {
|
||||
setMarkdown(mddata || '');
|
||||
}
|
||||
}, [mddata, mdurl]);
|
||||
useEffect(() => setIsLoading(loading), [loading]);
|
||||
return (
|
||||
<Context.Provider
|
||||
value={{
|
||||
isLoading,
|
||||
setIsLoading,
|
||||
markdown,
|
||||
setMarkdown,
|
||||
css,
|
||||
setCss,
|
||||
previewTheme,
|
||||
setPreviewTheme,
|
||||
theme,
|
||||
setTheme,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Context.Provider>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user