diff --git a/public/base.css b/public/base.css index 6c3d111..9027f95 100644 --- a/public/base.css +++ b/public/base.css @@ -96,8 +96,8 @@ select { font-size: inherit; } -input, -textarea { +form input, +form textarea { width: 100%; color: inherit; border-radius: var(--border-radius); diff --git a/public/index.html b/public/index.html index 6677d9a..c23fce2 100644 --- a/public/index.html +++ b/public/index.html @@ -147,6 +147,13 @@ window.addEventListener("locationchange", update_topics); document.addEventListener( 'user_logged_in', update_topics ); + document.addEventListener( 'user_logged_in', () => { + const user = document.body.dataset.user && JSON.parse( document.body.dataset.user ); + if ( !user ) { + return; + } + }); + /* check if we are logged in */ (async () => { try { diff --git a/public/sidebar/sidebar.html b/public/sidebar/sidebar.html index fef3c33..45e635a 100644 --- a/public/sidebar/sidebar.html +++ b/public/sidebar/sidebar.html @@ -158,44 +158,49 @@ new MutationObserver((mutations, observer) => { mutations.forEach((mutation) => { - const user_json = document.body.dataset.user; - const user = user_json - ? JSON.parse(user_json) - : { - username: "", - meta: { - avatar: DEFAULT_AVATAR_URL, - }, - }; + const user = document.body.dataset.user + ? JSON.parse(document.body.dataset.user) + : null; - const ids = document.querySelectorAll("[data-bind__user_id]"); - for (const id of ids) { - const bound_to = - typeof id.dataset["bind__user_id"] === "string" && - id.dataset["bind__user_id"].length > 0 - ? id.dataset["bind__user_id"] + const user_bound_elements = document.querySelectorAll("[data-bind-to-user-field]"); + for (const user_bound_element of user_bound_elements) { + const key = + user_bound_element.dataset + .bindToUserField; /* I hate that it converts the name */ + const key_elements = key.split("."); + + let value = undefined; + if (user) { + let current = user; + for (const key_element of key_elements) { + current = current[key_element]; + if (!current) { + break; + } + } + + value = current; + } + + const target = + typeof user_bound_element.dataset.userFieldTarget === "string" && + user_bound_element.dataset.userFieldTarget.length > 0 + ? user_bound_element.dataset.userFieldTarget : "innerHTML"; - avatar[bound_to] = user.id ?? ""; + + const default_value = + typeof user_bound_element.dataset.userFieldDefault === "string" && + user_bound_element.dataset.userFieldDefault.length > 0 + ? user_bound_element.dataset.userFieldDefault + : ""; + + user_bound_element[target] = value ?? default_value; } - const avatars = document.querySelectorAll("[data-bind__user_meta_avatar]"); - for (const avatar of avatars) { - const bound_to = - typeof avatar.dataset["bind__user_meta_avatar"] === "string" && - avatar.dataset["bind__user_meta_avatar"].length - ? avatar.dataset["bind__user_meta_avatar"] - : "innerHTML"; - avatar[bound_to] = user.meta?.avatar ?? DEFAULT_AVATAR_URL; - } - - const usernames = document.querySelectorAll("[data-bind__user_username]"); - for (const username of usernames) { - const bound_to = - typeof username.dataset["bind__user_username"] === "string" && - username.dataset["bind__user_username"].length > 0 - ? username.dataset["bind__user_username"] - : "innerHTML"; - username[bound_to] = user.username; + const primary_color_setting = user.meta.primary_color; + if (primary_color_setting) { + const root = document.querySelector(":root"); + root.style.setProperty("--base-color", primary_color_setting); } }); }).observe(document.body, { @@ -233,53 +238,74 @@ cursor: pointer; } -
-
- User Avatar - - + } + + for (const input of inputs) { + function on_updated(event) { + if (input.__debounce_timeout) { + clearTimeout(input.__debounce_timeout); + } + + input.__debounce_timeout = setTimeout(() => { + update_from_input(input); + }, 250); + } + + input.addEventListener("input", on_updated); + input.addEventListener("change", on_updated); + } + }); + +
+ User Avatar +
- +
@@ -309,27 +361,40 @@
-
- - -
-
+ delete document.body.dataset.user; + delete document.body.dataset.perms; + window.location = "/"; + + document.dispatchEvent(new CustomEvent("user_logged_out", { detail: {} })); + }; + } + + +
diff --git a/public/tabs/profile/profile.html b/public/tabs/profile/profile.html deleted file mode 100644 index 3dcbd15..0000000 --- a/public/tabs/profile/profile.html +++ /dev/null @@ -1,190 +0,0 @@ - - -
- - -
-
-
- User Avatar - - -
- -
- -
- -
- -
- -
- - -
-
-
-