Minor refactoring

dev
gravel 1 year ago
parent 63975969b2
commit 8216b28f83
Signed by: gravel
GPG Key ID: C0538F3C906B308F

@ -35,6 +35,8 @@ export const dom = {
export const JOIN_URL_PASTE = "Copied URL to clipboard. Paste into Session app to join"; export const JOIN_URL_PASTE = "Copied URL to clipboard. Paste into Session app to join";
export const communityQRCodeURL = (communityID) => `qr-codes/${communityID}.png`
export const COLUMN = { export const COLUMN = {
IDENTIFIER: 0, LANGUAGE: 1, NAME: 2, IDENTIFIER: 0, LANGUAGE: 1, NAME: 2,
DESCRIPTION: 3, USERS: 4, PREVIEW: 5, DESCRIPTION: 3, USERS: 4, PREVIEW: 5,
@ -53,6 +55,12 @@ export const COMPARISON = {
}; };
export const ATTRIBUTES = { export const ATTRIBUTES = {
ROW: {
IDENTIFIER: 'data-identifier',
PUBLIC_KEY: 'data-pubkey',
HOSTNAME: 'data-hostname',
STAFF_DATA: 'data-staff'
},
SORTING: { SORTING: {
ACTIVE: 'data-sort', ACTIVE: 'data-sort',
ASCENDING: 'data-sort-asc', ASCENDING: 'data-sort-asc',

@ -16,7 +16,8 @@
// Import magic numbers and data // Import magic numbers and data
import { import {
dom, COLUMN, COLUMN_LITERAL, COMPARISON, ATTRIBUTES, dom, COLUMN, COLUMN_LITERAL, COMPARISON, ATTRIBUTES,
columnAscendingByDefault, columnIsSortable, COLUMN_TRANSFORMATION, element, JOIN_URL_PASTE columnAscendingByDefault, columnIsSortable, COLUMN_TRANSFORMATION,
element, JOIN_URL_PASTE, communityQRCodeURL
} from './js/constants.js'; } from './js/constants.js';
// Hidden communities for transparency. // Hidden communities for transparency.
@ -104,7 +105,7 @@ function displayQRModal(communityID) {
} }
} }
dom.details_modal_qr_code().src = `qr-codes/${communityID}.png`; dom.details_modal_qr_code().src = communityQRCodeURL(communityID);
modal.showModal(); modal.showModal();
} }
@ -117,7 +118,7 @@ function addQRModalHandlers() {
const rows = dom.tbl_communities_content_rows(); const rows = dom.tbl_communities_content_rows();
if (!rows) throw new Error("Rows not found"); if (!rows) throw new Error("Rows not found");
for (const row of rows) { for (const row of rows) {
const communityID = row.getAttribute('data-identifier'); const communityID = row.getAttribute(ATTRIBUTES.ROW.IDENTIFIER);
row.querySelector('.td_qr_code').addEventListener( row.querySelector('.td_qr_code').addEventListener(
'click', 'click',
() => displayQRModal(communityID) () => displayQRModal(communityID)
@ -150,7 +151,7 @@ function addQRModalHandlers() {
/** /**
* @type {string[]} * @type {string[]}
*/ */
const staff = JSON.parse(this.getAttribute('data-staff')); const staff = JSON.parse(this.getAttribute(ATTRIBUTES.ROW.STAFF_DATA));
if (staff.length == 0) { if (staff.length == 0) {
alert("No public moderators available for this Community."); alert("No public moderators available for this Community.");
return; return;
@ -241,8 +242,8 @@ function setLastChecked(last_checked) {
function addServerIconInteractions() { function addServerIconInteractions() {
const rows = dom.tbl_communities_content_rows(); const rows = dom.tbl_communities_content_rows();
for (const row of rows) { for (const row of rows) {
const hostname = row.getAttribute('data-hostname'); const hostname = row.getAttribute(ATTRIBUTES.ROW.HOSTNAME);
const publicKey = row.getAttribute('data-pubkey'); const publicKey = row.getAttribute(ATTRIBUTES.ROW.PUBLIC_KEY);
const serverIcon = row.querySelector('.td_server_icon'); const serverIcon = row.querySelector('.td_server_icon');
serverIcon.addEventListener('click', () => { serverIcon.addEventListener('click', () => {
alert(`Host: ${hostname}\n\nPublic key:\n${publicKey}`); alert(`Host: ${hostname}\n\nPublic key:\n${publicKey}`);

Loading…
Cancel
Save