added udner construction for file compaction, planning for unbloating
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { type ReactNode, useEffect, useState } from "react";
|
||||
import { Navigate, useLocation } from "react-router-dom";
|
||||
import { getSiteAccessStatus } from "../api/siteAccess";
|
||||
|
||||
const STORAGE_KEY = "skymoney_beta_access";
|
||||
|
||||
@@ -10,16 +11,43 @@ type Props = {
|
||||
export function BetaGate({ children }: Props) {
|
||||
const location = useLocation();
|
||||
const [hasAccess, setHasAccess] = useState<boolean | null>(null);
|
||||
const [isEnabled, setIsEnabled] = useState<boolean | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setHasAccess(localStorage.getItem(STORAGE_KEY) === "true");
|
||||
let cancelled = false;
|
||||
(async () => {
|
||||
try {
|
||||
const status = await getSiteAccessStatus();
|
||||
const unlocked = !!status.unlocked;
|
||||
if (!cancelled) {
|
||||
setIsEnabled(!!status.enabled);
|
||||
setHasAccess(!status.enabled || unlocked);
|
||||
}
|
||||
if (status.enabled && unlocked) {
|
||||
localStorage.setItem(STORAGE_KEY, "true");
|
||||
}
|
||||
if (status.enabled && !unlocked) {
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
}
|
||||
} catch {
|
||||
// Fallback for temporary API/network issues.
|
||||
const localFallback = localStorage.getItem(STORAGE_KEY) === "true";
|
||||
if (!cancelled) {
|
||||
setIsEnabled(true);
|
||||
setHasAccess(localFallback);
|
||||
}
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (location.pathname === "/beta") {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
if (hasAccess === null) {
|
||||
if (hasAccess === null || isEnabled === null) {
|
||||
return (
|
||||
<div className="flex min-h-[40vh] items-center justify-center text-sm muted">
|
||||
Checking access…
|
||||
@@ -27,7 +55,7 @@ export function BetaGate({ children }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
if (!hasAccess) {
|
||||
if (isEnabled && !hasAccess) {
|
||||
return <Navigate to="/beta" replace />;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user