diff options
author | metamuffin <metamuffin@disroot.org> | 2023-09-08 15:29:20 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-09-08 15:29:20 +0200 |
commit | 7c3864fac1ded20e8137cf637ea55693492cf1f6 (patch) | |
tree | 967a18e97bbfa5c933c1b71dd1e35cbbc31b4f12 | |
parent | 564a6f1e38af84ef857e25bb0266012b38d1fb1d (diff) | |
download | keks-meet-7c3864fac1ded20e8137cf637ea55693492cf1f6.tar keks-meet-7c3864fac1ded20e8137cf637ea55693492cf1f6.tar.bz2 keks-meet-7c3864fac1ded20e8137cf637ea55693492cf1f6.tar.zst |
watches edit ui
-rw-r--r-- | client-web/source/helper.ts | 6 | ||||
-rw-r--r-- | client-web/source/preferences/mod.ts | 4 | ||||
-rw-r--r-- | client-web/source/room_watches.ts | 64 |
3 files changed, 48 insertions, 26 deletions
diff --git a/client-web/source/helper.ts b/client-web/source/helper.ts index 49c36fa..336f7d4 100644 --- a/client-web/source/helper.ts +++ b/client-web/source/helper.ts @@ -84,3 +84,9 @@ export class EventEmitter<E> { public add_listener(listener: (e: E) => unknown) { this.handlers.add(listener) } public remove_listener(listener: (e: E) => unknown) { this.handlers.delete(listener) } } + +export function array_swap<T>(arr: T[], a: number, b: number) { + const temp = arr[a] + arr[a] = arr[b] + arr[b] = temp +}
\ No newline at end of file diff --git a/client-web/source/preferences/mod.ts b/client-web/source/preferences/mod.ts index c4e502d..815afd9 100644 --- a/client-web/source/preferences/mod.ts +++ b/client-web/source/preferences/mod.ts @@ -91,12 +91,12 @@ export function generate_section(): string { export function load_params(): { raw_params: { [key: string]: string }, rsecret: string } { const raw_params: Record<string, string> = {} - const [rsecret, param_str] = window.location.hash.substring(1).split("?") + const [rsecret, param_str] = decodeURIComponent(window.location.hash.substring(1)).split("?") if (!param_str) return { rsecret, raw_params: {} } for (const kv of param_str.split("&")) { const [key, value] = kv.split("=") if (key == "prototype") continue - raw_params[decodeURIComponent(key)] = decodeURIComponent(value) + raw_params[key] = value } return { raw_params, rsecret } } diff --git a/client-web/source/room_watches.ts b/client-web/source/room_watches.ts index fb07ff5..01e2bc4 100644 --- a/client-web/source/room_watches.ts +++ b/client-web/source/room_watches.ts @@ -1,4 +1,4 @@ -import { e } from "./helper.ts"; +import { array_swap, e } from "./helper.ts"; import { PREFS, change_pref } from "./preferences/mod.ts"; import { crypto_hash } from "./protocol/crypto.ts"; import { SignalingConnection } from "./protocol/mod.ts"; @@ -13,7 +13,7 @@ interface Watch { export function ui_room_watches(conn: SignalingConnection): HTMLElement { const listing = e("div", { class: "room-watches-listing" }) - const watches: Watch[] = [] + let watches: Watch[] = [] const update_watches = () => (conn.send_control({ watch_rooms: watches.map(w => w.hash) }), update_listing()); const add_watch = async (secret: string) => watches.push({ name: secret.split("#")[0], secret, hash: await crypto_hash(secret), user_count: 0 }) @@ -22,49 +22,65 @@ export function ui_room_watches(conn: SignalingConnection): HTMLElement { conn.control_handler.add_listener(packet => { if (packet.room_info) { - const w = watches.find(w => w.hash == packet.room_info!.hash) - w!.user_count = packet.room_info.user_count + const w = watches.filter(w => w.hash == packet.room_info!.hash) + w.forEach(w => w.user_count = packet.room_info!.user_count) update_listing() } }) + let edit = false; + const update_listing = () => { listing.innerHTML = "" - for (const w of watches) { + for (let wi = 0; wi < watches.length; wi++) { + const w = watches[wi] const ucont = [] if (w.user_count > 0) ucont.push(e("div", {})) if (w.user_count > 1) ucont.push(e("div", {})) if (w.user_count > 2) ucont.push(e("div", {})) if (w.user_count > 3) ucont.push(e("span", {}, `+${w.user_count - 3}`)) - listing.append(e("li", {}, - e("a", { - href: "#" + encodeURIComponent(w.secret), + const el = e("li", {}, e("a", + { + href: "#" + w.secret, class: w.secret == conn.room ? "current-room" : [] }, - w.name, - e("div", { class: "users" }, ...ucont) - ) + w.name, + e("div", { class: "users" }, ...ucont), + )) + if (edit) el.append(e("button", { onclick(_) { watches = watches.filter(e => e != w); update_listing() } }, "X")) + if (edit && wi > 0) el.append(e("button", { onclick(_) { array_swap(watches, wi, wi - 1); update_listing() } }, "Move up")) + if (edit && wi < watches.length - 1) el.append(e("button", { onclick(_) { array_swap(watches, wi, wi + 1); update_listing() } }, "Move down")) + listing.append(el) + } + + if (edit) { + let input: HTMLInputElement; + listing.append(e("li", { class: "room-watches-edit" }, + e("label", {}, "Add room:", input = e("input", { type: "text" })), + e("button", { + async onclick(_e) { + for (const w of input.value.split(";")) + await add_watch(w) + update_watches() + input.value = "" + } + }, "Add") )) } } load_watches() - let input: HTMLInputElement; return e("div", { class: "room-watches" }, e("h2", {}, "Known Rooms"), listing, - e("div", { class: "room-watches-edit" }, - e("label", {}, "Add room:", input = e("input", { type: "text" })), - e("button", { - async onclick(_e) { - for (const w in input.value.split(";")) - await add_watch(w) - update_watches() - save_watches() - input.value = "" - } - }, "Add") - ) + e("button", { + onclick(e) { + edit = !edit; + e.textContent = edit ? "Finish edit" : "Edit"; + if (!edit) save_watches(), update_watches() + update_listing() + } + }, "Edit"), ) } |