Merge branch 'dev' into parallel-fetching

dev
gravel 1 year ago
commit 0f5d03d23c
Signed by: gravel
GPG Key ID: C0538F3C906B308F

@ -35,12 +35,14 @@ Run at least once: `make fetch` to query servers. This can take around 5 minutes
Run when developing: `make dev` to watch for changes & serve HTML locally in browser.
Symlink the commit hook provided in [`etc/hooks`](etc/hooks/) to `.git/hooks/<hook>` to run a full test cycle when committing to main.
See [`Makefile`](Makefile) for more details.
### Running your own copy
- point your webserver at the [`output`](output/) folder
- install and enable systemd services from the [`systemd`](systemd/) folder or an equivalent timer
- install and enable systemd services from the [`etc/systemd`](etc/systemd/) folder or an equivalent timer
## Code style guidelines

@ -7,7 +7,7 @@ export const dom = {
tbl_communities: () => document.getElementById("tbl_communities"),
tbl_communities_content_rows:
() => 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) => {
const dateCreated = new Date(row.getAttribute(ATTRIBUTES.ROW.DATE_CREATED) * 1000);
/** @type {string[]} */
@ -49,6 +49,8 @@ export const STAFF_ID_PASTE = "Copied staff ping to clipboard. Use it in the sel
export const IDENTIFIER_PASTE = "Copied internal room identifier. Use it to identify a room, such as when contributing language labels."
export const DETAILS_LINK_PASTE = "Copied link to Community details.";
export const communityQRCodeURL = (communityID) => `qr-codes/${communityID}.png`
export const COLUMN = {

@ -17,7 +17,7 @@
import {
dom, COLUMN, COLUMN_LITERAL, COMPARISON, ATTRIBUTES,
columnAscendingByDefault, columnIsSortable, COLUMN_TRANSFORMATION,
element, JOIN_URL_PASTE, communityQRCodeURL, STAFF_ID_PASTE, IDENTIFIER_PASTE
element, JOIN_URL_PASTE, communityQRCodeURL, STAFF_ID_PASTE, IDENTIFIER_PASTE, DETAILS_LINK_PASTE
} from './js/constants.js';
// Hidden communities for transparency.
@ -76,6 +76,32 @@ function getTimestamp() {
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;
}
// manual scrolling to prevent jumping after every modal open
row.scrollIntoView({
behavior: "smooth"
});
try {
displayQRModal(communityID);
} catch (e) {
console.error("Could not navigate to community " + communityID);
console.error(e);
}
}
/**
* Triggers all actions dependent on page load.
*/
@ -92,6 +118,7 @@ function onLoad() {
addQRModalHandlers();
addServerIconInteractions();
preloadImages();
reactToURLParameters();
}
/**
@ -160,6 +187,8 @@ function displayQRModal(communityID, pane = 0) {
document.getElementById('details-modal-panes').setAttribute('data-pane', pane);
location.hash=`#${communityID}`;
modal.showModal();
}
@ -254,6 +283,13 @@ function addQRModalHandlers() {
}
)
document.querySelector('#details-modal-copy-room-details-link')?.addEventListener(
'click',
function() {
copyToClipboard(location.href, DETAILS_LINK_PASTE);
}
)
for (const anchor of dom.qr_code_buttons()) {
// Disable QR code links
anchor.setAttribute("href", "#");
@ -310,7 +346,7 @@ function hideBadCommunities() {
for (const category of ['tests', 'offensive']) {
numberOfHiddenCommunities +=
filteredCommunities[category]
.map(hideElementByID)
.map(hideCommunity)
.reduce((a, b) => a + b);
}
@ -319,10 +355,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) {
const element = document.getElementById(id);
function hideCommunity(communityID) {
const element = dom.community_row(communityID);
element?.remove();
return element ? 1 : 0;
}

@ -47,7 +47,7 @@
$room_id = $room->get_room_identifier();
$icon_cached = room_icon_path($room_id);
$icon_resized = room_icon_path_resized($room_id, $size);
$icon_expired = file_exists($icon_cached) && filemtime($icon_cached) < strtotime("-1 hour");
$icon_expired = file_exists($icon_cached) && filemtime($icon_cached) < strtotime("-1 day");
// Re-fetch icons periodically.
if (!file_exists($icon_cached) || $icon_expired) {

@ -599,7 +599,10 @@
* Return information for JSON serialization.
*/
function jsonSerialize(): array {
return get_object_vars($this);
$details = get_object_vars($this);
unset($details['room_hints']);
unset($details['merge_error']);
return $details;
}
/**

@ -103,7 +103,16 @@
class="themed-button"
data-hydrate-with="identifier:data-identifier"
title="Copy this room's identifier to uniquely identify this room to the sessioncommunities.online team"
>Copy Community ID</button>
>
Copy ID
</button>
<button
id="details-modal-copy-room-details-link"
class="themed-button"
title="Copy link to show details about this Community"
>
Share
</button>
<gap></gap>
<div id="details-modal-pane-selection" class="hidden">
<button

@ -71,7 +71,7 @@
$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-pubkey="<?=$pubkey?>"
data-hostname="<?=$hostname?>"

Loading…
Cancel
Save