stear/example/connect.js
2022-06-09 17:33:54 +02:00

41 lines
1.2 KiB
JavaScript

import l1 from "../stear/extra/Elements/loading1.js";
import alert from "../stear/extra/Pages/alert.js";
import { _ } from "../stear/main.js";
import { fadein, fadeout, wait } from "../stear/utils.js";
export const preRender = true;
export const render = ({},{}) =>
_({find:"main"},[
_({type:"p",find:"text",style:{
position: "absolute",
minWidth: "90%",
textAlign: "center",
top: "25%",
left: "50%",
transform: "translate(-50%,-50%)",
}}),
_({style:{
position: "absolute",
left: "50%",
top: "50%",
transform: "translate(-50%, -50%)",
}}, l1())
]);
export const call = async (stear, { find, resolve, render, call }, {name,id}) => {
find.text._.innerText = "Connecting to: " + name + " (" + id + ")";
await fadein(find.main._, 200, true);
//do connection
await wait(1000);
var success = Math.random()>0.25;
if(success){
await call(alert, { text: "success" });
await fadeout(find.main._);
return resolve(true);
}else{
await call(alert, { text: "error" });
await fadeout(find.main._);
return resolve(false);
}
}