Post own page

This commit is contained in:
2024-02-06 01:10:22 +08:00
parent d3adb20b0e
commit bbdc8e6aa6
11 changed files with 206 additions and 24 deletions

View File

@@ -2,7 +2,7 @@ import Navbar from "./shared/Navbar.tsx";
import { readProfiles, useUserinfo } from "../stores/userinfo.tsx";
import { createEffect, createMemo, createSignal, Show } from "solid-js";
import { readWellKnown } from "../stores/wellKnown.tsx";
import { BeforeLeaveEventArgs, useBeforeLeave, useLocation, useNavigate, useSearchParams } from "@solidjs/router";
import { BeforeLeaveEventArgs, useLocation, useNavigate, useSearchParams } from "@solidjs/router";
export default function RootLayout(props: any) {
const [ready, setReady] = createSignal(false);
@@ -17,21 +17,19 @@ export default function RootLayout(props: any) {
createEffect(() => {
if (ready()) {
keepGate(location.pathname);
keepGate(location.pathname + location.search);
}
}, [ready, userinfo]);
function keepGate(path: string, e?: BeforeLeaveEventArgs) {
const whitelist = ["/auth", "/auth/callback"];
const blacklist = ["/creator"];
if (!userinfo?.isLoggedIn && !whitelist.includes(path)) {
if (!userinfo?.isLoggedIn && blacklist.includes(path)) {
if (!e?.defaultPrevented) e?.preventDefault();
navigate(`/auth/login?redirect_uri=${path}`);
navigate(`/auth?redirect_uri=${path}`);
}
}
useBeforeLeave((e: BeforeLeaveEventArgs) => keepGate(e.to.toString().split("?")[0], e));
const mainContentStyles = createMemo(() => {
if(!searchParams["noTitle"]) {
return "h-[calc(100vh-64px)] mt-[64px]"