import { atom, useAtom } from "jotai"; import { atomWithStorage } from "jotai/utils"; import { useEffect } from "react"; import { lazy } from "react"; import { DengiCaching } from "./trash/dengiCashingSystem"; import { ifstyle } from "./trash/helpers"; import { LoginPage } from "./pages/LoginPage"; import { DX4App } from "./pages/DX4AppPage"; export const API_BASE_URL = "http://192.168.3.10:8321/api.php"; const classIDAtom = atomWithStorage("class-id", ""); const adminAtom = atomWithStorage("admin-id", ""); const pickmeModeAtom = atomWithStorage("pickmeMode", false); const EditorPage = lazy(() => import("./pages/editor")); const TestPage = lazy(() => import("./pages/test")); const dengi_cash = new DengiCaching(); // KATAMAZ DENGI ROUTER 4 PRO MAX ULTIMATE // 💀💀 // PROS - vrode raboatat, // too simple, lightweight, stupidly fast // (beacause you basicly download entire site, lol) // CONS - shit function firstPathSegment(path) { const m = path.match(/^\/?([^/]+)/); return m ? m[1] : ""; } const secondPathSegment = (p) => p.replace(/^\/?[^/]+/, "").replace(/^\/+/, ""); const routeAtom = atom("/"); const basePageProps = { // atoms classIDAtom, adminAtom, routeAtom, // fucntions setsetRoute, secondPathSegment, ifstyle, // constants API_BASE_URL, // caching dengi_cash, // etc pickmeModeAtom, // <3 }; const pages = { "/": , "/app": , "/exit": , "/editor": , "/test": , }; let changeAnchor = true; let defaultAnchor = document.location.hash.substring(1); // lol 💀 function setsetRoute(setRoute, path) { changeAnchor = true; setRoute(path); document.location.hash = path; } export default function DX4() { const [route, _setRoute] = useAtom(routeAtom); useEffect(() => { if ( document.location.hash && document.location.hash.substring(1) !== route ) { _setRoute(document.location.hash.substring(1)); } window.addEventListener("load", () => { if (defaultAnchor == "" || defaultAnchor == "/") { document.location.hash = defaultAnchor; } }); }, [route, _setRoute]); window.addEventListener("hashchange", () => { if (document.location.hash == "") { document.location.hash = "/"; } if (changeAnchor) { changeAnchor = false; return; } _setRoute(document.location.hash.substring(1)); }); const page = Object.entries(pages).find( ([key]) => firstPathSegment(key) == firstPathSegment(route) ); return ( (page ? page[1] : false) || ||
some shit happened
); } export function ERROR404() { const route = useAtom(routeAtom)[0]; return (
404((((
{route}
); } export function ExitPage() { const [_userId, setUserId] = useAtom(classIDAtom); const setRoute = useAtom(routeAtom)[1]; return (
); }