This commit is contained in:
Rizky 2024-03-22 01:15:19 +07:00
parent 07e33460cd
commit 8ed1e99a35
3 changed files with 8 additions and 7 deletions

View File

@ -15,7 +15,7 @@ Error generating stack: `+i.message+`
} }
`),children:[(0,Se.jsx)("div",{className:"text-[10px] text-slate-400 whitespace-nowrap",children:o}),(0,Se.jsx)("div",{className:"pr-outer w-full h-[3px] flex items-stretch rounded-sm overflow-hidden",children:(0,Se.jsx)("div",{className:cx("bg-blue-800 transition-all duration-200 rounded-sm w-full",css` `),children:[(0,Se.jsx)("div",{className:"text-[10px] text-slate-400 whitespace-nowrap",children:o}),(0,Se.jsx)("div",{className:"pr-outer w-full h-[3px] flex items-stretch rounded-sm overflow-hidden",children:(0,Se.jsx)("div",{className:cx("bg-blue-800 transition-all duration-200 rounded-sm w-full",css`
transform: translate(${-100+s.value*200}%); transform: translate(${-100+s.value*200}%);
`)})}),i]})})]})};var Fs=O(ce());var Vh=(e,t)=>{e.status="loading",e.on_status_changes&&e.on_status_changes(e.status),e.site.id=t.site_id,e.site.api_url=t.api_url,!e.site.api&&!e.site.db&&(e.status="ready",e.on_status_changes&&e.on_status_changes(e.status))};var ln={ts:0,status:"init",meta:{},entry:[],tick:0,mode:"desktop",site:{id:"",api_url:"",api:null,db:null},site_url:null,script:{init_local_effect:void 0},visit:void 0,on_status_changes:void 0,layout:void 0,page:{cur:{id:""},navs:{}},on_preload:void 0};var Ny=O(ce());var le=O(ce()),Hu=class extends le.Component{displayName="ReactUseErrorBoundary";componentDidCatch(...t){this.setState({}),this.props.onError(...t)}render(){return this.props.children}},M1=()=>!1,$h=(0,le.createContext)({componentDidCatch:{current:void 0},error:void 0,setError:M1});function Hh({children:e}){let[t,n]=(0,le.useState)(),r=(0,le.useRef)(),o=(0,le.useMemo)(()=>({componentDidCatch:r,error:t,setError:n}),[t]);return le.default.createElement($h.Provider,{value:o},le.default.createElement(Hu,{error:t,onError:(i,s)=>{n(i),r.current?.(i,s)}},e))}Hh.displayName="ReactUseErrorBoundaryContext";function Wh(e){function t(n){return le.default.createElement(Hh,null,le.default.createElement(e,{key:"WrappedComponent",...n}))}return t.displayName=`WithErrorBoundary(${e.displayName??e.name??"Component"})`,t}function Gh(e){let t=(0,le.useContext)($h);t.componentDidCatch.current=e;let n=(0,le.useCallback)(()=>{t.setError(void 0)},[]);return[t.error,n]}var qe=O(V()),mt=Wh(({children:e,meta:t,id:n,silent:r=!0})=>{let o=nn({retrying:!1,meta:t}),[i,s]=Gh((a,f)=>{r!==!0&&console.warn(a)});t&&o.meta!==t&&(o.meta=t,setTimeout(s));let l=t;return i?(0,qe.jsxs)("div",{className:"bg-red-100 border border-red-300 rounded-sm text-xs flex flex-col items-center",children:[(0,qe.jsxs)("div",{className:"text-[10px] font-bold text-red-900 self-stretch px-1",children:["ERROR ",l?.item.name?"["+l.item.name+"]:":""]}),(0,qe.jsx)("p",{className:"border-b border-red-300 px-1 pb-1 min-w-[100px]",children:o.retrying?(0,qe.jsx)(qe.Fragment,{children:"Retrying..."}):(0,qe.jsx)(qe.Fragment,{children:i.message})}),(0,qe.jsx)("div",{className:"p-1",children:(0,qe.jsx)("button",{onClick:()=>{o.retrying=!0,o.render(),setTimeout(()=>{o.retrying=!1,o.render(),s()},100)},className:"bg-white border border-white hover:border-red-400 hover:bg-red-50 rounded px-2",children:"Try again"})})]}):e});var Ae=(e,t,n,r)=>{let o=e[t];return n==="desktop"||!n?!o&&e.mobile&&e.mobile[t]&&(o=e.mobile[t]):e.mobile&&e.mobile[t]&&(o=e.mobile[t]),o||(o=r),o};var Qh=(e,t)=>{let n=Ae(e,"adv",t,{});return typeof n.css=="string"&&n.css.trim()?cx(css` `)})}),i]})})]})};var Fs=O(ce());var Vh=(e,t)=>{e.status="loading",e.on_status_changes&&e.on_status_changes(e.status),e.site.id=t.site_id,e.site.api_url=t.api_url,e.status="ready",e.on_status_changes&&e.on_status_changes(e.status)};var ln={ts:0,status:"init",meta:{},entry:[],tick:0,mode:"desktop",site:{id:"",api_url:"",api:null,db:null},site_url:null,script:{init_local_effect:void 0},visit:void 0,on_status_changes:void 0,layout:void 0,page:{cur:{id:""},navs:{}},on_preload:void 0};var Ny=O(ce());var le=O(ce()),Hu=class extends le.Component{displayName="ReactUseErrorBoundary";componentDidCatch(...t){this.setState({}),this.props.onError(...t)}render(){return this.props.children}},M1=()=>!1,$h=(0,le.createContext)({componentDidCatch:{current:void 0},error:void 0,setError:M1});function Hh({children:e}){let[t,n]=(0,le.useState)(),r=(0,le.useRef)(),o=(0,le.useMemo)(()=>({componentDidCatch:r,error:t,setError:n}),[t]);return le.default.createElement($h.Provider,{value:o},le.default.createElement(Hu,{error:t,onError:(i,s)=>{n(i),r.current?.(i,s)}},e))}Hh.displayName="ReactUseErrorBoundaryContext";function Wh(e){function t(n){return le.default.createElement(Hh,null,le.default.createElement(e,{key:"WrappedComponent",...n}))}return t.displayName=`WithErrorBoundary(${e.displayName??e.name??"Component"})`,t}function Gh(e){let t=(0,le.useContext)($h);t.componentDidCatch.current=e;let n=(0,le.useCallback)(()=>{t.setError(void 0)},[]);return[t.error,n]}var qe=O(V()),mt=Wh(({children:e,meta:t,id:n,silent:r=!0})=>{let o=nn({retrying:!1,meta:t}),[i,s]=Gh((a,f)=>{r!==!0&&console.warn(a)});t&&o.meta!==t&&(o.meta=t,setTimeout(s));let l=t;return i?(0,qe.jsxs)("div",{className:"bg-red-100 border border-red-300 rounded-sm text-xs flex flex-col items-center",children:[(0,qe.jsxs)("div",{className:"text-[10px] font-bold text-red-900 self-stretch px-1",children:["ERROR ",l?.item.name?"["+l.item.name+"]:":""]}),(0,qe.jsx)("p",{className:"border-b border-red-300 px-1 pb-1 min-w-[100px]",children:o.retrying?(0,qe.jsx)(qe.Fragment,{children:"Retrying..."}):(0,qe.jsx)(qe.Fragment,{children:i.message})}),(0,qe.jsx)("div",{className:"p-1",children:(0,qe.jsx)("button",{onClick:()=>{o.retrying=!0,o.render(),setTimeout(()=>{o.retrying=!1,o.render(),s()},100)},className:"bg-white border border-white hover:border-red-400 hover:bg-red-50 rounded px-2",children:"Try again"})})]}):e});var Ae=(e,t,n,r)=>{let o=e[t];return n==="desktop"||!n?!o&&e.mobile&&e.mobile[t]&&(o=e.mobile[t]):e.mobile&&e.mobile[t]&&(o=e.mobile[t]),o||(o=r),o};var Qh=(e,t)=>{let n=Ae(e,"adv",t,{});return typeof n.css=="string"&&n.css.trim()?cx(css`
${n.css} ${n.css}
`,t):""};var Kh=(e,t)=>{let n=Ae(e,"bg",t,{size:"contain",pos:"center"}),r=`${serverurl}${n.url}`;return n&&n.url&&n.url.startsWith("http")&&(r=n.url),cx(` `,t):""};var Kh=(e,t)=>{let n=Ae(e,"bg",t,{size:"contain",pos:"center"}),r=`${serverurl}${n.url}`;return n&&n.url&&n.url.startsWith("http")&&(r=n.url),cx(`
background-repeat: no-repeat; background-repeat: no-repeat;

View File

@ -16,6 +16,7 @@ export const viLoadSnapshot = async (p: PG) => {
if (api_url && apiURL.hostname) { if (api_url && apiURL.hostname) {
await loadApiProxyDef(api_url, true); await loadApiProxyDef(api_url, true);
const api = w.prasiApi[api_url]; const api = w.prasiApi[api_url];
if (api && api.apiTypes && api.prismaTypes) { if (api && api.apiTypes && api.prismaTypes) {
const zip = JSON.stringify({ const zip = JSON.stringify({
@ -46,6 +47,8 @@ export const viLoadSnapshot = async (p: PG) => {
} catch (e: any) { } catch (e: any) {
if (e && !e.message.toLowerCase().includes("invalid url")) { if (e && !e.message.toLowerCase().includes("invalid url")) {
console.warn("Failed to load API [Snapshot]:", api_url); console.warn("Failed to load API [Snapshot]:", api_url);
} else {
console.error(e);
} }
} }
@ -62,6 +65,7 @@ export const applyEnv = async (p: PG) => {
const url = `/prod/${p.site.id}/_prasi/code/index.js?ts=${p.site.code_ts}`; const url = `/prod/${p.site.id}/_prasi/code/index.js?ts=${p.site.code_ts}`;
const fn = new Function("callback", `import("${url}").then(callback)`); const fn = new Function("callback", `import("${url}").then(callback)`);
try { try {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
fn((exports: any) => { fn((exports: any) => {

View File

@ -1,5 +1,4 @@
import { VG } from "../render/global"; import { VG } from "../render/global";
import { viLoadLegacy } from "./load-legacy";
export const viLoad = (vi: VG, arg: { site_id: string; api_url: string }) => { export const viLoad = (vi: VG, arg: { site_id: string; api_url: string }) => {
vi.status = "loading"; vi.status = "loading";
@ -9,10 +8,8 @@ export const viLoad = (vi: VG, arg: { site_id: string; api_url: string }) => {
vi.site.id = arg.site_id; vi.site.id = arg.site_id;
vi.site.api_url = arg.api_url; vi.site.api_url = arg.api_url;
if (!vi.site.api && !vi.site.db) { vi.status = "ready";
vi.status = "ready"; if (vi.on_status_changes) {
if (vi.on_status_changes) { vi.on_status_changes(vi.status);
vi.on_status_changes(vi.status);
}
} }
}; };