From af1784079b893dfd98c057effa78c149d40e64b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Mon, 25 Nov 2024 13:02:03 +0100 Subject: [PATCH] Applied new perfectionist rules --- eslint.config.js | 2 +- src/lib/State.ts | 2 -- src/lib/container.ts | 8 ++--- src/lib/history.ts | 70 +++++++++++++++++++++---------------------- src/lib/navigation.ts | 18 +++++------ 5 files changed, 49 insertions(+), 51 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index e16e916e..c89ebca8 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,6 +1,6 @@ -import js from "@eslint/js"; import eslintComments from "@eslint-community/eslint-plugin-eslint-comments"; import commentsConfig from "@eslint-community/eslint-plugin-eslint-comments/configs"; +import js from "@eslint/js"; import compat from "eslint-plugin-compat"; import perfectionist from "eslint-plugin-perfectionist"; import playwright from "eslint-plugin-playwright"; diff --git a/src/lib/State.ts b/src/lib/State.ts index 015d43a7..c2af8094 100644 --- a/src/lib/State.ts +++ b/src/lib/State.ts @@ -105,11 +105,9 @@ export function State( function transitionInNewImage(): void { currentImageView?.transitionIn( removeActivityIndicatorFromDOM, - /* eslint-disable @typescript-eslint/no-use-before-define -- Cyclical dependencies */ previous, next, close, - /* eslint-enable */ ); } diff --git a/src/lib/container.ts b/src/lib/container.ts index e9def7e8..f13ee992 100644 --- a/src/lib/container.ts +++ b/src/lib/container.ts @@ -31,8 +31,8 @@ export function darkenOverlay(): void { container.classList.add("ilb-overlay"); } -export function transitionOutContainer(): void { - container.style.opacity = "0"; +export function getContainer(): HTMLDivElement { + return container; } export function removeContainerFromDOM(): void { @@ -45,6 +45,6 @@ export function removeContainerFromDOM(): void { document.body.classList.remove("ilb-body"); } -export function getContainer(): HTMLDivElement { - return container; +export function transitionOutContainer(): void { + container.style.opacity = "0"; } diff --git a/src/lib/history.ts b/src/lib/history.ts index dd2f0368..f7f594e8 100644 --- a/src/lib/history.ts +++ b/src/lib/history.ts @@ -6,41 +6,6 @@ interface HistoryState { imageLightboxSet?: string; } -export function pushQuitToHistory(): void { - let newQuery = removeQueryField( - document.location.search, - "imageLightboxIndex", - ); - newQuery = removeQueryField(newQuery, "imageLightboxSet"); - window.history.pushState({}, "", document.location.pathname + newQuery); -} - -export function pushToHistory( - index: number, - set: string | undefined, - images: Array, -): void { - const newIndex = images[index].dataset["ilb2Id"] ?? index.toString(); - let newQuery = addQueryField( - document.location.search, - "imageLightboxIndex", - newIndex, - ); - const newHistoryState: HistoryState = { - imageLightboxIndex: newIndex, - imageLightboxSet: "", - }; - if (set !== undefined) { - newHistoryState.imageLightboxSet = set; - newQuery = addQueryField(newQuery, "imageLightboxSet", set); - } - window.history.pushState( - newHistoryState, - "", - document.location.pathname + newQuery, - ); -} - export function openHistory( set: string | undefined, images: Array, @@ -109,3 +74,38 @@ export function popHistory( true, ); } + +export function pushQuitToHistory(): void { + let newQuery = removeQueryField( + document.location.search, + "imageLightboxIndex", + ); + newQuery = removeQueryField(newQuery, "imageLightboxSet"); + window.history.pushState({}, "", document.location.pathname + newQuery); +} + +export function pushToHistory( + index: number, + set: string | undefined, + images: Array, +): void { + const newIndex = images[index].dataset["ilb2Id"] ?? index.toString(); + let newQuery = addQueryField( + document.location.search, + "imageLightboxIndex", + newIndex, + ); + const newHistoryState: HistoryState = { + imageLightboxIndex: newIndex, + imageLightboxSet: "", + }; + if (set !== undefined) { + newHistoryState.imageLightboxSet = set; + newQuery = addQueryField(newQuery, "imageLightboxSet", set); + } + window.history.pushState( + newHistoryState, + "", + document.location.pathname + newQuery, + ); +} diff --git a/src/lib/navigation.ts b/src/lib/navigation.ts index 4b8aa4a7..ccccd765 100644 --- a/src/lib/navigation.ts +++ b/src/lib/navigation.ts @@ -40,15 +40,6 @@ export function addNavigationItems( } } -export function changeNavigationCurrent(currentIndex: number): void { - for (let i = 0; i < navigation.children.length; i++) { - navigation.children.item(i)?.classList.remove("ilb-navigation-active"); - } - navigation.children - .item(currentIndex) - ?.classList.add("ilb-navigation-active"); -} - export function addNavigationToDOM( images: Array, currentIndexFn: () => number | null, @@ -70,3 +61,12 @@ export function addNavigationToDOM( e.stopPropagation(); }); } + +export function changeNavigationCurrent(currentIndex: number): void { + for (let i = 0; i < navigation.children.length; i++) { + navigation.children.item(i)?.classList.remove("ilb-navigation-active"); + } + navigation.children + .item(currentIndex) + ?.classList.add("ilb-navigation-active"); +}