wip fix
This commit is contained in:
parent
a9576969fa
commit
fa46235a3d
|
|
@ -26,7 +26,8 @@ export const loadComponent = async (p: PG, id_comp: string, sync?: boolean) => {
|
||||||
loadcomp.pending.add(id_comp);
|
loadcomp.pending.add(id_comp);
|
||||||
clearTimeout(loadcomp.timeout);
|
clearTimeout(loadcomp.timeout);
|
||||||
loadcomp.timeout = setTimeout(async () => {
|
loadcomp.timeout = setTimeout(async () => {
|
||||||
const comps = await p.sync.comp.load([...loadcomp.pending], sync);
|
const comps = await p.sync?.comp.load([...loadcomp.pending], sync);
|
||||||
|
if (comps) {
|
||||||
let result = Object.entries(comps);
|
let result = Object.entries(comps);
|
||||||
|
|
||||||
for (const [id_comp, comp] of result) {
|
for (const [id_comp, comp] of result) {
|
||||||
|
|
@ -36,6 +37,9 @@ export const loadComponent = async (p: PG, id_comp: string, sync?: boolean) => {
|
||||||
}
|
}
|
||||||
loadcomp.pending.clear();
|
loadcomp.pending.clear();
|
||||||
resolve(result.length > 0);
|
resolve(result.length > 0);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
}, 150);
|
}, 150);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -73,7 +77,7 @@ export const loadCompSnapshot = async (
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await p.sync.yjs.sv_local(
|
const res = await p.sync?.yjs.sv_local(
|
||||||
"comp",
|
"comp",
|
||||||
comp_id,
|
comp_id,
|
||||||
Buffer.from(compress(bin))
|
Buffer.from(compress(bin))
|
||||||
|
|
@ -86,7 +90,7 @@ export const loadCompSnapshot = async (
|
||||||
);
|
);
|
||||||
Y.applyUpdate(doc as any, decompress(res.diff), "local");
|
Y.applyUpdate(doc as any, decompress(res.diff), "local");
|
||||||
|
|
||||||
await p.sync.yjs.diff_local(
|
await p.sync?.yjs.diff_local(
|
||||||
"comp",
|
"comp",
|
||||||
comp_id,
|
comp_id,
|
||||||
Buffer.from(compress(diff_local))
|
Buffer.from(compress(diff_local))
|
||||||
|
|
@ -144,7 +148,8 @@ export const updateComponentMeta = async (
|
||||||
{
|
{
|
||||||
load: async (comp_ids: string[]) => {
|
load: async (comp_ids: string[]) => {
|
||||||
const ids = comp_ids.filter((id) => !p.comp.loaded[id]);
|
const ids = comp_ids.filter((id) => !p.comp.loaded[id]);
|
||||||
const comps = await p.sync.comp.load(ids, true);
|
const comps = await p.sync?.comp.load(ids, true);
|
||||||
|
if (comps) {
|
||||||
let result = Object.entries(comps);
|
let result = Object.entries(comps);
|
||||||
|
|
||||||
for (const [id_comp, comp] of result) {
|
for (const [id_comp, comp] of result) {
|
||||||
|
|
@ -152,6 +157,7 @@ export const updateComponentMeta = async (
|
||||||
await loadCompSnapshot(p, id_comp, comp.snapshot);
|
await loadCompSnapshot(p, id_comp, comp.snapshot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,12 @@ export const reloadPage = async (
|
||||||
page.on_update = async (bin: Uint8Array, origin: any) => {
|
page.on_update = async (bin: Uint8Array, origin: any) => {
|
||||||
if (origin === "local" || !p.sync) return;
|
if (origin === "local" || !p.sync) return;
|
||||||
|
|
||||||
|
if (page.page.id !== remotePage.id) {
|
||||||
|
alert("Page ID Mismatch!\n Refreshing to preventing data loss...");
|
||||||
|
location.reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const res = await p.sync.yjs.sv_local(
|
const res = await p.sync.yjs.sv_local(
|
||||||
"page",
|
"page",
|
||||||
p.page.cur.id,
|
p.page.cur.id,
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@ import { PG } from "../../ed/logic/ed-global";
|
||||||
import { evalCJS } from "../../ed/logic/ed-sync";
|
import { evalCJS } from "../../ed/logic/ed-sync";
|
||||||
import { treeRebuild } from "../../ed/logic/tree/build";
|
import { treeRebuild } from "../../ed/logic/tree/build";
|
||||||
|
|
||||||
const decoder = new TextDecoder();
|
|
||||||
|
|
||||||
export const viLoadSnapshot = async (p: PG) => {
|
export const viLoadSnapshot = async (p: PG) => {
|
||||||
let api_url = p.site.config.api_url;
|
let api_url = p.site.config.api_url;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -210,6 +210,20 @@ const viRoute = async (p: PG) => {
|
||||||
if (preview.first_render) {
|
if (preview.first_render) {
|
||||||
preview.first_render = false;
|
preview.first_render = false;
|
||||||
} else {
|
} else {
|
||||||
|
if (p.page.doc) {
|
||||||
|
let page = p.page.list[params.page_id];
|
||||||
|
if (!page) {
|
||||||
|
p.page.list[params.page_id] = {} as any;
|
||||||
|
page = p.page.list[params.page_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page && page.on_update) {
|
||||||
|
page.doc.off("update", page.on_update);
|
||||||
|
page.doc.destroy();
|
||||||
|
delete p.page.list[params.page_id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let page_cache = p.preview.meta_cache[params.page_id];
|
let page_cache = p.preview.meta_cache[params.page_id];
|
||||||
|
|
||||||
let should_render = false;
|
let should_render = false;
|
||||||
|
|
@ -231,7 +245,6 @@ const viRoute = async (p: PG) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.status = "ready";
|
p.status = "ready";
|
||||||
p.sync.page.load(params.page_id);
|
|
||||||
if (should_render) p.render();
|
if (should_render) p.render();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue