diff --git a/freechat-client/pages/index.html b/freechat-client/pages/index.html index 3df49a3..43cf367 100644 --- a/freechat-client/pages/index.html +++ b/freechat-client/pages/index.html @@ -79,24 +79,16 @@ + diff --git a/freechat-client/src/html.js b/freechat-client/src/html.js new file mode 100644 index 0000000..10fc548 --- /dev/null +++ b/freechat-client/src/html.js @@ -0,0 +1,44 @@ + +/** + * {String} id | id for the + * {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 + */ +exports.new_node = function(id, type, attrs) { + let node = document.createElement(type) + if(id) { node.id = id; } + + for(const key in attrs) { + if(key == 'classList') { + attrs['classList'].forEach(cls => node.classList.add(cls)) + continue + } + node[key] = attrs[key] + } + return node +} + +/** + * {Config} config | configuration object passed from the ipc + * {String} dom_id | element container for the server list itself + * */ +exports.build_server_list = function (config, dom_id) { + 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', { + 'classList': ['btn', 'btn-outline-secondary', 'btn-nav-settings'], + 'textContent': server['name'], + 'type': 'button' + }) + container.appendChild(child) + } +}