From 1e6a9ac844b78b0f77bfee01cf4be3b98d0369ca Mon Sep 17 00:00:00 2001 From: shockrah Date: Thu, 28 Jan 2021 18:01:38 -0800 Subject: [PATCH] +Setting proper callbacks on * Prefering server domains for get's in build_server_list * Fixing jsdoc for new_node to not be garbage --- freechat-client/src/html.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/freechat-client/src/html.js b/freechat-client/src/html.js index 10fc548..15bce49 100644 --- a/freechat-client/src/html.js +++ b/freechat-client/src/html.js @@ -1,13 +1,12 @@ /** - * {String} id | id for the - * {Object} attrs | config object with the following valid fields and their types + * @param {String} id HTML ID + * @param {String} type Base tag type => examples include 'button' 'div' + * @param {Object} attrs Config object with the following valid fields and their types * - * NOTE: all these fields are optional - * {Array} attrs.class | classes to apply to the new node - * {String} attrs.textContent | Textual content to write + * @returns HTMLElement */ -exports.new_node = function(id, type, attrs) { +exports.new_node = function (id, type, attrs) { let node = document.createElement(type) if(id) { node.id = id; } @@ -26,19 +25,28 @@ exports.new_node = function(id, type, attrs) { * {String} dom_id | element container for the server list itself * */ exports.build_server_list = function (config, dom_id) { - if(!config['servers']) { - return; - } + const channels = require('./channels.js') + if(!config['servers']) { return; } let container = document.getElementById(dom_id) for(const server of config['servers']) { - let child = html.new_node(server['ip'] || server['url'], 'button', { + const id = server['domain'] || server['ip'] + + let child = html.new_node(id, 'button', { 'classList': ['btn', 'btn-outline-secondary', 'btn-nav-settings'], 'textContent': server['name'], - 'type': 'button' + 'type': 'button', + 'onClick': channels.get_channels(id, server['port']) }) + // Why not jquery? because it doesn't write to the node's attributes itself + // for some reason + child.addEventListener('click', function() { + // NOTE: at some point /invite/ will be handled on port + channels.get_channels(server['domain'], server['port']) + }) + container.appendChild(child) } }