chore(*): use prettier for formatting

This commit is contained in:
Cory Dransfeldt 2025-06-14 16:43:12 -07:00
parent 6c659fe1d0
commit 029caaaa9e
No known key found for this signature in database
73 changed files with 1390 additions and 794 deletions

View file

@ -1,52 +1,52 @@
class SelectPagination extends HTMLElement {
static register(tagName = 'select-pagination') {
if ("customElements" in window) customElements.define(tagName, this)
if ('customElements' in window) customElements.define(tagName, this);
}
static get observedAttributes() {
return ['data-base-index']
return ['data-base-index'];
}
get baseIndex() {
return parseInt(this.getAttribute('data-base-index') || '0', 10)
return parseInt(this.getAttribute('data-base-index') || '0', 10);
}
connectedCallback() {
if (this.shadowRoot) return
if (this.shadowRoot) return;
this.attachShadow({ mode: 'open' }).appendChild(document.createElement('slot'))
this.attachShadow({ mode: 'open' }).appendChild(document.createElement('slot'));
const uriSegments = window.location.pathname.split('/').filter(Boolean)
let pageNumber = this.extractPageNumber(uriSegments)
if (pageNumber === null) pageNumber = this.baseIndex
const uriSegments = window.location.pathname.split('/').filter(Boolean);
let pageNumber = this.extractPageNumber(uriSegments);
if (pageNumber === null) pageNumber = this.baseIndex;
this.control = this.querySelector('select')
this.control.value = pageNumber.toString()
this.control = this.querySelector('select');
this.control.value = pageNumber.toString();
this.control.addEventListener('change', (event) => {
pageNumber = parseInt(event.target.value)
const updatedUrlSegments = this.updateUrlSegments(uriSegments, pageNumber)
window.location.href = `${window.location.origin}/${updatedUrlSegments.join('/')}`
})
pageNumber = parseInt(event.target.value);
const updatedUrlSegments = this.updateUrlSegments(uriSegments, pageNumber);
window.location.href = `${window.location.origin}/${updatedUrlSegments.join('/')}`;
});
}
extractPageNumber(segments) {
const lastSegment = segments[segments.length - 1]
return !isNaN(lastSegment) ? parseInt(lastSegment) : null
const lastSegment = segments[segments.length - 1];
return !isNaN(lastSegment) ? parseInt(lastSegment) : null;
}
updateUrlSegments(segments, pageNumber) {
const lastIsPage = !isNaN(segments[segments.length - 1])
const lastIsPage = !isNaN(segments[segments.length - 1]);
if (lastIsPage) {
segments[segments.length - 1] = pageNumber.toString()
segments[segments.length - 1] = pageNumber.toString();
} else {
segments.push(pageNumber.toString())
segments.push(pageNumber.toString());
}
if (pageNumber === this.baseIndex) segments.pop()
if (pageNumber === this.baseIndex) segments.pop();
return segments
return segments;
}
}
SelectPagination.register()
SelectPagination.register();

View file

@ -21,7 +21,9 @@ window.addEventListener('load', () => {
if (isDynamic && !isLoaded) {
const markdownFields = dialog.dataset.markdown || '';
try {
const res = await fetch(`/api/query.php?data=${isDynamic}&id=${dialogId}&markdown=${encodeURIComponent(markdownFields)}`);
const res = await fetch(
`/api/query.php?data=${isDynamic}&id=${dialogId}&markdown=${encodeURIComponent(markdownFields)}`
);
const [data] = await res.json();
const firstField = markdownFields.split(',')[0]?.trim();
const html = data?.[`${firstField}_html`] || '<p>No notes available.</p>';

View file

@ -7,22 +7,23 @@ const staticAssets = [
'/assets/fonts/dmi.woff2',
'/assets/fonts/ml.woff2',
'/assets/scripts/index.js',
'/assets/scripts/components/select-pagination.js',
'/assets/scripts/components/select-pagination.js'
];
self.addEventListener('install', event => {
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(cacheName)
.then(cache => cache.addAll(staticAssets))
caches
.open(cacheName)
.then((cache) => cache.addAll(staticAssets))
.then(() => self.skipWaiting())
);
});
self.addEventListener('activate', event => {
self.addEventListener('activate', (event) => {
event.waitUntil(
(async () => {
const keys = await caches.keys();
await Promise.all(keys.filter(key => key !== cacheName).map(key => caches.delete(key)));
await Promise.all(keys.filter((key) => key !== cacheName).map((key) => caches.delete(key)));
if (self.registration.navigationPreload) await self.registration.navigationPreload.enable();
@ -31,7 +32,7 @@ self.addEventListener('activate', event => {
);
});
self.addEventListener('fetch', event => {
self.addEventListener('fetch', (event) => {
const request = event.request;
if (request.method !== 'GET') return;
@ -51,6 +52,5 @@ self.addEventListener('fetch', event => {
return;
}
event.respondWith(caches.match(request).then(response => response || fetch(request))
);
event.respondWith(caches.match(request).then((response) => response || fetch(request)));
});