From 360bf02ca9cfc38ac0ec3d66152261178fc59246 Mon Sep 17 00:00:00 2001 From: Stephane Richin Date: Fri, 8 Dec 2023 17:09:51 +0100 Subject: [PATCH] chore: setup knip and fix warning --- .eslintrc | 3 +++ .knip.json | 3 +++ src/components/NavbarLink.tsx | 2 +- src/components/Navigation.tsx | 2 +- src/components/PlayerActions.tsx | 2 +- src/components/TransferList.tsx | 2 +- src/database/utils.ts | 6 ------ src/hooks/useScript.ts | 5 +++-- src/providers/PlayerMode.tsx | 2 +- src/serviceWorkerRegistration.ts | 12 ------------ src/translations/index.ts | 2 +- src/types/interfaces/Search.ts | 8 -------- src/types/interfaces/SponsorBlock.ts | 2 +- src/utils/downloadFile.ts | 19 ------------------- src/utils/getArrayDifference.ts | 2 +- 15 files changed, 17 insertions(+), 55 deletions(-) create mode 100644 .eslintrc create mode 100644 .knip.json delete mode 100644 src/utils/downloadFile.ts diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..f298005 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": ["react-app", "react-app/jest"] +} diff --git a/.knip.json b/.knip.json new file mode 100644 index 0000000..28256dc --- /dev/null +++ b/.knip.json @@ -0,0 +1,3 @@ +{ + "entry": ["src/index.tsx"] +} diff --git a/src/components/NavbarLink.tsx b/src/components/NavbarLink.tsx index 463cbb2..6883561 100644 --- a/src/components/NavbarLink.tsx +++ b/src/components/NavbarLink.tsx @@ -11,7 +11,7 @@ import { useLocation } from "react-router-dom"; import { useStableNavigate } from "../providers/Navigate"; import classes from "./NavbarLink.module.css"; -export type RoutePath = +type RoutePath = | "/" | "/search" | "/favorites" diff --git a/src/components/Navigation.tsx b/src/components/Navigation.tsx index bf73a90..2db5d6c 100644 --- a/src/components/Navigation.tsx +++ b/src/components/Navigation.tsx @@ -23,7 +23,7 @@ import { NavbarLink } from "./NavbarLink"; import classes from "./Navigation.module.css"; import { PlayerSpace } from "./Player"; -export const NAVIGATION_WIDTH = 88; +const NAVIGATION_WIDTH = 88; export const Navigation = memo(() => { const { t } = useTranslation(); diff --git a/src/components/PlayerActions.tsx b/src/components/PlayerActions.tsx index 18ae6b3..5ad19ee 100644 --- a/src/components/PlayerActions.tsx +++ b/src/components/PlayerActions.tsx @@ -48,7 +48,7 @@ interface ButtonNextVideoProps extends ActionIconProps { iconSize?: number; } -export const ButtonPlayPause: FC = memo( +const ButtonPlayPause: FC = memo( ({ size, radius, iconSize }) => { const playerState = usePlayerState(); const playerAudio = usePlayerAudio(); diff --git a/src/components/TransferList.tsx b/src/components/TransferList.tsx index 94cf29a..77771e9 100644 --- a/src/components/TransferList.tsx +++ b/src/components/TransferList.tsx @@ -14,7 +14,7 @@ import { useTranslation } from "react-i18next"; import classes from "./TransferList.module.css"; -export type TransferListData = [string[], string[]]; +type TransferListData = [string[], string[]]; interface TransferListProps { data: string[]; diff --git a/src/database/utils.ts b/src/database/utils.ts index 7a120eb..6372f38 100644 --- a/src/database/utils.ts +++ b/src/database/utils.ts @@ -57,12 +57,6 @@ export const getAllPlaylists = (): CardPlaylist[] => { return db.queryAll("playlists"); }; -export const getLocalPlaylists = (): CardPlaylist[] => { - return db.queryAll("playlists", { - query: (row: Playlist) => row.title !== "Favorites" && !row.playlistId, - }); -}; - export const getPlaylist = (playlistId: number): Playlist => { return db.queryAll("playlists", { query: { ID: playlistId } })[0]; }; diff --git a/src/hooks/useScript.ts b/src/hooks/useScript.ts index caa7a3d..5126af9 100644 --- a/src/hooks/useScript.ts +++ b/src/hooks/useScript.ts @@ -2,8 +2,9 @@ import { useEffect, useState } from 'react' // Source: https://usehooks-ts.com/react-hook/use-script -export type UseScriptStatus = 'idle' | 'loading' | 'ready' | 'error' -export interface UseScriptOptions { +type UseScriptStatus = 'idle' | 'loading' | 'ready' | 'error' + +interface UseScriptOptions { shouldPreventLoad?: boolean removeOnUnmount?: boolean } diff --git a/src/providers/PlayerMode.tsx b/src/providers/PlayerMode.tsx index 2531ea5..c79fb9f 100644 --- a/src/providers/PlayerMode.tsx +++ b/src/providers/PlayerMode.tsx @@ -7,7 +7,7 @@ import { useState, } from "react"; -export type PlayerMode = "audio" | "video"; +type PlayerMode = "audio" | "video"; const PlayerModeContext = createContext("audio"); const SetPlayerModeContext = createContext<(mode: PlayerMode) => void>( diff --git a/src/serviceWorkerRegistration.ts b/src/serviceWorkerRegistration.ts index 603b26c..086c241 100644 --- a/src/serviceWorkerRegistration.ts +++ b/src/serviceWorkerRegistration.ts @@ -132,15 +132,3 @@ function checkValidServiceWorker(swUrl: string, config?: Config) { ); }); } - -export function unregister() { - if ("serviceWorker" in navigator) { - navigator.serviceWorker.ready - .then((registration) => { - registration.unregister(); - }) - .catch((error) => { - console.error(error.message); - }); - } -} diff --git a/src/translations/index.ts b/src/translations/index.ts index 8d3f76a..86809f3 100644 --- a/src/translations/index.ts +++ b/src/translations/index.ts @@ -33,7 +33,7 @@ export const languagesValues = [ }, ]; -export const resources = { +const resources = { en: { translation: en, }, diff --git a/src/types/interfaces/Search.ts b/src/types/interfaces/Search.ts index bd671fc..4c6104c 100644 --- a/src/types/interfaces/Search.ts +++ b/src/types/interfaces/Search.ts @@ -8,14 +8,6 @@ export type SearchDuration = "all" | "short" | "medium" | "long"; export type SearchDate = "all" | "hour" | "today" | "week" | "month" | "year"; export type SearchService = "invidious" | "youtube_music"; -export interface SearchParams { - q: String; - type: SearchTypes; - sortBy: SearchSortBy; - date: SearchDate; - duration: SearchDuration; -} - export interface Search { q: string; type: SearchTypes; diff --git a/src/types/interfaces/SponsorBlock.ts b/src/types/interfaces/SponsorBlock.ts index 12ad12d..f2ccbd3 100644 --- a/src/types/interfaces/SponsorBlock.ts +++ b/src/types/interfaces/SponsorBlock.ts @@ -1,4 +1,4 @@ -export type SponsorBlockCategory = +type SponsorBlockCategory = | "sponsor" | "intro" | "outro" diff --git a/src/utils/downloadFile.ts b/src/utils/downloadFile.ts deleted file mode 100644 index d8dfcf7..0000000 --- a/src/utils/downloadFile.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { notifications } from "@mantine/notifications"; - -export const downloadFile = (url: string, filename: string): Promise => { - return fetch(url) - .then((response) => response.blob()) - .then((blob) => { - const link = document.createElement("a"); - link.href = URL.createObjectURL(blob); - link.download = filename; - link.click(); - }) - .catch((error) => { - notifications.show({ - title: "Download", - message: "Failed to download file", - color: "red", - }); - }); -}; diff --git a/src/utils/getArrayDifference.ts b/src/utils/getArrayDifference.ts index 573fc23..0011a7e 100644 --- a/src/utils/getArrayDifference.ts +++ b/src/utils/getArrayDifference.ts @@ -2,7 +2,7 @@ import { removeDuplicateVideoId } from "../database/utils"; import type { Card, CardVideo } from "../types/interfaces/Card"; import type { Playlist } from "../types/interfaces/Playlist"; -export const getCardId = (card: T): string | number => +const getCardId = (card: T): string | number => // @ts-ignore card.ID || card.videoId || card.playlistId || card.authorId;