Fix some any types

This commit is contained in:
Isaac Wise 2024-07-25 18:58:52 -05:00
parent e79b98d3b0
commit 0b8a9b4310
No known key found for this signature in database
GPG Key ID: A02A33A7E2427136
16 changed files with 49 additions and 55 deletions

View File

@ -4,10 +4,10 @@ import { useEffect, useState } from "react";
import { styles } from "./styles";
import { Options } from "./types";
import CreatableSelect from "react-select/creatable";
import Select from "react-select";
import Select, { ActionMeta } from "react-select";
type Props = {
onChange: any;
onChange: (newValue: unknown, actionMeta: ActionMeta<unknown>) => void;
showDefaultValue?: boolean;
defaultValue?:
| {

View File

@ -3,9 +3,10 @@ import { useEffect, useState } from "react";
import CreatableSelect from "react-select/creatable";
import { styles } from "./styles";
import { Options } from "./types";
import { ActionMeta } from "react-select";
type Props = {
onChange: any;
onChange: (newValue: unknown, actionMeta: ActionMeta<unknown>) => void;
defaultValue?: {
value: number;
label: string;

View File

@ -85,7 +85,7 @@ export default function LinkCard({ link, flipDropdown, editMode }: Props) {
const permissions = usePermissions(collection?.id as number);
useEffect(() => {
let interval: any;
let interval: NodeJS.Timeout | null = null;
if (
isVisible &&

View File

@ -84,7 +84,7 @@ export default function LinkMasonry({ link, flipDropdown, editMode }: Props) {
const permissions = usePermissions(collection?.id as number);
useEffect(() => {
let interval: any;
let interval: NodeJS.Timeout | null = null;
if (
isVisible &&

View File

@ -104,7 +104,7 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
);
})();
let interval: any;
let interval: NodeJS.Timeout | null = null;
if (!isReady()) {
interval = setInterval(async () => {

View File

@ -4,10 +4,8 @@ import {
ArchivedFormat,
LinkIncludingShortenedCollectionAndTags,
} from "@/types/global";
import toast from "react-hot-toast";
import Link from "next/link";
import { useRouter } from "next/router";
import { useSession } from "next-auth/react";
type Props = {
name: string;
@ -24,7 +22,6 @@ export default function PreservedFormatRow({
activeLink,
downloadable,
}: Props) {
const session = useSession();
const { getLink } = useLinkStore();
const [link, setLink] =
@ -36,19 +33,15 @@ export default function PreservedFormatRow({
useEffect(() => {
(async () => {
const data = await getLink(link.id as number, isPublic);
setLink(
(data as any).response as LinkIncludingShortenedCollectionAndTags
);
const { data } = await getLink(link.id as number, isPublic);
setLink(data as LinkIncludingShortenedCollectionAndTags);
})();
let interval: any;
let interval: NodeJS.Timeout | null = null;
if (link?.image === "pending" || link?.pdf === "pending") {
interval = setInterval(async () => {
const data = await getLink(link.id as number, isPublic);
setLink(
(data as any).response as LinkIncludingShortenedCollectionAndTags
);
const { data } = await getLink(link.id as number, isPublic);
setLink(data as LinkIncludingShortenedCollectionAndTags);
}, 5000);
} else {
if (interval) {

View File

@ -75,7 +75,7 @@ export default function ReadableView({ link }: Props) {
useEffect(() => {
if (link) getLink(link?.id as number);
let interval: any;
let interval: NodeJS.Timeout | null = null;
if (
link &&
(link?.image === "pending" ||

View File

@ -2,19 +2,17 @@ import axios, { AxiosError } from "axios"
axios.defaults.baseURL = "http://localhost:3000"
export async function seedUser (username?: string, password?: string, name?: string) {
export async function seedUser(username?: string, password?: string, name?: string) {
try {
return await axios.post("/api/v1/users", {
username: username || "test",
password: password || "password",
name: name || "Test User",
})
} catch (e: any) {
if (e instanceof AxiosError) {
if (e.response?.status === 400) {
return
}
}
throw e
} catch (error) {
const axiosError = error as AxiosError;
if (axiosError && axiosError.response?.status === 400) return
throw error
}
}

View File

@ -1,11 +1,11 @@
import { prisma } from "@/lib/api/db";
import { LinkRequestQuery, Sort } from "@/types/global";
import { LinkRequestQuery, Order, Sort } from "@/types/global";
export default async function getDashboardData(
userId: number,
query: LinkRequestQuery
) {
let order: any;
let order: Order = { id: "desc" };
if (query.sort === Sort.DateNewestFirst) order = { id: "desc" };
else if (query.sort === Sort.DateOldestFirst) order = { id: "asc" };
else if (query.sort === Sort.NameAZ) order = { name: "asc" };

View File

@ -1,5 +1,5 @@
import { prisma } from "@/lib/api/db";
import { LinkRequestQuery, Sort } from "@/types/global";
import { LinkRequestQuery, Order, Sort } from "@/types/global";
type Response<D> =
| {
@ -17,7 +17,7 @@ export default async function getDashboardData(
userId: number,
query: LinkRequestQuery
): Promise<Response<any>> {
let order: any;
let order: Order = { id: "desc" };
if (query.sort === Sort.DateNewestFirst) order = { id: "desc" };
else if (query.sort === Sort.DateOldestFirst) order = { id: "asc" };
else if (query.sort === Sort.NameAZ) order = { name: "asc" };

View File

@ -1,11 +1,11 @@
import { prisma } from "@/lib/api/db";
import { LinkRequestQuery, Sort } from "@/types/global";
import { LinkRequestQuery, Order, Sort } from "@/types/global";
export default async function getLink(userId: number, query: LinkRequestQuery) {
const POSTGRES_IS_ENABLED =
process.env.DATABASE_URL?.startsWith("postgresql");
let order: any;
let order: Order = { id: "desc" };
if (query.sort === Sort.DateNewestFirst) order = { id: "desc" };
else if (query.sort === Sort.DateOldestFirst) order = { id: "asc" };
else if (query.sort === Sort.NameAZ) order = { name: "asc" };

View File

@ -1,5 +1,5 @@
import { prisma } from "@/lib/api/db";
import { LinkRequestQuery, Sort } from "@/types/global";
import { LinkRequestQuery, Order, Sort } from "@/types/global";
export default async function getLink(
query: Omit<LinkRequestQuery, "tagId" | "pinnedOnly">
@ -7,7 +7,7 @@ export default async function getLink(
const POSTGRES_IS_ENABLED =
process.env.DATABASE_URL?.startsWith("postgresql");
let order: any;
let order: Order = { id: "desc" };
if (query.sort === Sort.DateNewestFirst) order = { id: "desc" };
else if (query.sort === Sort.DateOldestFirst) order = { id: "asc" };
else if (query.sort === Sort.NameAZ) order = { name: "asc" };

View File

@ -7,10 +7,10 @@ export function isPWA() {
}
export function isIphone() {
return /iPhone/.test(navigator.userAgent) && !(window as any).MSStream;
return /iPhone/.test(navigator.userAgent) && !(window as unknown as { MSStream?: any }).MSStream;
}
export function dropdownTriggerer(e: any) {
export function dropdownTriggerer(e: React.FocusEvent<HTMLElement> | React.MouseEvent<HTMLElement>) {
let targetEl = e.currentTarget;
if (targetEl && targetEl.matches(":focus")) {
setTimeout(function () {

View File

@ -39,7 +39,7 @@ export function monolithAvailable(
);
}
export function previewAvailable(link: any) {
export function previewAvailable(link: LinkIncludingShortenedCollectionAndTags) {
return (
link &&
link.preview &&

View File

@ -81,6 +81,8 @@ export enum Sort {
DescriptionZA,
}
export type Order = { [key: string]: 'asc' | 'desc' };
export type LinkRequestQuery = {
sort: Sort;
cursor?: number;