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 }); fireEvent.click(element, { button: 0 });
expect(mockCallback).toHaveBeenCalledTimes(1);
// Remove the listener // Remove the listener
localCleanup(); localCleanup();

View file

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

View file

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