fix
This commit is contained in:
parent
1d0957ee1d
commit
d0e6137f6b
File diff suppressed because one or more lines are too long
|
|
@ -95,7 +95,7 @@ export const initFrontEnd = async (
|
||||||
filename?.endsWith(".css") ||
|
filename?.endsWith(".css") ||
|
||||||
filename?.endsWith(".html")
|
filename?.endsWith(".html")
|
||||||
) {
|
) {
|
||||||
console.log(filename);
|
console.log(filename);
|
||||||
|
|
||||||
if (typeof fe !== "undefined" && !fe.rebuilding) {
|
if (typeof fe !== "undefined" && !fe.rebuilding) {
|
||||||
fe.rebuilding = true;
|
fe.rebuilding = true;
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import { EdPopSite } from "./panel/popup/site/site-popup";
|
||||||
import { iconVSCode } from "./panel/popup/code/icons";
|
import { iconVSCode } from "./panel/popup/code/icons";
|
||||||
import { isLocalhost } from "../../utils/ui/is-localhost";
|
import { isLocalhost } from "../../utils/ui/is-localhost";
|
||||||
import { w } from "../../utils/types/general";
|
import { w } from "../../utils/types/general";
|
||||||
|
import { edInitSync } from "./logic/ed-sync";
|
||||||
|
|
||||||
export const EdBase = () => {
|
export const EdBase = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
|
|
@ -170,6 +171,37 @@ export const EdBase = () => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{w.sync_too_long && (
|
||||||
|
<div
|
||||||
|
className={cx(
|
||||||
|
css`
|
||||||
|
position: fixed;
|
||||||
|
bottom: 20px;
|
||||||
|
left: 0px;
|
||||||
|
right: 0px;
|
||||||
|
z-index: 999;
|
||||||
|
`,
|
||||||
|
"flex justify-center cursor-pointer"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className="space-x-2 flex bg-red-100 text-red-700 px-4 py-2 rounded-full text-sm">
|
||||||
|
<div>Sync taking too long...</div>
|
||||||
|
<div
|
||||||
|
className={cx(
|
||||||
|
css`
|
||||||
|
background: white;
|
||||||
|
`,
|
||||||
|
"rounded-full px-3 cursor-pointer border border-red-500"
|
||||||
|
)}
|
||||||
|
onClick={() => {
|
||||||
|
location.reload();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Reload Page
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -160,8 +160,7 @@ export const EDGlobal = {
|
||||||
{ entry: string[]; meta: Record<string, IMeta>; url: string }
|
{ entry: string[]; meta: Record<string, IMeta>; url: string }
|
||||||
>,
|
>,
|
||||||
},
|
},
|
||||||
sync: null as null | Awaited<ReturnType<typeof clientStartSync>>,
|
sync: undefined as undefined | Awaited<ReturnType<typeof clientStartSync>>,
|
||||||
sync_assigned: false,
|
|
||||||
site: deepClone(EmptySite),
|
site: deepClone(EmptySite),
|
||||||
site_tstamp: Date.now(),
|
site_tstamp: Date.now(),
|
||||||
site_exports: {} as Record<string, any>,
|
site_exports: {} as Record<string, any>,
|
||||||
|
|
|
||||||
|
|
@ -41,51 +41,6 @@ export const loadSession = (p: PG) => {
|
||||||
|
|
||||||
export const edInitSync = (p: PG) => {
|
export const edInitSync = (p: PG) => {
|
||||||
loadSession(p);
|
loadSession(p);
|
||||||
if (location.pathname.startsWith("/vi/")) {
|
|
||||||
if (page.list.length === 0) {
|
|
||||||
_db.page
|
|
||||||
.findMany({
|
|
||||||
where: {
|
|
||||||
id_site: params.site_id,
|
|
||||||
is_deleted: false,
|
|
||||||
is_default_layout: false,
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
url: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then((list) => {
|
|
||||||
page.list = list;
|
|
||||||
edInitSync(p);
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!page.route) {
|
|
||||||
page.route = createRouter();
|
|
||||||
for (const e of page.list) {
|
|
||||||
page.route.insert(e.url, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const arrpath = location.pathname.split("/");
|
|
||||||
const pathname = "/" + arrpath.slice(3).join("/");
|
|
||||||
|
|
||||||
if (!params.page_id) {
|
|
||||||
const res = page.route.lookup(pathname);
|
|
||||||
if (res) {
|
|
||||||
params.page_id = res.id;
|
|
||||||
if (res.params) {
|
|
||||||
for (const [k, v] of Object.entries(res.params)) {
|
|
||||||
if (!["site_id", "page_id"].includes(k)) {
|
|
||||||
params[k] = v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p.sync) {
|
if (p.sync) {
|
||||||
if (p.site.id === "--loading--") return false;
|
if (p.site.id === "--loading--") return false;
|
||||||
|
|
@ -131,8 +86,7 @@ export const edInitSync = (p: PG) => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!p.sync && !p.sync_assigned) {
|
if (!p.sync) {
|
||||||
p.sync_assigned = true;
|
|
||||||
p.site = deepClone(EmptySite);
|
p.site = deepClone(EmptySite);
|
||||||
clientStartSync({
|
clientStartSync({
|
||||||
user_id: p.user.id,
|
user_id: p.user.id,
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ const runtime = {
|
||||||
action: {
|
action: {
|
||||||
pending: {} as Record<
|
pending: {} as Record<
|
||||||
string,
|
string,
|
||||||
{ ts: number; resolve: (value: any) => void }
|
{ ts: number; resolve: (value: any) => void; timeout: any }
|
||||||
>,
|
>,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -208,6 +208,7 @@ const connect = (
|
||||||
const pending = runtime.action.pending[msg.argid];
|
const pending = runtime.action.pending[msg.argid];
|
||||||
if (pending) {
|
if (pending) {
|
||||||
pending.resolve(msg.val);
|
pending.resolve(msg.val);
|
||||||
|
clearTimeout(pending.timeout);
|
||||||
delete runtime.action.pending[msg.argid];
|
delete runtime.action.pending[msg.argid];
|
||||||
const idb = conf.idb;
|
const idb = conf.idb;
|
||||||
if (idb) {
|
if (idb) {
|
||||||
|
|
@ -258,6 +259,11 @@ const doAction = async <T>(arg: {
|
||||||
runtime.action.pending[argid] = {
|
runtime.action.pending[argid] = {
|
||||||
ts: Date.now(),
|
ts: Date.now(),
|
||||||
resolve,
|
resolve,
|
||||||
|
timeout: path.startsWith("yjs.")
|
||||||
|
? setTimeout(() => {
|
||||||
|
w.sync_too_long = true;
|
||||||
|
}, 10000)
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
sendWs(ws, { type: SyncType.Action, code, args, argid });
|
sendWs(ws, { type: SyncType.Action, code, args, argid });
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ export const w = window as unknown as {
|
||||||
_api: any;
|
_api: any;
|
||||||
_db: any;
|
_db: any;
|
||||||
offline: boolean;
|
offline: boolean;
|
||||||
|
sync_too_long: boolean;
|
||||||
editorRender?: () => void;
|
editorRender?: () => void;
|
||||||
debug: {
|
debug: {
|
||||||
on: any;
|
on: any;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue