fix mobile
This commit is contained in:
parent
246f106c35
commit
898685f117
|
|
@ -0,0 +1,55 @@
|
||||||
|
import { w } from "../../utils/script/init-api";
|
||||||
|
import { Loader } from "../live/logic/global";
|
||||||
|
|
||||||
|
const base = `/_web/${(window as any).id_site}`;
|
||||||
|
|
||||||
|
const cache = { site: null as any, pages: [] as any, api: null };
|
||||||
|
|
||||||
|
export const mobileLoader: Loader = {
|
||||||
|
async site(p, id) {
|
||||||
|
const res = (await load(`/site?prod=1`)) as {
|
||||||
|
site: any;
|
||||||
|
pages: any;
|
||||||
|
api: any;
|
||||||
|
};
|
||||||
|
cache.site = res.site;
|
||||||
|
cache.pages = res.pages;
|
||||||
|
cache.api = res.api;
|
||||||
|
|
||||||
|
w.serverurl = res.site.config.api_url;
|
||||||
|
w.apiurl = res.site.config.api_url;
|
||||||
|
|
||||||
|
w.prasiApi = {
|
||||||
|
[res.site.config.api_url]: { apiEntry: res.api },
|
||||||
|
};
|
||||||
|
|
||||||
|
return res.site;
|
||||||
|
},
|
||||||
|
async comp(p, id) {
|
||||||
|
const comp = (await load(`/comp/${id}`)) as any;
|
||||||
|
p.comps.all[id] = comp;
|
||||||
|
return comp;
|
||||||
|
},
|
||||||
|
npm(p, type, id) {
|
||||||
|
if (type === "site") return `/_web/${cache.site.id}/npm-site/site.js`;
|
||||||
|
return `/_web/${cache.site.id}/npm-page/${id}/page.js`;
|
||||||
|
},
|
||||||
|
async page(p, id) {
|
||||||
|
const page = cache.pages.find((x: any) => x.id === id);
|
||||||
|
if (page && !page.content_tree) {
|
||||||
|
const res = (await load(`/page/${id}`)) as any;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
async pages(p, id) {
|
||||||
|
return cache.pages;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const load = async (url: string) => {
|
||||||
|
const res = await fetch(`${base}${url}`);
|
||||||
|
const text = await res.text();
|
||||||
|
const json = JSON.parse(text);
|
||||||
|
return json;
|
||||||
|
};
|
||||||
|
|
@ -16,7 +16,6 @@ export const siteLoader: Loader = {
|
||||||
cache.pages = res.pages;
|
cache.pages = res.pages;
|
||||||
cache.api = res.api;
|
cache.api = res.api;
|
||||||
|
|
||||||
if (typeof w.basepath === "undefined") w.basepath = "";
|
|
||||||
w.serverurl = res.site.config.api_url;
|
w.serverurl = res.site.config.api_url;
|
||||||
w.apiurl = res.site.config.api_url;
|
w.apiurl = res.site.config.api_url;
|
||||||
|
|
||||||
|
|
@ -49,8 +48,7 @@ export const siteLoader: Loader = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const load = async (url: string) => {
|
const load = async (url: string) => {
|
||||||
console.log("loading", `${w.basepath}${base}${url}`);
|
const res = await fetch(`${base}${url}`);
|
||||||
const res = await fetch(`${w.basepath}${base}${url}`);
|
|
||||||
const text = await res.text();
|
const text = await res.text();
|
||||||
const json = JSON.parse(text);
|
const json = JSON.parse(text);
|
||||||
return json;
|
return json;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ const w = window as unknown as {
|
||||||
prasiContext: any;
|
prasiContext: any;
|
||||||
rootRender: any;
|
rootRender: any;
|
||||||
mobile: any;
|
mobile: any;
|
||||||
|
mobilepath?: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!w.mobile) {
|
if (!w.mobile) {
|
||||||
|
|
@ -25,7 +26,6 @@ const Root: FC<{ url: URL; Live: any }> = ({ url, Live }) => {
|
||||||
render({});
|
render({});
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(siteLoader)
|
|
||||||
const Provider = GlobalContext.Provider as FC<{ value: any; children: any }>;
|
const Provider = GlobalContext.Provider as FC<{ value: any; children: any }>;
|
||||||
return (
|
return (
|
||||||
<Provider value={w.prasiContext}>
|
<Provider value={w.prasiContext}>
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ export const w = window as unknown as {
|
||||||
dbClient: typeof dbClient;
|
dbClient: typeof dbClient;
|
||||||
serverurl: string;
|
serverurl: string;
|
||||||
apiurl: string;
|
apiurl: string;
|
||||||
basepath: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createAPI = (url: string) => {
|
export const createAPI = (url: string) => {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,9 @@ export const defineWindow = async (awaitServerUrl = true) => {
|
||||||
|
|
||||||
const port = location.port;
|
const port = location.port;
|
||||||
w.baseurl = scheme + "://" + host + (port ? ":" + port : "") + "/";
|
w.baseurl = scheme + "://" + host + (port ? ":" + port : "") + "/";
|
||||||
w.basepath = "/";
|
if (!w.basepath) {
|
||||||
|
w.basepath = "/";
|
||||||
|
}
|
||||||
w.css = css;
|
w.css = css;
|
||||||
w.extractCss = extractCss;
|
w.extractCss = extractCss;
|
||||||
w.pathname = location.pathname;
|
w.pathname = location.pathname;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue