This commit is contained in:
Rizky 2024-01-24 06:01:04 +07:00
parent 669ed3112c
commit 2f74afcd30
5 changed files with 33 additions and 24 deletions

View File

@ -35,6 +35,7 @@ export const EdMain = () => {
local.cache = (
<Vi
meta={p.page.meta}
mode={p.mode}
api_url={p.site.config.api_url}
site_id={p.site.id}
page_id={p.page.cur.id}

View File

@ -82,6 +82,7 @@ export const ViPreview = (arg: { pathname: string }) => {
>
<Vi
meta={p.page.meta}
mode={p.mode}
api_url={p.site.config.api_url}
site_id={p.site.id}
page_id={p.page.cur.id}

View File

@ -4,26 +4,27 @@ import { viParts } from "./parts";
type ViStatus = "init" | "loading" | "ready";
export const ViGlobal = {
ts: 0,
status: "init" as ViStatus,
meta: {} as Record<string, IMeta>,
tick: 0,
site: {
id: "",
api_url: "",
api: null as any,
db: null as any,
code: {
mode: "old" as "old" | "vsc",
},
},
script: {
init_local_effect: undefined as undefined | Record<string, boolean>,
},
visit: undefined as
| undefined
| ((meta: IMeta, parts: ReturnType<typeof viParts>) => void),
on_status_changes: undefined as void | ((status: ViStatus) => void),
ts: 0,
status: "init" as ViStatus,
meta: {} as Record<string, IMeta>,
tick: 0,
mode: "desktop" as "mobile" | "desktop",
site: {
id: "",
api_url: "",
api: null as any,
db: null as any,
code: {
mode: "old" as "old" | "vsc",
},
},
script: {
init_local_effect: undefined as undefined | Record<string, boolean>,
},
visit: undefined as
| undefined
| ((meta: IMeta, parts: ReturnType<typeof viParts>) => void),
on_status_changes: undefined as void | ((status: ViStatus) => void),
};
export type VG = typeof ViGlobal & { render: () => void };

View File

@ -1,5 +1,8 @@
export const viScriptArg = (vi: { site: { db: any; api: any } }) => ({
isMobile: false,
isDesktop: true,
isEditor: true,
export const viScriptArg = (vi: {
mode: "mobile" | "desktop";
site: { db: any; api: any };
}) => ({
isMobile: vi.mode === "mobile",
isDesktop: vi.mode === "desktop",
isEditor: location.pathname.startsWith("/ed/"),
});

View File

@ -9,6 +9,7 @@ import { render_stat } from "./render/render";
export const Vi: FC<{
meta: Record<string, IMeta>;
mode: "mobile" | "desktop";
comp_load?: (comp_id: string) => Promise<void>;
entry: string[];
api_url: string;
@ -26,6 +27,7 @@ export const Vi: FC<{
api_url,
site_id,
api,
mode,
db,
visit,
script,
@ -33,6 +35,7 @@ export const Vi: FC<{
on_status_changed,
}) => {
const vi = useGlobal(ViGlobal, "VI");
vi.mode = mode;
vi.on_status_changes = on_status_changed;
if (rs === "disabled") {