stear/example/connect.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-06-09 17:30:40 +02:00
import { l1 } from "../stear/extra/Elements/loading1.js";
import alert from "../stear/extra/Pages/alert.js";
2022-06-09 16:26:27 +02:00
import { _ } from "../stear/main.js";
import { fadein, fadeout, wait } from "../stear/utils.js";
2022-06-09 16:36:21 +02:00
//import "./waitStyle.js";
2022-06-09 15:29:53 +02:00
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%)",
2022-06-09 16:49:03 +02:00
}}, l1())
2022-06-09 15:29:53 +02:00
]);
2022-06-09 16:26:27 +02:00
export const call = async (stear, { find, resolve, render, call }, {name,id}) => {
2022-06-09 15:29:53 +02:00
find.text._.innerText = "Connecting to: " + name + " (" + id + ")";
2022-06-09 16:49:03 +02:00
await fadein(find.main._, 200, true);
2022-06-09 15:29:53 +02:00
//do connection
await wait(1000);
var success = Math.random()>0.25;
if(success){
2022-06-09 17:30:40 +02:00
await call(alert, { titel: "Connecting", text: "success" });
2022-06-09 15:29:53 +02:00
await fadeout(find.main._);
return resolve(true);
}else{
2022-06-09 17:30:40 +02:00
await call(alert, { text: "error" });
2022-06-09 15:29:53 +02:00
await fadeout(find.main._);
return resolve(false);
}
}