1
Fork 0

Miscellaneous utilities fixes.

This commit is contained in:
Bauke 2023-06-25 12:00:43 +02:00
parent fdb9b0e711
commit 143451e39c
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
6 changed files with 20 additions and 22 deletions

View File

@ -1,6 +1,6 @@
/** /**
* Creates an HTML Element from a given string. Only use this when using * Creates an HTML Element from a given string. Only use this when using
* `htm/preact` isn't practical. * Preact isn't practical.
*/ */
export function createElementFromString<T extends Element>(input: string): T { export function createElementFromString<T extends Element>(input: string): T {
const template = document.createElement("template"); const template = document.createElement("template");

View File

@ -1,3 +1,6 @@
/**
* Initialize the `TildesReExtended` global.
*/
export function initializeGlobals() { export function initializeGlobals() {
if (window.TildesReExtended === undefined) { if (window.TildesReExtended === undefined) {
window.TildesReExtended = { window.TildesReExtended = {

View File

@ -2,8 +2,7 @@ import {log} from "./logging.js";
import {querySelectorAll} from "./query-selectors.js"; import {querySelectorAll} from "./query-selectors.js";
/** /**
* Tries to extract and save the groups. Returns the current saved groups when * Try to extract the groups when in the group listing page at `/groups`.
* the user is not in `/groups` and the new ones when they are in `/groups`.
*/ */
export function extractGroups(): string[] | undefined { export function extractGroups(): string[] | undefined {
if (window.location.pathname !== "/groups") { if (window.location.pathname !== "/groups") {

View File

@ -1,5 +1,5 @@
/** /**
* Logs something to the console under the debug level. * Log something to the console under the debug level.
* @param thing The thing to log. * @param thing The thing to log.
* @param force If true, ignores whether or not debug logging is enabled. * @param force If true, ignores whether or not debug logging is enabled.
*/ */

View File

@ -1,15 +1,17 @@
// These utility functions mainly exist so it's easier to work with TypeScript's // These utility functions mainly exist so it's easier to work with TypeScript's
// typing and so we don't have to write `document.query...` all the time. // typing and so we don't have to write `document.query...` all the time.
// The first function should only ever be used when we know for certain that /**
// the target element is going to exist. * Get the first element found that matches the selector. Only use this when you
* know for certain that the target element exists.
/** Returns the first element found that matches the selector. */ */
export function querySelector<T extends Element>(selector: string): T { export function querySelector<T extends Element>(selector: string): T {
return document.querySelector(selector)!; return document.querySelector(selector)!;
} }
/** Returns all elements found from all the selectors. */ /**
* Get all elements found from all the given selectors.
*/
export function querySelectorAll<T extends Element>( export function querySelectorAll<T extends Element>(
...selectors: string[] ...selectors: string[]
): T[] { ): T[] {

View File

@ -9,12 +9,11 @@ export function createReportTemplate(
location: "gitlab" | "tildes", location: "gitlab" | "tildes",
trxVersion: string, trxVersion: string,
): string { ): string {
let introText = let introText = "Thank you for taking the time to report a bug!";
"Thank you for taking the time to report a bug! Don't forget to fill in an\n appropriate title above, and make sure the information below is correct."; introText += "\n Please make sure the information below is correct.";
if (location === "tildes") { if (location === "gitlab") {
introText = introText += "\n Don't forget to set a title for the issue!";
"Thank you for taking the time to report a bug! Please make sure the\n information below is correct.";
} }
const layout = platform.layout ?? "<unknown>"; const layout = platform.layout ?? "<unknown>";
@ -43,16 +42,11 @@ export function createReportTemplate(
reportTemplate += `| Device | ${manufacturer} ${product} |\n`; reportTemplate += `| Device | ${manufacturer} ${product} |\n`;
} }
reportTemplate += `\n<h3>The Problem</h3> reportTemplate += `\n
<!-- <!--
Please explain in sufficient detail what the problem is. When possible, Please explain in sufficient detail what the problem is. When possible,
including an image or video showing the problem also helps immensely. including an image or video showing the problem also helps immensely, but it's
-->\n\n\n not required.
<h3>A Solution</h3>
<!--
If you know of any possible solutions, feel free to include them. If the
solution is just something like "it should work" then you can safely omit
this section.
-->\n\n\n`; -->\n\n\n`;
return reportTemplate; return reportTemplate;