This commit is contained in:
rizrmd 2024-02-14 16:32:18 -07:00
parent 388cedeabe
commit f58ee518c1
4 changed files with 34 additions and 9 deletions

View File

@ -1,9 +1,8 @@
import { useLocal } from "@/utils/use-local"; import { useLocal } from "@/utils/use-local";
import { cx } from "class-variance-authority"; import { cx } from "class-variance-authority";
import { ArrowRight } from "lucide-react";
import { FC, useEffect } from "react"; import { FC, useEffect } from "react";
import { Skeleton } from "../ui/skeleton"; import { Skeleton } from "../ui/skeleton";
import { ArrowRight, ArrowRightCircle, ChevronRight } from "lucide-react";
import { IconRight } from "react-day-picker";
export const Detail: FC<{ export const Detail: FC<{
detail: (item: any) => Record<string, [string, string, string]>; detail: (item: any) => Record<string, [string, string, string]>;
@ -13,14 +12,33 @@ export const Detail: FC<{
const local = useLocal({ const local = useLocal({
status: "init" as "init" | "loading" | "ready", status: "init" as "init" | "loading" | "ready",
detail: null as any, detail: null as any,
pathname: "",
mode: mode,
on_load,
}); });
if (!isEditor) { if (!isEditor) {
if (
location.pathname !== local.pathname ||
mode !== local.mode ||
local.on_load !== on_load
) {
local.status = "init";
local.on_load = on_load;
local.mode = mode;
}
useEffect(() => { useEffect(() => {
if (local.status === "init" && typeof on_load === "function") { if (local.status === "init" && typeof on_load === "function") {
local.status = "loading"; local.status = "loading";
if (location.pathname === "") {
local.detail = detail({}); local.detail = detail({});
} else {
local.detail = detail({});
local.pathname = location.pathname;
}
local.render(); local.render();
const res = on_load({ params: {} }); const res = on_load({ params: {} });
if (typeof res === "object" && res instanceof Promise) { if (typeof res === "object" && res instanceof Promise) {
res.then((item) => { res.then((item) => {
@ -34,7 +52,7 @@ export const Detail: FC<{
local.render(); local.render();
} }
} }
}, [on_load]); }, [local.status]);
} }
let values = {}; let values = {};
@ -121,8 +139,7 @@ export const Detail: FC<{
className={cx( className={cx(
"c-flex c-flex-col c-items-stretch", "c-flex c-flex-col c-items-stretch",
!is_last && `c-border-r c-pr-2 c-mr-2`, !is_last && `c-border-r c-pr-2 c-mr-2`,
!is_first && `c-ml-1`, !is_first && `c-ml-1`
)} )}
> >
<div className={"c-flex c-font-bold"}>{label}</div> <div className={"c-flex c-font-bold"}>{label}</div>
@ -174,6 +191,9 @@ const Linkable: FC<{
mode !== "standard" && "text-sm" mode !== "standard" && "text-sm"
)} )}
onClick={() => { onClick={() => {
if (link.startsWith("http://") || link.startsWith("https://")) {
window.open(link, "_blank");
}
if (!isEditor) { if (!isEditor) {
navigate(link); navigate(link);
} }

View File

@ -9,3 +9,4 @@ export { List } from "@/comps/list/List";
export { Slider } from "@/comps/ui/slider"; export { Slider } from "@/comps/ui/slider";
export { longDate, shortDate } from "@/utils/date"; export { longDate, shortDate } from "@/utils/date";
export { Button } from "@/comps/ui/button"; export { Button } from "@/comps/ui/button";
export { getPathname } from "@/utils/pathname";

1
utils/globals.d.ts vendored
View File

@ -2,6 +2,7 @@ declare var isEditor: boolean;
declare var isMobile: boolean; declare var isMobile: boolean;
declare var isDesktop: boolean; declare var isDesktop: boolean;
declare var css: any; declare var css: any;
declare var params: any;
declare var cx: any; declare var cx: any;
declare var preload: (urls: string[] | string) => any; declare var preload: (urls: string[] | string) => any;
declare var navigate: (link: string) => void; declare var navigate: (link: string) => void;

View File

@ -1,8 +1,11 @@
export const getPathname = () => { export const getPathname = () => {
if (["localhost", "prasi.avolut.com"].includes(location.hostname)) { if (["localhost", "prasi.avolut.com"].includes(location.hostname)) {
if (location.pathname.startsWith("/vi")) { if (
return '/' + location.pathname.split("/").slice(3).join('/'); location.pathname.startsWith("/vi") ||
location.pathname.startsWith("/deploy")
) {
return "/" + location.pathname.split("/").slice(3).join("/");
} }
} }
return location.pathname return location.pathname;
}; };