Use hash in URL to open modal

dev
gravel 1 year ago
parent 172e8605ac
commit 6eaf63bb94
Signed by: gravel
GPG Key ID: C0538F3C906B308F

@ -7,7 +7,7 @@ export const dom = {
tbl_communities: () => document.getElementById("tbl_communities"), tbl_communities: () => document.getElementById("tbl_communities"),
tbl_communities_content_rows: tbl_communities_content_rows:
() => Array.from(dom.tbl_communities()?.rows)?.filter(row => !row.querySelector('th')), () => Array.from(dom.tbl_communities()?.rows)?.filter(row => !row.querySelector('th')),
community_row: (communityID) => document.getElementById(communityID), community_row: (communityID) => document.querySelector(`.room-row[${ATTRIBUTES.ROW.IDENTIFIER}="${communityID}"]`),
row_info: (row) => { row_info: (row) => {
const dateCreated = new Date(row.getAttribute(ATTRIBUTES.ROW.DATE_CREATED) * 1000); const dateCreated = new Date(row.getAttribute(ATTRIBUTES.ROW.DATE_CREATED) * 1000);
/** @type {string[]} */ /** @type {string[]} */

@ -76,6 +76,26 @@ function getTimestamp() {
return timestamp; return timestamp;
} }
/**
* Processes URL hash and parameter to trigger actions on the page.
*/
function reactToURLParameters() {
const hash = location.hash;
if (hash == "") return;
const communityID = hash.slice(1);
const row = dom.community_row(communityID);
if (row == null || !(row instanceof HTMLTableRowElement)) {
return;
}
try {
displayQRModal(communityID);
} catch (e) {
console.error("Could not navigate to community " + communityID);
console.error(e);
}
}
/** /**
* Triggers all actions dependent on page load. * Triggers all actions dependent on page load.
*/ */
@ -92,6 +112,7 @@ function onLoad() {
addQRModalHandlers(); addQRModalHandlers();
addServerIconInteractions(); addServerIconInteractions();
preloadImages(); preloadImages();
reactToURLParameters();
} }
/** /**
@ -160,6 +181,14 @@ function displayQRModal(communityID, pane = 0) {
document.getElementById('details-modal-panes').setAttribute('data-pane', pane); document.getElementById('details-modal-panes').setAttribute('data-pane', pane);
location.hash=`#${communityID}`;
// manual scrolling to prevent jumping after every modal open
row.scrollIntoView({
behavior: "smooth"
});
modal.showModal(); modal.showModal();
} }
@ -310,7 +339,7 @@ function hideBadCommunities() {
for (const category of ['tests', 'offensive']) { for (const category of ['tests', 'offensive']) {
numberOfHiddenCommunities += numberOfHiddenCommunities +=
filteredCommunities[category] filteredCommunities[category]
.map(hideElementByID) .map(hideCommunity)
.reduce((a, b) => a + b); .reduce((a, b) => a + b);
} }
@ -319,10 +348,10 @@ function hideBadCommunities() {
} }
/** /**
* Removes an element by its ID and returns the number of elements removed. * Removes a Community by its ID and returns the number of elements removed.
*/ */
function hideElementByID(id) { function hideCommunity(communityID) {
const element = document.getElementById(id); const element = dom.community_row(communityID);
element?.remove(); element?.remove();
return element ? 1 : 0; return element ? 1 : 0;
} }

@ -71,7 +71,7 @@
$tags_json = json_encode($room->get_room_tags()); $tags_json = json_encode($room->get_room_tags());
?> ?>
<tr id="<?=$id?>" class="room-row" itemscope itemtype="https://schema.org/EntryPoint" <tr class="room-row" itemscope itemtype="https://schema.org/EntryPoint"
data-identifier="<?=$id?>" data-identifier="<?=$id?>"
data-pubkey="<?=$pubkey?>" data-pubkey="<?=$pubkey?>"
data-hostname="<?=$hostname?>" data-hostname="<?=$hostname?>"

Loading…
Cancel
Save