update
This commit is contained in:
parent
0358a6025b
commit
deaf58dfce
7 changed files with 19 additions and 17 deletions
12
frontend/src/@types/dom.d.ts
vendored
Normal file
12
frontend/src/@types/dom.d.ts
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
interface CustomEventMap {
|
||||
"ft:pageChange": CustomEvent<{}>;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Document { //adds definition to Document, but you can do the same with HTMLElement
|
||||
addEventListener<K extends keyof CustomEventMap>(type: K,
|
||||
listener: (this: Document, ev: CustomEventMap[K]) => void): void;
|
||||
dispatchEvent<K extends keyof CustomEventMap>(ev: CustomEventMap[K]): void;
|
||||
}
|
||||
}
|
||||
export { }; //keep that for TS compiler.
|
||||
|
|
@ -6,6 +6,12 @@ import { getUser, updateUser } from "@app/auth";
|
|||
import io, { Socket } from 'socket.io-client';
|
||||
|
||||
let __socket: Socket | undefined = undefined;
|
||||
document.addEventListener('ft:pageChange', () => {
|
||||
if (__socket !== undefined)
|
||||
__socket.close();
|
||||
__socket = undefined;
|
||||
console.log("Page changed");
|
||||
})
|
||||
function getSocket(): Socket {
|
||||
if (__socket === undefined)
|
||||
__socket = io("wss://localhost:8888", {
|
||||
|
|
|
|||
|
|
@ -195,6 +195,7 @@ export async function handleRoute() {
|
|||
if (user === null && !route_handler.special_args.bypass_auth)
|
||||
return navigateTo(`/login?returnTo=${encodeURIComponent(window.location.pathname)}`)
|
||||
const app = document.getElementById('app')!;
|
||||
document.dispatchEvent(new CustomEvent('ft:pageChange' as any, {} as any) as any);
|
||||
let ret = await executeRouteHandler(route_handler, window.location.pathname, args)
|
||||
app.innerHTML = ret.html;
|
||||
if (ret.postInsert) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue