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 communityQRCodeURL = (communityID) => `qr-codes/${communityID}.png`
export const COLUMN = {
IDENTIFIER: 0, LANGUAGE: 1, NAME: 2,
DESCRIPTION: 3, USERS: 4, PREVIEW: 5,
@ -53,6 +55,12 @@ export const COMPARISON = {
};
export const ATTRIBUTES = {
ROW: {
IDENTIFIER: 'data-identifier',
PUBLIC_KEY: 'data-pubkey',
HOSTNAME: 'data-hostname',
STAFF_DATA: 'data-staff'
},
SORTING: {
ACTIVE: 'data-sort',
ASCENDING: 'data-sort-asc',

@ -16,7 +16,8 @@
// Import magic numbers and data
import {
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';
// 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();
}
@ -117,7 +118,7 @@ function addQRModalHandlers() {
const rows = dom.tbl_communities_content_rows();
if (!rows) throw new Error("Rows not found");
for (const row of rows) {
const communityID = row.getAttribute('data-identifier');
const communityID = row.getAttribute(ATTRIBUTES.ROW.IDENTIFIER);
row.querySelector('.td_qr_code').addEventListener(
'click',
() => displayQRModal(communityID)
@ -150,7 +151,7 @@ function addQRModalHandlers() {
/**
* @type {string[]}
*/
const staff = JSON.parse(this.getAttribute('data-staff'));
const staff = JSON.parse(this.getAttribute(ATTRIBUTES.ROW.STAFF_DATA));
if (staff.length == 0) {
alert("No public moderators available for this Community.");
return;
@ -159,7 +160,7 @@ function addQRModalHandlers() {
copyToClipboard(`@${staffId}`, 'Copied staff ID to clipboard.');
}
)
for (const anchor of dom.qr_code_buttons()) {
// Disable QR code links
anchor.setAttribute("href", "#");
@ -241,8 +242,8 @@ function setLastChecked(last_checked) {
function addServerIconInteractions() {
const rows = dom.tbl_communities_content_rows();
for (const row of rows) {
const hostname = row.getAttribute('data-hostname');
const publicKey = row.getAttribute('data-pubkey');
const hostname = row.getAttribute(ATTRIBUTES.ROW.HOSTNAME);
const publicKey = row.getAttribute(ATTRIBUTES.ROW.PUBLIC_KEY);
const serverIcon = row.querySelector('.td_server_icon');
serverIcon.addEventListener('click', () => {
alert(`Host: ${hostname}\n\nPublic key:\n${publicKey}`);

Loading…
Cancel
Save