|
@@ -6,6 +6,9 @@ import {
|
|
|
useConfigReducer,
|
|
|
} from "src/reducer/reducer";
|
|
|
import { ReactComponent, StorageConfig } from "src/typings/global";
|
|
|
+import { isValidJson } from "src/utils/isValidJson";
|
|
|
+import { useRouter } from "next/router";
|
|
|
+import { decode } from "js-base64";
|
|
|
|
|
|
export interface AppConfig {
|
|
|
json: string;
|
|
@@ -42,9 +45,16 @@ const WithConfig: ReactComponent = ({ children }) => {
|
|
|
settings: states.settings,
|
|
|
};
|
|
|
|
|
|
+ const router = useRouter();
|
|
|
+ const { json } = router.query;
|
|
|
+
|
|
|
React.useEffect(() => {
|
|
|
const jsonStored = localStorage.getItem("json");
|
|
|
- if (jsonStored) {
|
|
|
+ const jsonDecode = decode(String(json));
|
|
|
+
|
|
|
+ if (isValidJson(jsonDecode)) {
|
|
|
+ dispatch({ type: ConfigActionType.SET_JSON, payload: jsonDecode });
|
|
|
+ } else if (jsonStored) {
|
|
|
dispatch({ type: ConfigActionType.SET_JSON, payload: jsonStored });
|
|
|
}
|
|
|
|
|
@@ -57,7 +67,7 @@ const WithConfig: ReactComponent = ({ children }) => {
|
|
|
}
|
|
|
|
|
|
setRender(true);
|
|
|
- }, [dispatch]);
|
|
|
+ }, [dispatch, json]);
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
if (render)
|