This commit is contained in:
Rizky 2023-11-27 16:29:14 +07:00
parent 3429621f3e
commit e29ccb0d46
9 changed files with 83 additions and 16 deletions

View File

@ -2,6 +2,7 @@ import { FC } from "react";
import { EdCompPicker } from "./panel/header/mid/comp-picker";
import { EdPagePicker } from "./panel/header/mid/page-picker";
import { EdMain } from "./panel/main/main";
import { TopBtn } from "./panel/header/top-btn";
export const EdMid: FC<{}> = () => {
return (
@ -11,14 +12,18 @@ export const EdMid: FC<{}> = () => {
"h-[35px] border-b flex p-1 items-stretch text-[12px] justify-between"
)}
>
<div className="flex items-stretch">
<div className="flex items-stretch flex-1 ">
<EdPagePicker />
</div>
<div className="flex items-center">
<div className="flex items-center flex-1 justify-center ">
<EdCompPicker />
</div>
<div className="flex items-stretch justify-end"></div>
<div className="flex items-center flex-1 justify-end">
<TopBtn style="slim" className="font-mono text-[9px]">
PREVIEW
</TopBtn>
</div>
</div>
<EdMain />
</div>

View File

@ -14,7 +14,7 @@ export const EdPagePicker = () => {
};
p.render();
}}
innerClassName="flex items-center justify-center space-x-2"
style="slim"
>
<div
dangerouslySetInnerHTML={{

View File

@ -36,7 +36,7 @@ export const TopBtn = ({
"border border-slate-300 hover:bg-blue-500 hover:border-blue-500 hover:text-white rounded-[2px]",
disabled && "text-slate-400 border border-slate-100",
]
: "px-1 rounded-[2px] hover:bg-blue-400 hover:text-white w-[25px] h-[22px] justify-center",
: "px-1 rounded-[2px] hover:bg-blue-400 hover:text-white min-w-[25px] h-[26px] justify-center",
underlight &&
css`
border-bottom-color: ${underlight};

View File

@ -22,7 +22,7 @@ export const EdPopComp = () => {
compPicker.render = local.render;
useEffect(() => {
// waitUntil(() => local.tree).then(() => {});
local.tree?.openAll();
}, [p.ui.popup.comp.open, compPicker.site_id]);
if (!p.ui.popup.comp.open) return null;

View File

@ -5,7 +5,9 @@ import { CompItem } from "./comp-tree";
export const compPicker = {
site_id: "",
ref: null as any,
tab: "all" as "all" | "trash",
tree: [] as NodeModel<CompItem>[],
trash: [] as NodeModel<CompItem>[],
status: "ready" as "loading" | "ready",
render: () => {},
};
@ -13,6 +15,54 @@ export const compPicker = {
export const reloadCompPicker = async (p: PG) => {
compPicker.status = "loading";
compPicker.site_id = p.site.id;
p.comp.group[p.site.id] = await p.sync.comp.group(p.site.id);
const group = p.comp.group[p.site.id];
compPicker.tree = [];
compPicker.trash = [];
const comp_ids: string[] = [];
let trash_id = "";
for (const [k, v] of Object.entries(group)) {
const tree: NodeModel<CompItem>[] =
v.name !== "__TRASH__" ? compPicker.tree : compPicker.trash;
if (v.name === "__TRASH__") {
trash_id = k;
}
tree.push({
id: k,
parent: "comp-root",
text: v.name,
data: { id: k, name: v.name, type: "folder" },
});
comp_ids.push(k);
}
const comps = await db.component.findMany({
where: { id_component_group: { in: comp_ids } },
select: { id: true, id_component_group: true, name: true },
});
for (const comp of Object.values(comps)) {
if (comp.id_component_group) {
const tree: NodeModel<CompItem>[] =
comp.id_component_group !== trash_id
? compPicker.tree
: compPicker.trash;
tree.push({
id: comp.id,
parent: comp.id_component_group,
text: comp.name,
data: { id: comp.id, name: comp.name, type: "component" },
});
}
}
console.log(compPicker.tree);
compPicker.status = "ready";
compPicker.render();
};

View File

@ -7,7 +7,7 @@ import { compPicker, reloadCompPicker } from "./comp-reload";
export type CompItem = {
id: string;
name: string;
type: "page" | "folder";
type: "component" | "folder";
};
export const edPageTreeRender: NodeRender<CompItem> = (
node: NodeModel<CompItem>,

View File

@ -111,7 +111,11 @@ export const devLoader: Loader = {
const load = async (url: string) => {
const res = await fetch(url);
const text = await res.text();
const json = JSON.parse(text);
return json;
try {
const text = await res.text();
const json = JSON.parse(text);
return json;
} catch (e) {
return null;
}
};

View File

@ -56,7 +56,11 @@ export const mobileLoader: Loader = {
const load = async (url: string) => {
const res = await fetch(`${w.mobilepath}${url}`);
const text = await res.text();
const json = JSON.parse(text);
return json;
try {
const text = await res.text();
const json = JSON.parse(text);
return json;
} catch (e) {
return null;
}
};

View File

@ -49,7 +49,11 @@ export const siteLoader: Loader = {
const load = async (url: string) => {
const res = await fetch(`${base}${url}`);
const text = await res.text();
const json = JSON.parse(text);
return json;
try {
const text = await res.text();
const json = JSON.parse(text);
return json;
} catch (e) {
return null;
}
};