wip load code
This commit is contained in:
parent
3ab768d3c7
commit
212c8686f1
|
|
@ -302,7 +302,7 @@ model code_assign {
|
|||
id_component_group String? @db.Uuid
|
||||
id_page String? @db.Uuid
|
||||
id String @id(map: "code_assign_id") @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
code code @relation(fields: [id_code], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||
code code @relation(fields: [id_code], references: [id], onDelete: Cascade, onUpdate: NoAction)
|
||||
component_group component_group? @relation(fields: [id_component_group], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||
page page? @relation(fields: [id_page], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { w } from "../../../utils/types/general";
|
|||
import { Loading } from "../../../utils/ui/loading";
|
||||
import { EmptySite, PG } from "./ed-global";
|
||||
import { treeRebuild } from "./tree/build";
|
||||
import { evalCJS } from "../../view/logic/load-code";
|
||||
import { evalCJS } from "../../view/logic/load-code-new";
|
||||
import { reloadPage } from "./ed-route";
|
||||
import { loadSite } from "./ed-site";
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { View } from "../../../view/view";
|
|||
import { EDGlobal, active } from "../../logic/ed-global";
|
||||
import { compLoaded } from "../../logic/tree/build";
|
||||
import { loadComponent } from "../../logic/tree/sync-walk";
|
||||
import { code } from "../popup/code/code";
|
||||
|
||||
export const EdMain = () => {
|
||||
const p = useGlobal(EDGlobal, "EDITOR");
|
||||
|
|
@ -18,9 +19,10 @@ export const EdMain = () => {
|
|||
>
|
||||
<div className="absolute overflow-auto inset-0">
|
||||
{!!p.page.building && <Loading backdrop={false} />}
|
||||
{!p.page.building && (
|
||||
{!p.page.building && code.mode !== "" && (
|
||||
<View
|
||||
mode={p.mode}
|
||||
code_mode={code.mode}
|
||||
layout={{ show: false }}
|
||||
isEditor={true}
|
||||
api_url={p.site.config.api_url}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,16 @@ import {
|
|||
} from "./icons";
|
||||
import { CodeNameItem, CodeNameList, codeName } from "./name-list";
|
||||
|
||||
export const code = {
|
||||
mode: "" as "" | "old" | "new",
|
||||
};
|
||||
|
||||
export const EdPopCode = () => {
|
||||
const p = useGlobal(EDGlobal, "EDITOR");
|
||||
const local = useLocal({ namePicker: false, codeAssign: false });
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (code.mode === "new") {
|
||||
if (p.ui.popup.code.open) {
|
||||
const id_code = await p.sync.activity("site", {
|
||||
action: p.ui.popup.code.open ? "open" : "close",
|
||||
|
|
@ -36,12 +40,18 @@ export const EdPopCode = () => {
|
|||
}
|
||||
}
|
||||
p.ui.popup.code.init = true;
|
||||
}
|
||||
})();
|
||||
}, [p.ui.popup.code.open]);
|
||||
|
||||
const vscode_url = isLocalhost()
|
||||
? "http://localhost:3000?"
|
||||
: "https://code.web.andromedia.co.id?tkn=prasi&";
|
||||
useEffect(() => {
|
||||
if (code.mode === "") {
|
||||
db.code.findFirst({ where: { id_site: p.site.id } }).then((e) => {
|
||||
code.mode = !!e ? "new" : "old";
|
||||
p.render();
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
|
@ -54,7 +64,49 @@ export const EdPopCode = () => {
|
|||
}
|
||||
}}
|
||||
>
|
||||
<div className={cx("bg-white select-none fixed inset-[50px] bottom-0")}>
|
||||
<div
|
||||
className={cx("bg-white select-none fixed inset-[50px] bottom-0 flex")}
|
||||
>
|
||||
{!code.mode && <Loading note="checking-version" backdrop={false} />}
|
||||
{code.mode === "new" && <CodeBody />}
|
||||
{code.mode === "old" && (
|
||||
<div className="flex items-center justify-center flex-col flex-1">
|
||||
<div>This site still using old code</div>
|
||||
<div
|
||||
onClick={() => {
|
||||
if (
|
||||
confirm(
|
||||
"Old code will not load, are you sure want to upgrade ?"
|
||||
)
|
||||
) {
|
||||
code.mode = "new";
|
||||
p.ui.popup.code.open = false;
|
||||
p.render();
|
||||
}
|
||||
}}
|
||||
className="border border-blue-500 cursor-pointer bg-blue-100 p-2 hover:bg-blue-200"
|
||||
>
|
||||
Upgrade to New Code Project
|
||||
</div>
|
||||
<div className="text-xs py-2">
|
||||
Warning: old code will not load once upgraded.
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
const CodeBody = () => {
|
||||
const p = useGlobal(EDGlobal, "EDITOR");
|
||||
const local = useLocal({ namePicker: false, codeAssign: false });
|
||||
|
||||
const vscode_url = isLocalhost()
|
||||
? "http://localhost:3000?"
|
||||
: "https://code.web.andromedia.co.id?tkn=prasi&";
|
||||
|
||||
return (
|
||||
<div className="relative w-full h-full flex flex-col">
|
||||
<div className="border-b flex h-[40px] items-stretch">
|
||||
<Popover
|
||||
|
|
@ -105,8 +157,7 @@ export const EdPopCode = () => {
|
|||
></div>
|
||||
</Popover>
|
||||
|
||||
{p.ui.popup.code.name !== "site" &&
|
||||
p.ui.popup.code.name !== "SSR" && (
|
||||
{p.ui.popup.code.name !== "site" && p.ui.popup.code.name !== "SSR" && (
|
||||
<>
|
||||
<Tooltip
|
||||
content={"Delete Code Module"}
|
||||
|
|
@ -228,7 +279,5 @@ export const EdPopCode = () => {
|
|||
></div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { NodeModel, RenderParams } from "@minoru/react-dnd-treeview";
|
||||
import { EDGlobal, EdMeta } from "../../../../logic/ed-global";
|
||||
import { useGlobal, useLocal } from "web-utils";
|
||||
import { FC, useEffect } from "react";
|
||||
import { Tooltip } from "../../../../../../utils/ui/tooltip";
|
||||
import { useGlobal, useLocal } from "web-utils";
|
||||
import { EDGlobal, EdMeta } from "../../../../logic/ed-global";
|
||||
|
||||
export const EdTreeName = ({
|
||||
node,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const codeMap = {
|
|||
compGroup: {} as Record<string, string[]>,
|
||||
comp: {} as Record<string, string>,
|
||||
};
|
||||
export const vLoadCode = async (v: VG, forceLoad?: boolean) => {
|
||||
export const newLoadCode = async (v: VG, forceLoad?: boolean) => {
|
||||
if (forceLoad) {
|
||||
codeLoaded.clear();
|
||||
v.status = "load-code";
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import { VG } from "./global";
|
||||
|
||||
export const oldLoadCode = (v: VG) => {};
|
||||
|
|
@ -4,11 +4,12 @@ import { IContent } from "../../utils/types/general";
|
|||
import { Loading } from "../../utils/ui/loading";
|
||||
import { ViewGlobal } from "./logic/global";
|
||||
import { vInit } from "./logic/init";
|
||||
import { vLoadCode } from "./logic/load-code";
|
||||
import { newLoadCode } from "./logic/load-code-new";
|
||||
import { VLoad, VLoadComponent } from "./logic/types";
|
||||
import { VEntry } from "./render/entry";
|
||||
import { ErrorBox } from "./render/meta/script/error-box";
|
||||
import { IRoot } from "../../utils/types/root";
|
||||
import { oldLoadCode } from "./logic/load-code-old";
|
||||
|
||||
type ViewProp = {
|
||||
load: VLoad;
|
||||
|
|
@ -17,6 +18,7 @@ type ViewProp = {
|
|||
page_id: string;
|
||||
api_url: string;
|
||||
mode: "desktop" | "mobile";
|
||||
code_mode?: "old" | "new";
|
||||
layout?: { show: boolean };
|
||||
isEditor?: boolean;
|
||||
bind?: (arg: { render: () => void }) => void;
|
||||
|
|
@ -41,6 +43,7 @@ const BoxedView: FC<ViewProp> = ({
|
|||
layout,
|
||||
page_id,
|
||||
bind,
|
||||
code_mode,
|
||||
hover,
|
||||
active,
|
||||
hidden,
|
||||
|
|
@ -79,7 +82,11 @@ const BoxedView: FC<ViewProp> = ({
|
|||
}
|
||||
|
||||
if (v.status === "load-code" || v.status === "loading-code") {
|
||||
vLoadCode(v);
|
||||
if (!code_mode || code_mode === "new") {
|
||||
newLoadCode(v);
|
||||
} else {
|
||||
oldLoadCode(v);
|
||||
}
|
||||
if (v.status === "load-code" || v.status === "loading-code") {
|
||||
return (
|
||||
<>
|
||||
|
|
|
|||
Loading…
Reference in New Issue