add param to URL
This commit is contained in:
1 parent
c71c833b77
commit
42aae20fa3
2 files changed
+16
-3
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import { BasePage, BaseFallback } from "@/Components/design-elements";
|
import { BasePage, BaseFallback } from "@/Components/design-elements";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import { Link } from "react-router-dom";
|
import { Link, useSearchParams } from "react-router-dom";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
|
|
||||||
@@ -9,7 +9,12 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { useIsAdmin } from "@/Hooks/useIsAdmin";
|
import { useIsAdmin } from "@/Hooks/useIsAdmin";
|
||||||
import { useLocation, useParams } from "react-router-dom";
|
import { useLocation, useParams } from "react-router-dom";
|
||||||
import { useGet } from "@/Hooks/UseApi";
|
import { useGet } from "@/Hooks/UseApi";
|
||||||
import { resolveStatusPageTheme } from "@/Types/StatusPage";
|
import {
|
||||||
|
isStatusPageRange,
|
||||||
|
resolveStatusPageTheme,
|
||||||
|
STATUS_PAGE_RANGES,
|
||||||
|
type StatusPageRange,
|
||||||
|
} from "@/Types/StatusPage";
|
||||||
import {
|
import {
|
||||||
PUBLIC_STATUS_PAGE_PREFIX,
|
PUBLIC_STATUS_PAGE_PREFIX,
|
||||||
type StatusPageResponse,
|
type StatusPageResponse,
|
||||||
@@ -80,21 +85,26 @@ const StatusPageView = () => {
|
|||||||
const { url } = useParams();
|
const { url } = useParams();
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
|
|
||||||
const onCustomDomainHost = isCustomDomainHost();
|
const onCustomDomainHost = isCustomDomainHost();
|
||||||
const isPublic =
|
const isPublic =
|
||||||
onCustomDomainHost || location.pathname.startsWith(PUBLIC_STATUS_PAGE_PREFIX);
|
onCustomDomainHost || location.pathname.startsWith(PUBLIC_STATUS_PAGE_PREFIX);
|
||||||
|
|
||||||
|
const rawRange = searchParams.get("range");
|
||||||
|
const range = isStatusPageRange(rawRange) ? rawRange : "latest";
|
||||||
|
|
||||||
const apiUrl = buildStatusPageApiPath({
|
const apiUrl = buildStatusPageApiPath({
|
||||||
url,
|
url,
|
||||||
useCustomDomain: onCustomDomainHost,
|
useCustomDomain: onCustomDomainHost,
|
||||||
|
range,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data, isLoading, error } = useGet<StatusPageResponse>(
|
const { data, isLoading, error } = useGet<StatusPageResponse>(
|
||||||
apiUrl,
|
apiUrl,
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
refreshInterval: 10000,
|
refreshInterval: range === "latest" ? 10000 : 60000,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ export const STATUS_PAGE_RANGE_DAYS: Record<
|
|||||||
number
|
number
|
||||||
> = { "30d": 30, "60d": 60, "90d": 90 };
|
> = { "30d": 30, "60d": 60, "90d": 90 };
|
||||||
|
|
||||||
|
export const isStatusPageRange = (value: string | null): value is StatusPageRange =>
|
||||||
|
STATUS_PAGE_RANGES.some((range) => range === value);
|
||||||
|
|
||||||
export const resolveStatusPageTheme = (
|
export const resolveStatusPageTheme = (
|
||||||
value: string | null | undefined
|
value: string | null | undefined
|
||||||
): StatusPageTheme =>
|
): StatusPageTheme =>
|
||||||
|
|||||||
Reference in new issue
Block a user