Refactor + add message box.

This commit is contained in:
Paul
2021-06-20 20:30:42 +01:00
parent b8fba749af
commit 9e460c5b3d
28 changed files with 225 additions and 120 deletions

View File

@@ -1,12 +1,12 @@
import { ReactNode } from "react";
import { useContext } from "preact/hooks";
import { Redirect } from "react-router-dom";
import { Children } from "../../types/Preact";
import { OperationsContext } from "./RevoltClient";
interface Props {
auth?: boolean;
children: ReactNode | ReactNode[];
children: Children;
}
export const CheckAuth = (props: Props) => {

View File

@@ -11,8 +11,17 @@ export interface HookContext {
export function useForceUpdate(context?: HookContext): HookContext {
const client = useContext(AppContext);
if (context) return context;
const [, updateState] = useState({});
return { client, forceUpdate: useCallback(() => updateState({}), []) };
const H = useState(undefined);
var updateState: (_: undefined) => void;
if (Array.isArray(H)) {
let [, u] = H;
updateState = u;
} else {
console.warn('Failed to construct using useState.');
console.warn(H);
updateState = ()=>{};
}
return { client, forceUpdate: useCallback(() => updateState(undefined), []) };
}
function useObject(type: string, id?: string | string[], context?: HookContext) {