diff --git a/starsky/starsky/clientapp/src/components/molecules/archive-sidebar/archive-sidebar-label-edit-search-replace.tsx b/starsky/starsky/clientapp/src/components/molecules/archive-sidebar/archive-sidebar-label-edit-search-replace.tsx index 22e2db7d3f..1737fbd8f3 100644 --- a/starsky/starsky/clientapp/src/components/molecules/archive-sidebar/archive-sidebar-label-edit-search-replace.tsx +++ b/starsky/starsky/clientapp/src/components/molecules/archive-sidebar/archive-sidebar-label-edit-search-replace.tsx @@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react"; import { ArchiveContext } from "../../../contexts/archive-context"; import useGlobalSettings from "../../../hooks/use-global-settings"; import useLocation from "../../../hooks/use-location/use-location"; +import { IConnectionDefault } from "../../../interfaces/IConnectionDefault"; import { PageType } from "../../../interfaces/IDetailView"; import { IExifStatus } from "../../../interfaces/IExifStatus"; import { IFileIndexItem } from "../../../interfaces/IFileIndexItem"; @@ -87,8 +88,8 @@ const ArchiveSidebarLabelEditSearchReplace: React.FunctionComponent = () => { return bodyParams; } - function handleFetchPostResponse(anyData: { data: IFileIndexItem[] }) { - const result = new CastToInterface().InfoFileIndexArray(anyData.data); + function handleFetchPostResponse(anyData: IConnectionDefault) { + const result = new CastToInterface().InfoFileIndexArray(anyData.data as IFileIndexItem[]); result.forEach((element) => { if (element.status === IExifStatus.ReadOnly) setIsError(MessageWriteErrorReadOnly); if (element.status === IExifStatus.NotFoundSourceMissing) diff --git a/starsky/starsky/clientapp/src/components/molecules/health-check-for-updates/health-check-for-updates.tsx b/starsky/starsky/clientapp/src/components/molecules/health-check-for-updates/health-check-for-updates.tsx index 07d1522426..0b4cfccf7d 100644 --- a/starsky/starsky/clientapp/src/components/molecules/health-check-for-updates/health-check-for-updates.tsx +++ b/starsky/starsky/clientapp/src/components/molecules/health-check-for-updates/health-check-for-updates.tsx @@ -30,7 +30,10 @@ export function SkipDisplayOfUpdate(): boolean { */ const HealthCheckForUpdates: FunctionComponent = () => { const checkForUpdates = useFetch(new UrlQuery().UrlHealthCheckForUpdates(), "get"); - const releaseInfo = useFetch(new UrlQuery().UrlHealthReleaseInfo(checkForUpdates.data), "get"); + const releaseInfo = useFetch( + new UrlQuery().UrlHealthReleaseInfo(checkForUpdates.data as string), + "get" + ); const settings = useGlobalSettings(); @@ -53,7 +56,7 @@ const HealthCheckForUpdates: FunctionComponent = () => { const MessageNewVersionUpdateHtml = language.token( MessageNewVersionUpdateToken, ["{WhereToFindRelease}", "{otherInfo}"], - [WhereToFindRelease, releaseInfo.data] + [WhereToFindRelease, releaseInfo.data as string] ); return ( diff --git a/starsky/starsky/clientapp/src/components/molecules/health-status-error/health-status-error.tsx b/starsky/starsky/clientapp/src/components/molecules/health-status-error/health-status-error.tsx index cf0623f0a2..8bde66a5a3 100644 --- a/starsky/starsky/clientapp/src/components/molecules/health-status-error/health-status-error.tsx +++ b/starsky/starsky/clientapp/src/components/molecules/health-status-error/health-status-error.tsx @@ -25,12 +25,14 @@ const HealthStatusError: React.FunctionComponent = () => { {MessageHealthStatusCriticalErrors} ]; - if (!healthCheck.data?.entries) { + const healthCheckData = healthCheck.data as { entries: IHealthEntry[] }; + + if (!healthCheckData?.entries) { content.push(
  • BackendServices HTTP StatusCode: {healthCheck.statusCode}
  • ); } else { - healthCheck.data.entries.forEach((entry: IHealthEntry) => { + healthCheckData.entries.forEach((entry: IHealthEntry) => { if (entry.isHealthy) return; content.push(
  • {entry.name}
  • ); }); diff --git a/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/internal/inline-search-suggest.tsx b/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/internal/inline-search-suggest.tsx index 7bb9a980be..aee1aa724e 100644 --- a/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/internal/inline-search-suggest.tsx +++ b/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/internal/inline-search-suggest.tsx @@ -21,9 +21,9 @@ const InlineSearchSuggest: React.FunctionComponent = const history = useLocation(); const settings = useGlobalSettings(); const language = new Language(settings.language); + const dataFeatures = props.featuresResult?.data as IEnvFeatures | undefined; useEffect(() => { - const dataFeatures = props.featuresResult?.data as IEnvFeatures | undefined; if (dataFeatures?.systemTrashEnabled || dataFeatures?.useLocalDesktop) { let newMenu = [...defaultMenu]; if (dataFeatures?.systemTrashEnabled) { @@ -35,7 +35,7 @@ const InlineSearchSuggest: React.FunctionComponent = setDefaultMenu([...newMenu]); } // es_lint-disable-next-line react-hooks/exhaustive-deps // https://github.com/facebook/react/pull/30774 - }, [props.featuresResult, props.featuresResult?.data?.systemTrashEnabled]); + }, [props.featuresResult, dataFeatures?.systemTrashEnabled]); const [defaultMenu, setDefaultMenu] = useState([ { diff --git a/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/menu-inline-search.spec.tsx b/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/menu-inline-search.spec.tsx index 9c24da2e9e..534622e5a5 100644 --- a/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/menu-inline-search.spec.tsx +++ b/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/menu-inline-search.spec.tsx @@ -4,9 +4,9 @@ import { MemoryRouter } from "react-router-dom"; import * as useFetch from "../../../hooks/use-fetch"; import { IConnectionDefault, newIConnectionDefault } from "../../../interfaces/IConnectionDefault"; import { IEnvFeatures } from "../../../interfaces/IEnvFeatures"; -import MenuInlineSearch from "./menu-inline-search"; import * as ArrowKeyDown from "./internal/arrow-key-down"; import * as InlineSearchSuggest from "./internal/inline-search-suggest"; +import MenuInlineSearch from "./menu-inline-search"; describe("menu-inline-search", () => { it("renders", () => { @@ -105,7 +105,7 @@ describe("menu-inline-search", () => { systemTrashEnabled: true, useLocalDesktop: false } as IEnvFeatures - } as IConnectionDefault; + }; it("default menu should show logout and trash in default mode", () => { dataFeaturesExample.data.useLocalDesktop = false; diff --git a/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/menu-inline-search.tsx b/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/menu-inline-search.tsx index bc96e93f22..33c07297b4 100644 --- a/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/menu-inline-search.tsx +++ b/starsky/starsky/clientapp/src/components/molecules/menu-inline-search/menu-inline-search.tsx @@ -30,11 +30,11 @@ const MenuInlineSearch: FunctionComponent = (props) => { // can't set this inside effect or if ==> performance issue, runs to often const responseObject = useFetch(new UrlQuery().UrlSearchSuggestApi(query), "get"); useEffect(() => { - if (!responseObject?.data?.length || responseObject.statusCode !== 200) { + if (!(responseObject?.data as string[])?.length || responseObject.statusCode !== 200) { if (suggest && suggest.length >= 1) setSuggest([]); return; } - const result: Array = [...responseObject.data]; + const result: Array = [...(responseObject?.data as string[])]; setSuggest(result); // to avoid endless loops diff --git a/starsky/starsky/clientapp/src/components/organisms/detail-view-sidebar/update-change.ts b/starsky/starsky/clientapp/src/components/organisms/detail-view-sidebar/update-change.ts index 8815bc8bde..e06b6aa351 100644 --- a/starsky/starsky/clientapp/src/components/organisms/detail-view-sidebar/update-change.ts +++ b/starsky/starsky/clientapp/src/components/organisms/detail-view-sidebar/update-change.ts @@ -84,7 +84,7 @@ export class UpdateChange { item: IConnectionDefault, resolve: (value: string | boolean | PromiseLike) => void ) { - if (item.statusCode !== 200 || !item.data || item.data.length === 0) { + if (item.statusCode !== 200 || !item.data || (item.data as IFileIndexItem[]).length === 0) { resolve("wrong status code or missing data"); return; } diff --git a/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/modal-archive-synchronize-manually.tsx b/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/modal-archive-synchronize-manually.tsx index 73255d14cc..f02135fe13 100644 --- a/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/modal-archive-synchronize-manually.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/modal-archive-synchronize-manually.tsx @@ -65,18 +65,24 @@ const ModalArchiveSynchronizeManually: React.FunctionComponent { - if (anyData.statusCode !== 200 || !anyData.data) { - setGeoSyncPercentage(-1); - return; + FetchGet(new UrlQuery().UrlGeoStatus(new URLPath().encodeURI(parentFolder))).then( + (anyData: unknown) => { + const containerData = anyData as { + statusCode: number; + data: { current: number; total: number }; + }; + if (containerData.statusCode !== 200 || !containerData.data) { + setGeoSyncPercentage(-1); + return; + } + + if (containerData.data?.current === 0 && containerData.data.total === 0) { + setGeoSyncPercentage(0); + return; + } + setGeoSyncPercentage((containerData.data.current / containerData.data.total) * 100); } - - if (anyData.data.current === 0 && anyData.data.total === 0) { - setGeoSyncPercentage(0); - return; - } - setGeoSyncPercentage((anyData.data.current / anyData.data.total) * 100); - }); + ); } useInterval(() => fetchGeoSyncStatus(), 10000); diff --git a/starsky/starsky/clientapp/src/components/organisms/modal-download/modal-download.tsx b/starsky/starsky/clientapp/src/components/organisms/modal-download/modal-download.tsx index 2cef177cdc..9c21b5a99b 100644 --- a/starsky/starsky/clientapp/src/components/organisms/modal-download/modal-download.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/modal-download/modal-download.tsx @@ -72,8 +72,8 @@ const ModalDownload: React.FunctionComponent = (props) => { setIsProcessing(ProcessingState.fail); return; } - setCreateZipKey(zipKeyResult.data); - await ExportIntervalUpdate(zipKeyResult.data, setIsProcessing); + setCreateZipKey(zipKeyResult.data as string); + await ExportIntervalUpdate(zipKeyResult.data as string, setIsProcessing); } useInterval(async () => { diff --git a/starsky/starsky/clientapp/src/components/organisms/modal-edit-date-time/modal-edit-datetime.tsx b/starsky/starsky/clientapp/src/components/organisms/modal-edit-date-time/modal-edit-datetime.tsx index 66dc8f4f08..bc9df65f90 100644 --- a/starsky/starsky/clientapp/src/components/organisms/modal-edit-date-time/modal-edit-datetime.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/modal-edit-date-time/modal-edit-datetime.tsx @@ -65,7 +65,7 @@ const ModalEditDatetime: React.FunctionComponent = (props) FetchPost(updateApiUrl, bodyParams.toString()).then((result) => { if (result.statusCode !== 200) return; - props.handleExit(result.data); + props.handleExit(result.data as IFileIndexItem[]); }); } diff --git a/starsky/starsky/clientapp/src/components/organisms/modal-geo/internal/update-geo-location.ts b/starsky/starsky/clientapp/src/components/organisms/modal-geo/internal/update-geo-location.ts index 0e0529fcaa..7f0c9890d6 100644 --- a/starsky/starsky/clientapp/src/components/organisms/modal-geo/internal/update-geo-location.ts +++ b/starsky/starsky/clientapp/src/components/organisms/modal-geo/internal/update-geo-location.ts @@ -32,7 +32,7 @@ export async function UpdateGeoLocation( new UrlQuery().UrlReverseLookup(location.latitude.toString(), location.longitude.toString()) ); if (reverseGeoCodeResult.statusCode === 200) { - model = reverseGeoCodeResult.data; + model = reverseGeoCodeResult.data as IGeoLocationModel; bodyParams.append("locationCity", model.locationCity); bodyParams.append("locationCountry", model.locationCountry); bodyParams.append("locationCountryCode", model.locationCountryCode); diff --git a/starsky/starsky/clientapp/src/components/organisms/modal-move-file/modal-move-file.tsx b/starsky/starsky/clientapp/src/components/organisms/modal-move-file/modal-move-file.tsx index 1f0036f167..8ac0f72165 100644 --- a/starsky/starsky/clientapp/src/components/organisms/modal-move-file/modal-move-file.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/modal-move-file/modal-move-file.tsx @@ -50,7 +50,7 @@ const ModalMoveFile: React.FunctionComponent = (props) => { const resultDo = await FetchPost(new UrlQuery().UrlDiskRename(), bodyParams.toString()); - if (!resultDo.data || resultDo.data.length === 0 || !resultDo.data[0].status) { + if (!Array.isArray(resultDo.data) || resultDo.data.length === 0 || !resultDo.data[0].status) { console.error("server error"); setError("Server error"); return null; diff --git a/starsky/starsky/clientapp/src/components/organisms/modal-move-folder-to-trash/modal-move-folder-to-trash.tsx b/starsky/starsky/clientapp/src/components/organisms/modal-move-folder-to-trash/modal-move-folder-to-trash.tsx index 51c98bba9f..e487187eab 100644 --- a/starsky/starsky/clientapp/src/components/organisms/modal-move-folder-to-trash/modal-move-folder-to-trash.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/modal-move-folder-to-trash/modal-move-folder-to-trash.tsx @@ -47,7 +47,7 @@ const ModalMoveFolderToTrash: React.FunctionComponent>(useSocketsEventName, { bubbles: false, detail: { - data: result.data, + data: result.data as IFileIndexItem[], type: "move-folder-to-trash-internal" } }) diff --git a/starsky/starsky/clientapp/src/components/organisms/modal-publish/modal-publish.tsx b/starsky/starsky/clientapp/src/components/organisms/modal-publish/modal-publish.tsx index 5f9a5507b9..fb1ad19045 100644 --- a/starsky/starsky/clientapp/src/components/organisms/modal-publish/modal-publish.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/modal-publish/modal-publish.tsx @@ -65,13 +65,14 @@ const ModalPublish: React.FunctionComponent = (props) => { setIsProcessing(ProcessingState.server); const zipKeyResult = await FetchPost(new UrlQuery().UrlPublishCreate(), bodyParams.toString()); + const zipKeyResultData = zipKeyResult.data as string; if (zipKeyResult.statusCode !== 200 || !zipKeyResult.data) { setIsProcessing(ProcessingState.fail); return; } - setCreateZipKey(zipKeyResult.data); - await ExportIntervalUpdate(zipKeyResult.data, setIsProcessing); + setCreateZipKey(zipKeyResultData); + await ExportIntervalUpdate(zipKeyResultData, setIsProcessing); } const allPublishProfiles = useFetch(new UrlQuery().UrlPublish(), "get").data as @@ -100,7 +101,9 @@ const ModalPublish: React.FunctionComponent = (props) => { FetchGet(new UrlQuery().UrlPublishExist(toUpdateItemName), CacheControl).then((result) => { if (result.statusCode !== 200) return; - setExistItemName(result.data); + + const resultData = result.data as boolean; + setExistItemName(resultData); }); } diff --git a/starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.spec.tsx b/starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.spec.tsx index dbdb21e1a1..228ea0d76d 100644 --- a/starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.spec.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.spec.tsx @@ -121,7 +121,7 @@ describe("PreferencesAppSettingsDesktop", () => { expect(formControlSpy).toHaveBeenCalledWith( { children: "/test", - contentEditable: undefined, + contentEditable: false, name: "tags", onBlur: expect.anything(), spellcheck: true diff --git a/starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx b/starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx index 8076e54942..c74eb30dbb 100644 --- a/starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx @@ -92,9 +92,9 @@ const PreferencesAppSettingsDesktop: React.FunctionComponent = () => { // roles const permissionsData = useFetch(new UrlQuery().UrlAccountPermissions(), "get"); - const isAppSettingsWrite = permissionsData?.data?.includes( - new UrlQuery().KeyAccountPermissionAppSettingsWrite() - ); + const isAppSettingsWrite = + Array.isArray(permissionsData?.data) && + permissionsData.data.includes(new UrlQuery().KeyAccountPermissionAppSettingsWrite()); const settings = useGlobalSettings(); diff --git a/starsky/starsky/clientapp/src/components/organisms/preferences-app-settings-storage-folder/preferences-app-settings-storage-folder.tsx b/starsky/starsky/clientapp/src/components/organisms/preferences-app-settings-storage-folder/preferences-app-settings-storage-folder.tsx index 02e037d329..6ee2bf59fa 100644 --- a/starsky/starsky/clientapp/src/components/organisms/preferences-app-settings-storage-folder/preferences-app-settings-storage-folder.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/preferences-app-settings-storage-folder/preferences-app-settings-storage-folder.tsx @@ -44,11 +44,12 @@ const PreferencesAppSettingsStorageFolder: React.FunctionComponent = () => { useEffect(() => { function permissions(): boolean { - if (!permissionsData?.data?.includes || permissionsData?.statusCode !== 200) { + const data = permissionsData?.data as string[]; + if (!data?.includes || permissionsData?.statusCode !== 200) { return false; } // AppSettingsWrite - return permissionsData.data.includes(new UrlQuery().KeyAccountPermissionAppSettingsWrite()); + return data.includes(new UrlQuery().KeyAccountPermissionAppSettingsWrite()); } setIsEnabled(permissions()); diff --git a/starsky/starsky/clientapp/src/components/organisms/preferences-password/preferences-password.tsx b/starsky/starsky/clientapp/src/components/organisms/preferences-password/preferences-password.tsx index 35e484369b..ec147464b6 100644 --- a/starsky/starsky/clientapp/src/components/organisms/preferences-password/preferences-password.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/preferences-password/preferences-password.tsx @@ -54,7 +54,7 @@ const PreferencesPassword: React.FunctionComponent = () => { bodyParams.toString() ); setLoading(false); - if (response.statusCode === 200 && response.data?.success) { + if (response.statusCode === 200 && (response.data as { success: boolean }).success) { setError(MessagePasswordChanged); return; } diff --git a/starsky/starsky/clientapp/src/components/organisms/preferences-username/preferences-username.tsx b/starsky/starsky/clientapp/src/components/organisms/preferences-username/preferences-username.tsx index 3fb3be8b29..2daef2dca3 100644 --- a/starsky/starsky/clientapp/src/components/organisms/preferences-username/preferences-username.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/preferences-username/preferences-username.tsx @@ -11,11 +11,18 @@ const PreferencesUsername: React.FunctionComponent = () => { const MessageUsername = language.key(localization.MessageUsername); const MessageRole = language.key(localization.MessageRole); + interface AccountStatusData { + credentialsIdentifiers: string[]; + roleCode: string; + } + const accountStatus = useFetch(new UrlQuery().UrlAccountStatus(), "get"); + const accountStatusData = accountStatus?.data as AccountStatusData; + let userName = language.key(localization.MessageUnknownUsername); - if (accountStatus.statusCode === 200 && accountStatus?.data?.credentialsIdentifiers[0]) { - userName = accountStatus?.data?.credentialsIdentifiers[0]; + if (accountStatus.statusCode === 200 && accountStatusData?.credentialsIdentifiers[0]) { + userName = accountStatusData?.credentialsIdentifiers[0]; if (userName === "mail@localhost") { userName = language.key(localization.MessageDesktopMailLocalhostUsername); } @@ -31,7 +38,7 @@ const PreferencesUsername: React.FunctionComponent = () => { {userName}
    {MessageRole}
    -
    {accountStatus?.data?.roleCode}
    +
    {accountStatusData?.roleCode}
    ); }; diff --git a/starsky/starsky/clientapp/src/hooks/use-gestures/IHandlers.types.ts b/starsky/starsky/clientapp/src/hooks/use-gestures/IHandlers.types.ts index edbcbdb514..24161681d9 100644 --- a/starsky/starsky/clientapp/src/hooks/use-gestures/IHandlers.types.ts +++ b/starsky/starsky/clientapp/src/hooks/use-gestures/IHandlers.types.ts @@ -1,3 +1,5 @@ +import { ICurrentTouches } from "./ICurrentTouches.types"; + export interface IHandlers { onPanStart?: () => void; onPanMove?: (ev: TouchEvent) => void; @@ -14,3 +16,7 @@ export interface IHandlers { onPinchChanged?: () => void; onPinchEnd?: () => void; } + +export interface IHandlersMapper { + [key: string]: (event?: ICurrentTouches) => void; +} diff --git a/starsky/starsky/clientapp/src/hooks/use-gestures/call-handler.spec.ts b/starsky/starsky/clientapp/src/hooks/use-gestures/call-handler.spec.ts index 5ce528dfbd..61270ee7e2 100644 --- a/starsky/starsky/clientapp/src/hooks/use-gestures/call-handler.spec.ts +++ b/starsky/starsky/clientapp/src/hooks/use-gestures/call-handler.spec.ts @@ -1,20 +1,21 @@ import { ICurrentTouches } from "./ICurrentTouches.types"; +import { IHandlers } from "./IHandlers.types"; import { callHandler } from "./call-handler"; describe("callHandler", () => { describe("callHandler", () => { it("should call test function", () => { - const handlers = { test: jest.fn() } as any; - callHandler("test", true as any, handlers); + const handlers = { test: jest.fn() } as unknown as IHandlers; + callHandler("test", true as unknown as ICurrentTouches, handlers); - expect(handlers.test).toHaveBeenCalled(); + expect((handlers as { test: jest.Mock }).test).toHaveBeenCalled(); }); it("should not call test function", () => { - const handlers = { test: jest.fn() } as any; - callHandler(undefined as any, true as any, handlers); + const handlers = { test: jest.fn() } as unknown as IHandlers; + callHandler(undefined as unknown as string, true as unknown as ICurrentTouches, handlers); - expect(handlers.test).toHaveBeenCalledTimes(0); + expect((handlers as { test: jest.Mock }).test).toHaveBeenCalledTimes(0); }); }); diff --git a/starsky/starsky/clientapp/src/hooks/use-gestures/call-handler.ts b/starsky/starsky/clientapp/src/hooks/use-gestures/call-handler.ts index ce23277ea9..2f08052c17 100644 --- a/starsky/starsky/clientapp/src/hooks/use-gestures/call-handler.ts +++ b/starsky/starsky/clientapp/src/hooks/use-gestures/call-handler.ts @@ -1,10 +1,10 @@ import { ICurrentTouches } from "./ICurrentTouches.types"; -import { IHandlers } from "./IHandlers.types"; +import { IHandlers, IHandlersMapper } from "./IHandlers.types"; export const callHandler = ( eventName: string, event: ICurrentTouches, - handlers: IHandlers | undefined + handlers: IHandlers | undefined | IHandlersMapper ) => { if (!handlers) { throw new Error(`handler ${eventName} is missing`); @@ -12,9 +12,12 @@ export const callHandler = ( if ( eventName && - (handlers as any)[eventName] && - typeof (handlers as any)[eventName] === "function" + handlers[eventName as keyof IHandlers] && + typeof handlers[eventName as keyof IHandlers] === "function" ) { - (handlers as any)[eventName](event); + const handler = handlers[eventName as keyof IHandlers]; + if (handler) { + (handler as (e: ICurrentTouches) => void)(event); + } } }; diff --git a/starsky/starsky/clientapp/src/hooks/use-gestures/debounce.ts b/starsky/starsky/clientapp/src/hooks/use-gestures/debounce.ts index 912c6864bd..fb6894a296 100644 --- a/starsky/starsky/clientapp/src/hooks/use-gestures/debounce.ts +++ b/starsky/starsky/clientapp/src/hooks/use-gestures/debounce.ts @@ -1,6 +1,6 @@ -export const debounce = (func: any, wait: number) => { - let timeout: any; - return function (...args: any) { +export const debounce = (func: (...args: unknown[]) => void, wait: number) => { + let timeout: ReturnType; + return function (...args: unknown[]) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore // eslint-disable-next-line @typescript-eslint/no-this-alias diff --git a/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.spec.tsx b/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.spec.tsx index 5a7cceb064..57b016aa49 100644 --- a/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.spec.tsx +++ b/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.spec.tsx @@ -1,10 +1,11 @@ -import { act, createEvent, fireEvent, render } from "@testing-library/react"; -import React, { useRef, useState } from "react"; +import { createEvent, fireEvent, render } from "@testing-library/react"; +import React, { act, useRef, useState } from "react"; import { mountReactHook } from "../___tests___/test-hook"; import * as callHandler from "./call-handler"; import * as debounce from "./debounce"; import * as getCurrentTouchesAll from "./get-current-touches"; import { getCurrentTouches } from "./get-current-touches"; +import { ICurrentTouches } from "./ICurrentTouches.types"; import { Pointer } from "./pointer"; import { getAngleDeg, getDistance, useGestures } from "./use-gestures"; @@ -48,7 +49,7 @@ describe("useGestures", () => { const p = getDistance(new Pointer({ clientX: 0, clientY: 0 }), { x: undefined, y: undefined - } as any); + } as unknown as Pointer); expect(p).toBe(0); }); @@ -74,7 +75,7 @@ describe("useGestures", () => { const p = getAngleDeg(new Pointer({ clientX: 0, clientY: 0 }), { x: undefined, y: undefined - } as any); + } as unknown as Pointer); expect(p).toBe(0); }); @@ -116,10 +117,10 @@ describe("useGestures", () => { const t = { current: { x: 1, y: 1 } }; const result = getCurrentTouches( - sourceEvent as any, - newTouches as any, - prevTouch as any, - t as any + sourceEvent as unknown as globalThis.TouchEvent, + newTouches as unknown as TouchList, + prevTouch as unknown as ICurrentTouches, + t as React.MutableRefObject ); expect(result.delta).toBe(20); @@ -150,10 +151,10 @@ describe("useGestures", () => { const t = { current: { x: 1, y: 1 } }; const result = getCurrentTouches( - sourceEvent as any, - newTouches as any, - prevTouch as any, - t as any + sourceEvent as unknown as globalThis.TouchEvent, + newTouches as unknown as TouchList, + prevTouch as unknown as ICurrentTouches, + t as React.MutableRefObject ); expect(result.angleDeg).toBe(180); @@ -167,22 +168,22 @@ describe("useGestures", () => { { clientX: 10, clientY: 0 - } as any + } ] - }; + } as TouchEventInit; const exampleDoubleTouches = { touches: [ { clientX: 10, clientY: 0 - } as any, + }, { clientX: 10, clientY: 0 - } as any + } ] - }; + } as TouchEventInit; it("check if is called once", () => { jest.useFakeTimers(); @@ -220,7 +221,7 @@ describe("useGestures", () => { expect(callHandlerSpy).toHaveBeenCalled(); expect(callHandlerSpy).toHaveBeenCalledWith("onPanStart", expect.anything(), undefined); - const component = hook.componentMount as any; + const component = hook.componentMount; component.unmount(); }); @@ -244,7 +245,7 @@ describe("useGestures", () => { expect(callHandlerSpy).toHaveBeenCalled(); expect(callHandlerSpy).toHaveBeenCalledWith("onPinchStart", expect.anything(), undefined); - const component = hook.componentMount as any; + const component = hook.componentMount; component.unmount(); }); @@ -268,7 +269,7 @@ describe("useGestures", () => { expect(callHandlerSpy).toHaveBeenCalled(); expect(callHandlerSpy).toHaveBeenCalledWith("onPanMove", expect.anything(), undefined); - const component = hook.componentMount as any; + const component = hook.componentMount; component.unmount(); }); @@ -280,7 +281,7 @@ describe("useGestures", () => { return { deltaX: undefined, deltaY: undefined - } as any; + } as unknown as ICurrentTouches; }); jest.spyOn(callHandler, "callHandler").mockImplementationOnce(() => {}); @@ -305,7 +306,7 @@ describe("useGestures", () => { expect(debounceSpy).toHaveBeenCalledTimes(0); - const component = hook.componentMount as any; + const component = hook.componentMount; component.unmount(); debounceSpy.mockReset(); }); @@ -315,7 +316,7 @@ describe("useGestures", () => { return { deltaX: 30, deltaY: 0 - } as any; + } as unknown as ICurrentTouches; }); const debounceAnonymousFnSpy = jest.fn(); @@ -341,7 +342,7 @@ describe("useGestures", () => { expect(debounceSpy).toHaveBeenCalled(); expect(debounceAnonymousFnSpy).toHaveBeenCalledWith("onSwipeRight", {}, "swipeRight"); - const component = hook.componentMount as any; + const component = hook.componentMount; component.unmount(); }); @@ -353,7 +354,7 @@ describe("useGestures", () => { return { deltaX: -30, deltaY: 0 - } as any; + } as unknown as ICurrentTouches; }); jest.spyOn(callHandler, "callHandler").mockImplementationOnce(() => {}); @@ -377,7 +378,7 @@ describe("useGestures", () => { expect(debounceSpy).toHaveBeenCalled(); expect(debounceAnonymousFnSpy).toHaveBeenCalledWith("onSwipeLeft", {}, "swipeLeft"); - const component = hook.componentMount as any; + const component = hook.componentMount; component.unmount(); }); @@ -389,7 +390,7 @@ describe("useGestures", () => { return { deltaX: 0, deltaY: 30 - } as any; + } as unknown as ICurrentTouches; }); jest.spyOn(callHandler, "callHandler").mockImplementationOnce(() => {}); @@ -413,7 +414,7 @@ describe("useGestures", () => { expect(debounceSpy).toHaveBeenCalled(); expect(debounceAnonymousFnSpy).toHaveBeenCalledWith("onSwipeDown", {}, "swipeDown"); - const component = hook.componentMount as any; + const component = hook.componentMount; component.unmount(); }); @@ -425,7 +426,7 @@ describe("useGestures", () => { return { deltaX: 0, deltaY: -30 - } as any; + } as unknown as ICurrentTouches; }); jest.spyOn(callHandler, "callHandler").mockImplementationOnce(() => {}); @@ -450,7 +451,7 @@ describe("useGestures", () => { expect(debounceSpy).toHaveBeenCalled(); expect(debounceAnonymousFnSpy).toHaveBeenCalledWith("onSwipeUp", {}, "swipeUp"); - const component = hook.componentMount as any; + const component = hook.componentMount; component.unmount(); }); @@ -477,7 +478,7 @@ describe("useGestures", () => { expect(callHandlerSpy).toHaveBeenCalled(); expect(callHandlerSpy).toHaveBeenCalledWith("onPinchChanged", undefined, undefined); - const component = hook.componentMount as any; + const component = hook.componentMount; component.unmount(); }); @@ -531,7 +532,7 @@ describe("useGestures", () => { expect(callHandlerSpy).toHaveBeenCalled(); expect(callHandlerSpy).toHaveBeenCalledWith("onPinchEnd", undefined, undefined); - const component = hook.componentMount as any; + const component = hook.componentMount; component.unmount(); }); @@ -564,7 +565,7 @@ describe("useGestures", () => { expect(callHandlerSpy).toHaveBeenCalled(); expect(callHandlerSpy).toHaveBeenNthCalledWith(1, "onPanEnd", undefined, undefined); expect(callHandlerSpy).toHaveBeenNthCalledWith(2, "onGesture1End", undefined, undefined); - const component = hook.componentMount as any; + const component = hook.componentMount; component.unmount(); }); }); diff --git a/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.ts b/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.ts index 9dba81dfbe..3179f57188 100644 --- a/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.ts +++ b/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.ts @@ -95,13 +95,15 @@ const executeTouchMove = ( } if (eventName) { - debounce( - (eventNameScoped: string, touchesScoped: ICurrentTouches, theGestureScoped: string) => { - callHandler(eventNameScoped, touchesScoped, handlers); - setGesture(theGestureScoped); - }, - 100 - )(eventName, touches, theGesture); + debounce((...args: unknown[]) => { + const [eventNameScoped, touchesScoped, theGestureScoped] = args as [ + string, + ICurrentTouches, + string + ]; + callHandler(eventNameScoped, touchesScoped, handlers); + setGesture(theGestureScoped); + }, 100)(eventName, touches, theGesture); } }; diff --git a/starsky/starsky/clientapp/src/hooks/use-intersection-observer.spec.tsx b/starsky/starsky/clientapp/src/hooks/use-intersection-observer.spec.tsx index 6aab734b09..dd5aa2d8ea 100644 --- a/starsky/starsky/clientapp/src/hooks/use-intersection-observer.spec.tsx +++ b/starsky/starsky/clientapp/src/hooks/use-intersection-observer.spec.tsx @@ -1,6 +1,9 @@ import { render } from "@testing-library/react"; -import React, { useRef } from "react"; -import useIntersection, { newIntersectionObserver } from "./use-intersection-observer"; +import React, { MutableRefObject, useRef } from "react"; +import useIntersection, { + IntersectionOptions, + newIntersectionObserver +} from "./use-intersection-observer"; describe("useIntersection", () => { const IntersectionComponentTest = () => { @@ -28,7 +31,12 @@ describe("useIntersection", () => { const target = useRef(null); render(
    ); const tagRef = { current: { scrollHeight: 100, clientHeight: 200 } }; - newIntersectionObserver(target, jest.fn(), true, tagRef); + newIntersectionObserver( + target, + jest.fn(), + true, + tagRef as unknown as MutableRefObject + ); return null; }; diff --git a/starsky/starsky/clientapp/src/hooks/use-intersection-observer.ts b/starsky/starsky/clientapp/src/hooks/use-intersection-observer.ts index 12ff220d54..3b6cf78ec2 100644 --- a/starsky/starsky/clientapp/src/hooks/use-intersection-observer.ts +++ b/starsky/starsky/clientapp/src/hooks/use-intersection-observer.ts @@ -6,7 +6,7 @@ type IntersectionChangeHandler = (entry: IntersectionObserverEntry) => void; // credits for: https://github.com/cats-oss/use-intersection -type IntersectionOptions = { +export type IntersectionOptions = { root?: React.RefObject; rootMargin?: string; threshold?: number | number[]; @@ -16,9 +16,9 @@ type IntersectionOptions = { export const newIntersectionObserver = ( ref: React.RefObject, - setIntersecting: React.Dispatch, + setIntersecting: React.Dispatch>, once: boolean | undefined, - optsRef: React.MutableRefObject, + optsRef: React.MutableRefObject, callback?: IntersectionChangeHandler ): IntersectionObserver => { const observer = new IntersectionObserver( diff --git a/starsky/starsky/clientapp/src/hooks/use-interval.spec.tsx b/starsky/starsky/clientapp/src/hooks/use-interval.spec.tsx index 5558dc2e31..b5ac105e61 100644 --- a/starsky/starsky/clientapp/src/hooks/use-interval.spec.tsx +++ b/starsky/starsky/clientapp/src/hooks/use-interval.spec.tsx @@ -24,7 +24,7 @@ describe("useInterval", () => { it("check if setInterval is called", () => { const clearIntervalSpy = jest.spyOn(window, "setInterval").mockImplementationOnce(() => { - return {} as any; + return {} as NodeJS.Timeout; }); const component = render(); diff --git a/starsky/starsky/clientapp/src/hooks/use-keyboard/use-hotkeys.tsx b/starsky/starsky/clientapp/src/hooks/use-keyboard/use-hotkeys.tsx index a9df836098..0dcdb96aa3 100644 --- a/starsky/starsky/clientapp/src/hooks/use-keyboard/use-hotkeys.tsx +++ b/starsky/starsky/clientapp/src/hooks/use-keyboard/use-hotkeys.tsx @@ -34,7 +34,7 @@ function useHotKeys( /* should do nothing, you should overwrite this */ }, // eslint-disable-next-line @typescript-eslint/no-unused-vars - _dependencies: any = [] + _dependencies: React.DependencyList = [] ) { useEffect(() => { const handler = function (event: KeyboardEvent) { diff --git a/starsky/starsky/clientapp/src/hooks/use-keyboard/use-keyboard-event.spec.tsx b/starsky/starsky/clientapp/src/hooks/use-keyboard/use-keyboard-event.spec.tsx index efd5ff9627..35d3f96a21 100644 --- a/starsky/starsky/clientapp/src/hooks/use-keyboard/use-keyboard-event.spec.tsx +++ b/starsky/starsky/clientapp/src/hooks/use-keyboard/use-keyboard-event.spec.tsx @@ -6,7 +6,7 @@ describe("useKeyboardEvent", () => { interface UseKeyboardEventComponentTestProps { regex: RegExp; callback: (arg0: KeyboardEvent) => void; - dependencies: any[]; + dependencies: React.DependencyList; } const UseKeyboardEventComponentTest: React.FunctionComponent = diff --git a/starsky/starsky/clientapp/src/hooks/use-keyboard/use-keyboard-event.ts b/starsky/starsky/clientapp/src/hooks/use-keyboard/use-keyboard-event.ts index c1ab48217c..358f0b4387 100644 --- a/starsky/starsky/clientapp/src/hooks/use-keyboard/use-keyboard-event.ts +++ b/starsky/starsky/clientapp/src/hooks/use-keyboard/use-keyboard-event.ts @@ -19,7 +19,7 @@ import { useEffect } from "react"; function useKeyboardEvent( regex: RegExp, callback: (arg0: KeyboardEvent) => void, - dependencies: any = [] + dependencies: React.DependencyList = [] ) { useEffect(() => { const handler = function (event: KeyboardEvent) { diff --git a/starsky/starsky/clientapp/src/hooks/use-location/use-location.spec.tsx b/starsky/starsky/clientapp/src/hooks/use-location/use-location.spec.tsx index 59c93b6de9..30137fc5b4 100644 --- a/starsky/starsky/clientapp/src/hooks/use-location/use-location.spec.tsx +++ b/starsky/starsky/clientapp/src/hooks/use-location/use-location.spec.tsx @@ -3,7 +3,7 @@ import React from "react"; import useLocation from "./use-location"; describe("useLocation", () => { - const UseLocationComponentTest: React.FunctionComponent = () => { + const UseLocationComponentTest: React.FunctionComponent = () => { useLocation(); return null; }; diff --git a/starsky/starsky/clientapp/src/hooks/use-searchlist.ts b/starsky/starsky/clientapp/src/hooks/use-searchlist.ts index 13396ea41f..0d0a762262 100644 --- a/starsky/starsky/clientapp/src/hooks/use-searchlist.ts +++ b/starsky/starsky/clientapp/src/hooks/use-searchlist.ts @@ -96,8 +96,8 @@ export const fetchContentUseSearchList = async ( archiveMedia.data.colorClassUsage = []; archiveMedia.data.colorClassActiveList = []; setArchive(archiveMedia.data); - } catch (e: any) { - if (e?.message?.indexOf("aborted") >= 0) { + } catch (e: unknown) { + if ((e as Error)?.message?.indexOf("aborted") >= 0) { console.log("useSearchList aborted"); return; } diff --git a/starsky/starsky/clientapp/src/interfaces/IConnectionDefault.ts b/starsky/starsky/clientapp/src/interfaces/IConnectionDefault.ts index 76865974c4..c36010f349 100644 --- a/starsky/starsky/clientapp/src/interfaces/IConnectionDefault.ts +++ b/starsky/starsky/clientapp/src/interfaces/IConnectionDefault.ts @@ -1,5 +1,5 @@ export interface IConnectionDefault { - data: any; + data: unknown; statusCode: number; } export function newIConnectionDefault(): IConnectionDefault { diff --git a/starsky/starsky/clientapp/src/shared/update-relative-object.ts b/starsky/starsky/clientapp/src/shared/update-relative-object.ts index 304e2e5620..7b9a2e6b7f 100644 --- a/starsky/starsky/clientapp/src/shared/update-relative-object.ts +++ b/starsky/starsky/clientapp/src/shared/update-relative-object.ts @@ -31,8 +31,8 @@ export class UpdateRelativeObject { rejects(new Error("status code not 200")); return; } - setRelativeObjects(result.data); - resolve(result.data); + setRelativeObjects(result.data as React.SetStateAction); + resolve(result.data as IRelativeObjects); }) .catch((err: Error) => { console.error(err);