2026-09-22 21:57:22 +02:00
|
|
|
import * as React from "../react";
|
2026-04-14 13:15:38 +00:00
|
|
|
|
2026-04-15 12:47:10 +00:00
|
|
|
class Tracker<T> {
|
|
|
|
|
state: React.State<T> | undefined;
|
2026-04-14 13:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 12:47:10 +00:00
|
|
|
class TrackerMap<T> {
|
|
|
|
|
trackers = new Map<string, Tracker<T>>();
|
2026-04-14 13:15:38 +00:00
|
|
|
|
2026-09-09 00:04:27 +02:00
|
|
|
private register = (key: string): Tracker<T>=> {
|
2026-04-14 13:15:38 +00:00
|
|
|
if (this.trackers.has(key)) {
|
2026-09-09 00:04:27 +02:00
|
|
|
return this.trackers.get(key)!;
|
2026-04-14 13:15:38 +00:00
|
|
|
}
|
2026-04-15 12:47:10 +00:00
|
|
|
const tracker = new Tracker<T>();
|
2026-04-14 13:15:38 +00:00
|
|
|
this.trackers.set(key, tracker);
|
|
|
|
|
return tracker;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-15 12:47:10 +00:00
|
|
|
setState = (
|
2026-04-14 13:15:38 +00:00
|
|
|
key: string,
|
2026-04-15 12:47:10 +00:00
|
|
|
stateBuilder: () => React.State<T>,
|
2026-09-09 00:04:27 +02:00
|
|
|
): React.State<T> | undefined => {
|
2026-04-15 12:47:10 +00:00
|
|
|
const tracker: Tracker<T> = this.register(key);
|
2026-04-14 13:15:38 +00:00
|
|
|
|
2026-04-15 12:47:10 +00:00
|
|
|
if (tracker.state != undefined) {
|
|
|
|
|
return tracker.state;
|
2026-04-14 13:15:38 +00:00
|
|
|
} else {
|
2026-04-15 12:47:10 +00:00
|
|
|
tracker.state = stateBuilder();
|
|
|
|
|
return tracker.state;
|
2026-04-14 13:15:38 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ViewController {
|
2026-04-15 12:47:10 +00:00
|
|
|
static readonly chatPages = new Tracker<HTMLElement>();
|
|
|
|
|
static readonly taskPages = new TrackerMap<HTMLElement>();
|
|
|
|
|
static readonly boardPages = new TrackerMap<HTMLElement>();
|
|
|
|
|
static readonly inlineReplies = new TrackerMap<HTMLElement>();
|
2026-04-14 13:15:38 +00:00
|
|
|
|
2026-04-15 12:47:10 +00:00
|
|
|
static readonly scrollToView = (id: string) => {
|
2026-04-14 13:15:38 +00:00
|
|
|
const element = document.getElementById(id);
|
2026-04-15 12:47:10 +00:00
|
|
|
if (!element) return;
|
2026-04-14 13:15:38 +00:00
|
|
|
element.scrollIntoView();
|
|
|
|
|
element.setAttribute("scrolled", "");
|
2026-04-15 12:47:10 +00:00
|
|
|
setTimeout(() => element.removeAttribute("scrolled"), 1000);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static readonly allowDrop = (event: DragEvent) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static readonly allowDrag = (event: DragEvent) => {
|
|
|
|
|
event.dataTransfer?.setData("text", "");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static readonly reload = () => {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static readonly setFocus = () => {
|
|
|
|
|
const focusedInModal = document.querySelector(
|
|
|
|
|
".modal[open] #focused",
|
|
|
|
|
) as HTMLElement;
|
|
|
|
|
if (focusedInModal) return focusedInModal.focus();
|
|
|
|
|
document.getElementById("focused")?.focus();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static readonly setFocusWithDelay = () => {
|
|
|
|
|
setTimeout(this.setFocus, 100);
|
|
|
|
|
};
|
2026-04-14 13:15:38 +00:00
|
|
|
}
|