adjustments based on PR comments

This commit is contained in:
SeinopSys 2022-04-17 14:42:13 +02:00 committed by Luna D
parent aade85a0ff
commit 87f37ab8d4
No known key found for this signature in database
GPG key ID: 4B1C63448394F688
4 changed files with 13 additions and 12 deletions

View file

@ -381,6 +381,8 @@ describe('DOM Utilities', () => {
fireEvent.click(element, { button: 0 });
expect(mockCallback).toHaveBeenCalledTimes(1);
// Remove the listener
localCleanup();

View file

@ -1,6 +1,6 @@
import { $$ } from './dom';
let dragSrcEl: HTMLElement | undefined;
let dragSrcEl: HTMLElement | null = null;
function dragStart(event: DragEvent, target: HTMLElement) {
target.classList.add('dragging');
@ -83,6 +83,5 @@ export function clearDragSource() {
if (!dragSrcEl) return;
dragSrcEl.classList.remove('dragging');
// eslint-disable-next-line no-undefined
dragSrcEl = undefined;
dragSrcEl = null;
}

View file

@ -1,8 +1,7 @@
import { clearEl } from './dom';
import store from './store';
function showVideoThumb(img: HTMLDivElement, size: string, urisString: string) {
const uris = JSON.parse(urisString);
function showVideoThumb(img: HTMLDivElement, size: string, uris: Record<string, string>) {
const thumbUri = uris[size];
const vidEl = img.querySelector('video');
@ -31,11 +30,11 @@ export function showThumb(img: HTMLDivElement) {
const urisString = img.dataset.uris;
if (!size || !urisString) return false;
const uris = JSON.parse(urisString);
const uris: Record<string, string> = JSON.parse(urisString);
const thumbUri = uris[size].replace(/webm$/, 'gif');
const picEl = img.querySelector('picture');
if (!picEl) return showVideoThumb(img, size, urisString);
if (!picEl) return showVideoThumb(img, size, uris);
const imgEl = picEl.querySelector('img');
if (!imgEl || imgEl.src.indexOf(thumbUri) !== -1) return false;
@ -128,15 +127,16 @@ export function spoilerThumb(img: HTMLDivElement, spoilerUri: string, reason: st
export function spoilerBlock(img: HTMLDivElement, spoilerUri: string, reason: string) {
const imgFiltered = img.querySelector('.image-filtered');
const imgEl = imgFiltered?.querySelector<HTMLImageElement>('img');
const imgReason = img.querySelector<HTMLElement>('.filter-explanation');
if (!imgEl) return;
const imgReason = img.querySelector<HTMLElement>('.filter-explanation');
const imageShow = img.querySelector('.image-show');
imgEl.src = spoilerUri;
if (imgReason) {
imgReason.innerHTML = reason;
}
img.querySelector('.image-show')?.classList.add('hidden');
imageShow?.classList.add('hidden');
if (imgFiltered) imgFiltered.classList.remove('hidden');
}

View file

@ -10,7 +10,7 @@ interface Result {
/**
* Compare two strings, C-style.
*/
function strcmp(a: string, b: string):number {
function strcmp(a: string, b: string): number {
return a < b ? -1 : Number(a > b);
}
@ -140,7 +140,7 @@ export class LocalAutocompleter {
/**
* Find the top k results by image count which match the given string prefix.
*/
topK(prefix: string, k:number): Result[] {
topK(prefix: string, k: number): Result[] {
const results: Record<string, Result> = {};
if (prefix === '') {