Skip to content

Commit

Permalink
Fix type issues (#4176)
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteStash authored Oct 16, 2023
1 parent 90dfaf6 commit 409f8fc
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 86 deletions.
5 changes: 1 addition & 4 deletions ui/v2.5/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ export const App: React.FC = () => {
}
);

const newMessages = flattenMessages(mergedMessages) as Record<
string,
string
>;
const newMessages = flattenMessages(mergedMessages);

yup.setLocale({
mixed: {
Expand Down
4 changes: 2 additions & 2 deletions ui/v2.5/src/components/List/ListFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const ListFilter: React.FC<IListFilterProps> = ({
// clear search input when filter is cleared
useEffect(() => {
if (!filter.searchTerm) {
queryRef.current.value = "";
if (queryRef.current) queryRef.current.value = "";
setQueryClearShowing(false);
}
}, [filter.searchTerm, queryRef]);
Expand Down Expand Up @@ -139,7 +139,7 @@ export const ListFilter: React.FC<IListFilterProps> = ({
}

function onClearQuery() {
queryRef.current.value = "";
if (queryRef.current) queryRef.current.value = "";
searchQueryUpdated("");
setQueryFocus();
setQueryClearShowing(false);
Expand Down
3 changes: 1 addition & 2 deletions ui/v2.5/src/components/MainNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ export const MainNavbar: React.FC = () => {
}, [configuration]);

// react-bootstrap typing bug
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const navbarRef = useRef<any>();
const navbarRef = useRef<HTMLElement | null>(null);
const intl = useIntl();

const maybeCollapse = useCallback(
Expand Down
3 changes: 1 addition & 2 deletions ui/v2.5/src/components/Shared/DetailItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { FormattedMessage } from "react-intl";

interface IDetailItem {
id?: string | null;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value?: any;
value?: React.ReactNode;
title?: string;
fullWidth?: boolean;
}
Expand Down
3 changes: 1 addition & 2 deletions ui/v2.5/src/components/Shared/ScrapeDialog/scrapeResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export class ObjectListScrapeResult<
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function hasScrapedValues(values: ScrapeResult<any>[]) {
export function hasScrapedValues(values: { scraped: boolean }[]): boolean {
return values.some((r) => r.scraped);
}
6 changes: 3 additions & 3 deletions ui/v2.5/src/components/Tagger/studios/StashSearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import StudioModal from "../scenes/StudioModal";
import { faTags } from "@fortawesome/free-solid-svg-icons";
import { useStudioCreate } from "src/core/StashService";
import { useIntl } from "react-intl";
import { apolloError } from "src/utils";

interface IStashSearchResultProps {
studio: GQL.SlimStudioDataFragment;
Expand Down Expand Up @@ -75,9 +76,8 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
});
input.parent_id = parentRes.data?.studioCreate?.id;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
handleSaveError(parentInput.name, e.message ?? "");
} catch (e) {
handleSaveError(parentInput.name, apolloError(e));
}
}

Expand Down
6 changes: 3 additions & 3 deletions ui/v2.5/src/components/Tagger/studios/StudioTagger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import StudioConfig from "./Config";
import { LOCAL_FORAGE_KEY, ITaggerConfig, initialConfig } from "../constants";
import StudioModal from "../scenes/StudioModal";
import { useUpdateStudio } from "../queries";
import { apolloError } from "src/utils";
import { faStar, faTags } from "@fortawesome/free-solid-svg-icons";

type JobFragment = Pick<
Expand Down Expand Up @@ -431,9 +432,8 @@ const StudioTaggerList: React.FC<IStudioTaggerListProps> = ({
});
input.parent_id = parentRes.data?.studioCreate?.id;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
handleSaveError(studioID, parentInput.name, e.message ?? "");
} catch (e) {
handleSaveError(studioID, parentInput.name, apolloError(e));
}
}

Expand Down
9 changes: 3 additions & 6 deletions ui/v2.5/src/core/StashService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,7 @@ export const useImagesDestroy = (input: GQL.ImagesDestroyInput) =>

function updateImageIncrementO(id: string) {
return (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
cache: ApolloCache<any>,
cache: ApolloCache<Record<string, StoreObject>>,
result: FetchResult<GQL.ImageIncrementOMutation>
) => {
const updatedOCount = result.data?.imageIncrementO;
Expand Down Expand Up @@ -893,8 +892,7 @@ export const mutateImageIncrementO = (id: string) =>

function updateImageDecrementO(id: string) {
return (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
cache: ApolloCache<any>,
cache: ApolloCache<Record<string, StoreObject>>,
result: FetchResult<GQL.ImageDecrementOMutation>
) => {
const updatedOCount = result.data?.imageDecrementO;
Expand Down Expand Up @@ -949,8 +947,7 @@ export const mutateImageDecrementO = (id: string) =>

function updateImageResetO(id: string) {
return (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
cache: ApolloCache<any>,
cache: ApolloCache<Record<string, StoreObject>>,
result: FetchResult<GQL.ImageResetOMutation>
) => {
const updatedOCount = result.data?.imageResetO;
Expand Down
6 changes: 2 additions & 4 deletions ui/v2.5/src/hooks/Lightbox/Lightbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ export const LightboxComponent: React.FC<IProps> = ({
if (isVisible) {
if (index === null) setIndex(initialIndex);
document.body.style.overflow = "hidden";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(Mousetrap as any).pause();
Mousetrap.pause();
}
}, [initialIndex, isVisible, setIndex, index]);

Expand All @@ -323,8 +322,7 @@ export const LightboxComponent: React.FC<IProps> = ({

hide();
document.body.style.overflow = "auto";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(Mousetrap as any).unpause();
Mousetrap.unpause();
}, [isFullscreen, hide]);

const handleClose = (e: React.MouseEvent<HTMLDivElement>) => {
Expand Down
44 changes: 4 additions & 40 deletions ui/v2.5/src/hooks/PageVisibility.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,14 @@
import { useEffect, useRef } from "react";
import { useEffect } from "react";

const usePageVisibility = (
visibilityChangeCallback: (hidden: boolean) => void
): void => {
const savedVisibilityChangedCallback = useRef<(hidden: boolean) => void>();

useEffect(() => {
// resolve event names for different browsers
let hidden = "";
let visibilityChange = "";

if (typeof document.hidden !== "undefined") {
hidden = "hidden";
visibilityChange = "visibilitychange";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} else if (typeof (document as any).msHidden !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} else if (typeof (document as any).webkitHidden !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}

if (
typeof document.addEventListener === "undefined" ||
hidden === undefined
) {
// this browser doesn't have support for modern event listeners or the Page Visibility API
return;
}

savedVisibilityChangedCallback.current = visibilityChangeCallback;

function fireCallback() {
const callback = savedVisibilityChangedCallback.current;
if (callback) {
const isHidden = document.visibilityState !== "visible";
callback(isHidden);
}
}

document.addEventListener(visibilityChange, fireCallback);
const callback = () => visibilityChangeCallback(document.hidden);
document.addEventListener("visibilitychange", callback);

return () => {
document.removeEventListener(visibilityChange, fireCallback);
document.removeEventListener("visibilitychange", callback);
};
}, [visibilityChangeCallback]);
};
Expand Down
8 changes: 4 additions & 4 deletions ui/v2.5/src/hooks/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ function createHookObject(toastFunc: (toast: IToast) => void) {
return {
success: toastFunc,
error: (error: unknown) => {
/* eslint-disable @typescript-eslint/no-explicit-any, no-console */
/* eslint-disable no-console */
let message: string;
if (error instanceof Error) {
message = error.message ?? error.toString();
} else if ((error as any).toString) {
message = (error as any).toString();
} else if (error instanceof String) {
message = error.toString();
} else {
console.error(error);
toastFunc({
Expand All @@ -72,7 +72,7 @@ function createHookObject(toastFunc: (toast: IToast) => void) {
header: "Error",
content: message,
});
/* eslint-enable @typescript-eslint/no-explicit-any, no-console */
/* eslint-enable no-console */
},
};
}
Expand Down
7 changes: 3 additions & 4 deletions ui/v2.5/src/utils/bulkUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ export function getAggregateInputIDs(
return undefined;
}

export function getAggregateState<T>(
export function getAggregateState<T, U>(
currentValue: T,
newValue: T,
newValue: U,
first: boolean
) {
if (!first && !isEqual(currentValue, newValue)) {
Expand Down Expand Up @@ -207,8 +207,7 @@ export function getAggregateStateObject<O, I>(
const inputKey = key as keyof I;

const currentValue = getProperty(output, outputKey);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const performerValue = getProperty(input, inputKey) as any;
const performerValue = getProperty(input, inputKey);

setProperty(
output,
Expand Down
4 changes: 4 additions & 0 deletions ui/v2.5/src/utils/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ApolloError } from "@apollo/client";

export const apolloError = (error: unknown) =>
error instanceof ApolloError ? error.message : "";
6 changes: 3 additions & 3 deletions ui/v2.5/src/utils/flattenMessages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const flattenMessages = (nestedMessages: any, prefix = "") => {
type NestedMessage = { [key: string]: NestedMessage | string };
const flattenMessages = (nestedMessages: NestedMessage | null, prefix = "") => {
if (nestedMessages === null) {
return {};
}
Expand All @@ -14,7 +14,7 @@ const flattenMessages = (nestedMessages: any, prefix = "") => {
}

return messages;
}, {});
}, {} as Record<string, string>);
};

export default flattenMessages;
3 changes: 1 addition & 2 deletions ui/v2.5/src/utils/focus.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useRef, useEffect } from "react";

const useFocus = () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const htmlElRef = useRef<any>();
const htmlElRef = useRef<HTMLInputElement | null>(null);
const setFocus = () => {
const currentEl = htmlElRef.current;
if (currentEl) {
Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./errors";
9 changes: 4 additions & 5 deletions ui/v2.5/src/utils/lazyComponent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentType, lazy } from "react";
import { lazy } from "react";

interface ILazyComponentError {
__lazyComponentError?: true;
Expand All @@ -8,11 +8,10 @@ export const isLazyComponentError = (e: unknown) => {
return !!(e as ILazyComponentError).__lazyComponentError;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const lazyComponent = <T extends ComponentType<any>>(
factory: Parameters<typeof lazy<T>>[0]
export const lazyComponent = <Props extends object>(
factory: () => Promise<{ default: React.FC<Props> }>
) => {
return lazy<T>(async () => {
return lazy(async () => {
try {
return await factory();
} catch (e) {
Expand Down

0 comments on commit 409f8fc

Please sign in to comment.