This commit is contained in:
Rizky 2024-08-14 06:19:43 +07:00
parent 1d0957ee1d
commit d0e6137f6b
7 changed files with 59 additions and 67 deletions

File diff suppressed because one or more lines are too long

View File

@ -95,7 +95,7 @@ export const initFrontEnd = async (
filename?.endsWith(".css") ||
filename?.endsWith(".html")
) {
console.log(filename);
console.log(filename);
if (typeof fe !== "undefined" && !fe.rebuilding) {
fe.rebuilding = true;

View File

@ -21,6 +21,7 @@ import { EdPopSite } from "./panel/popup/site/site-popup";
import { iconVSCode } from "./panel/popup/code/icons";
import { isLocalhost } from "../../utils/ui/is-localhost";
import { w } from "../../utils/types/general";
import { edInitSync } from "./logic/ed-sync";
export const EdBase = () => {
const p = useGlobal(EDGlobal, "EDITOR");
@ -170,6 +171,37 @@ export const EdBase = () => {
</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>
);
};

View File

@ -160,8 +160,7 @@ export const EDGlobal = {
{ entry: string[]; meta: Record<string, IMeta>; url: string }
>,
},
sync: null as null | Awaited<ReturnType<typeof clientStartSync>>,
sync_assigned: false,
sync: undefined as undefined | Awaited<ReturnType<typeof clientStartSync>>,
site: deepClone(EmptySite),
site_tstamp: Date.now(),
site_exports: {} as Record<string, any>,

View File

@ -41,51 +41,6 @@ export const loadSession = (p: PG) => {
export const edInitSync = (p: PG) => {
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.site.id === "--loading--") return false;
@ -131,8 +86,7 @@ export const edInitSync = (p: PG) => {
return false;
}
}
if (!p.sync && !p.sync_assigned) {
p.sync_assigned = true;
if (!p.sync) {
p.site = deepClone(EmptySite);
clientStartSync({
user_id: p.user.id,

View File

@ -58,7 +58,7 @@ const runtime = {
action: {
pending: {} as Record<
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];
if (pending) {
pending.resolve(msg.val);
clearTimeout(pending.timeout);
delete runtime.action.pending[msg.argid];
const idb = conf.idb;
if (idb) {
@ -258,6 +259,11 @@ const doAction = async <T>(arg: {
runtime.action.pending[argid] = {
ts: Date.now(),
resolve,
timeout: path.startsWith("yjs.")
? setTimeout(() => {
w.sync_too_long = true;
}, 10000)
: undefined,
};
sendWs(ws, { type: SyncType.Action, code, args, argid });

View File

@ -44,6 +44,7 @@ export const w = window as unknown as {
_api: any;
_db: any;
offline: boolean;
sync_too_long: boolean;
editorRender?: () => void;
debug: {
on: any;