diff --git a/frontend/src/api/actions/updateChannelOverwrite.ts b/frontend/src/api/actions/updateChannelOverwrite.ts index 1611fa6a..ab412041 100644 --- a/frontend/src/api/actions/updateChannelOverwrite.ts +++ b/frontend/src/api/actions/updateChannelOverwrite.ts @@ -3,7 +3,11 @@ import getApiUrl from '../../configuration/getApiUrl'; import getFetchCredentials from '../../configuration/getFetchCredentials'; import getCookie from '../../functions/getCookie'; -const updateChannelOverwrites = async (channelId: string, configKey: string, configValue: any) => { +const updateChannelOverwrites = async ( + channelId: string, + configKey: string, + configValue: string | boolean | number | null, +) => { const apiUrl = getApiUrl(); const csrfCookie = getCookie('csrftoken'); diff --git a/frontend/src/api/loader/loadApiToken.ts b/frontend/src/api/loader/loadApiToken.ts index aa52c01b..204eb041 100644 --- a/frontend/src/api/loader/loadApiToken.ts +++ b/frontend/src/api/loader/loadApiToken.ts @@ -28,7 +28,7 @@ const loadApiToken = async (): Promise => { } return apiToken; - } catch (e) { + } catch { return { token: '' }; } }; diff --git a/frontend/src/components/Navigation.tsx b/frontend/src/components/Navigation.tsx index 13232442..05fbe976 100644 --- a/frontend/src/components/Navigation.tsx +++ b/frontend/src/components/Navigation.tsx @@ -5,10 +5,10 @@ import iconExit from '/img/icon-exit.svg'; import Routes from '../configuration/routes/RouteList'; import NavigationItem from './NavigationItem'; import logOut from '../api/actions/logOut'; -import loadIsAdmin from '../functions/getIsAdmin'; +import useIsAdmin from '../functions/useIsAdmin'; const Navigation = () => { - const isAdmin = loadIsAdmin(); + const isAdmin = useIsAdmin(); const navigate = useNavigate(); const handleLogout = async (event: { preventDefault: () => void }) => { event.preventDefault(); diff --git a/frontend/src/components/SettingsNavigation.tsx b/frontend/src/components/SettingsNavigation.tsx index 6c035fd0..5475614b 100644 --- a/frontend/src/components/SettingsNavigation.tsx +++ b/frontend/src/components/SettingsNavigation.tsx @@ -1,9 +1,9 @@ import { Link } from 'react-router-dom'; import Routes from '../configuration/routes/RouteList'; -import loadIsAdmin from '../functions/getIsAdmin'; +import useIsAdmin from '../functions/useIsAdmin'; const SettingsNavigation = () => { - const isAdmin = loadIsAdmin(); + const isAdmin = useIsAdmin(); return ( <> diff --git a/frontend/src/configuration/colours/getColours.ts b/frontend/src/configuration/colours/useColours.ts similarity index 92% rename from frontend/src/configuration/colours/getColours.ts rename to frontend/src/configuration/colours/useColours.ts index af43781f..27b2acba 100644 --- a/frontend/src/configuration/colours/getColours.ts +++ b/frontend/src/configuration/colours/useColours.ts @@ -7,7 +7,7 @@ export const ColourConstant = { Midnight: 'midnight.css', }; -const importColours = () => { +const useColours = () => { const { userConfig } = useUserConfigStore(); const stylesheet = userConfig?.config.stylesheet; @@ -29,4 +29,4 @@ const importColours = () => { } }; -export default importColours; +export default useColours; diff --git a/frontend/src/functions/getIsAdmin.ts b/frontend/src/functions/useIsAdmin.ts similarity index 78% rename from frontend/src/functions/getIsAdmin.ts rename to frontend/src/functions/useIsAdmin.ts index ca4c2ce8..7fb5661b 100644 --- a/frontend/src/functions/getIsAdmin.ts +++ b/frontend/src/functions/useIsAdmin.ts @@ -1,10 +1,10 @@ import { useUserConfigStore } from '../stores/UserConfigStore'; -const loadIsAdmin = () => { +const useIsAdmin = () => { const { userConfig } = useUserConfigStore(); const isAdmin = userConfig?.is_staff || userConfig?.is_superuser; return isAdmin; }; -export default loadIsAdmin; +export default useIsAdmin; diff --git a/frontend/src/pages/Base.tsx b/frontend/src/pages/Base.tsx index 00724b36..74cae1ad 100644 --- a/frontend/src/pages/Base.tsx +++ b/frontend/src/pages/Base.tsx @@ -1,6 +1,6 @@ import { Outlet, useLoaderData, useLocation, useSearchParams } from 'react-router-dom'; import Footer from '../components/Footer'; -import importColours from '../configuration/colours/getColours'; +import useColours from '../configuration/colours/useColours'; import { UserMeType } from '../api/actions/updateUserConfig'; import { useEffect, useState } from 'react'; import Navigation from '../components/Navigation'; @@ -46,6 +46,7 @@ const Base = () => { useEffect(() => { setAuth(auth); setUserConfig(userConfig); + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); useEffect(() => { @@ -79,7 +80,7 @@ const Base = () => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [currentPage]); - importColours(); + useColours(); return ( <> diff --git a/frontend/src/pages/ChannelAbout.tsx b/frontend/src/pages/ChannelAbout.tsx index 6aa105ed..a3721dcf 100644 --- a/frontend/src/pages/ChannelAbout.tsx +++ b/frontend/src/pages/ChannelAbout.tsx @@ -12,7 +12,7 @@ import PaginationDummy from '../components/PaginationDummy'; import FormattedNumber from '../components/FormattedNumber'; import Button from '../components/Button'; import updateChannelOverwrites from '../api/actions/updateChannelOverwrite'; -import loadIsAdmin from '../functions/getIsAdmin'; +import useIsAdmin from '../functions/useIsAdmin'; export type ChannelBaseOutletContextType = { currentPage: number; @@ -34,7 +34,7 @@ const ChannelAbout = () => { const { channelId } = useParams() as ChannelAboutParams; const { setStartNotification } = useOutletContext() as ChannelBaseOutletContextType; const navigate = useNavigate(); - const isAdmin = loadIsAdmin(); + const isAdmin = useIsAdmin(); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const [descriptionExpanded, setDescriptionExpanded] = useState(false); @@ -76,7 +76,10 @@ const ChannelAbout = () => { })(); }, [refresh, channelId]); - const handleUpdateConfig = async (configKey: string, configValue: any) => { + const handleUpdateConfig = async ( + configKey: string, + configValue: string | boolean | number | null, + ) => { if (!channel) return; await updateChannelOverwrites(channel.channel_id, configKey, configValue); setRefresh(true); diff --git a/frontend/src/pages/ChannelBase.tsx b/frontend/src/pages/ChannelBase.tsx index e696a159..2b98d116 100644 --- a/frontend/src/pages/ChannelBase.tsx +++ b/frontend/src/pages/ChannelBase.tsx @@ -8,7 +8,7 @@ import { useEffect, useState } from 'react'; import ChannelBanner from '../components/ChannelBanner'; import loadChannelNav, { ChannelNavResponseType } from '../api/loader/loadChannelNav'; import loadChannelById from '../api/loader/loadChannelById'; -import loadIsAdmin from '../functions/getIsAdmin'; +import useIsAdmin from '../functions/useIsAdmin'; type ChannelParams = { channelId: string; @@ -22,7 +22,7 @@ export type ChannelResponseType = { const ChannelBase = () => { const { channelId } = useParams() as ChannelParams; const { currentPage, setCurrentPage } = useOutletContext() as OutletContextType; - const isAdmin = loadIsAdmin(); + const isAdmin = useIsAdmin(); const [channelResponse, setChannelResponse] = useState(); const [channelNav, setChannelNav] = useState(); diff --git a/frontend/src/pages/ChannelVideo.tsx b/frontend/src/pages/ChannelVideo.tsx index a4709b4a..2303feb3 100644 --- a/frontend/src/pages/ChannelVideo.tsx +++ b/frontend/src/pages/ChannelVideo.tsx @@ -72,7 +72,6 @@ const ChannelVideo = ({ videoType }: ChannelVideoProps) => { setVideoAggsResponse(channelAggs); setRefresh(false); })(); - // eslint-disable-next-line react-hooks/exhaustive-deps }, [ refresh, userConfig.config.sort_by, diff --git a/frontend/src/pages/Channels.tsx b/frontend/src/pages/Channels.tsx index 86a9fd91..1a7ec6ee 100644 --- a/frontend/src/pages/Channels.tsx +++ b/frontend/src/pages/Channels.tsx @@ -12,7 +12,7 @@ import ScrollToTopOnNavigate from '../components/ScrollToTop'; import Notifications from '../components/Notifications'; import Button from '../components/Button'; import updateChannelSubscription from '../api/actions/updateChannelSubscription'; -import loadIsAdmin from '../functions/getIsAdmin'; +import useIsAdmin from '../functions/useIsAdmin'; import { useUserConfigStore } from '../stores/UserConfigStore'; type ChannelOverwritesType = { @@ -50,7 +50,7 @@ type ChannelsListResponse = { const Channels = () => { const { userConfig, setPartialConfig } = useUserConfigStore(); const { currentPage, setCurrentPage } = useOutletContext() as OutletContextType; - const isAdmin = loadIsAdmin(); + const isAdmin = useIsAdmin(); const [channelListResponse, setChannelListResponse] = useState(); const [showAddForm, setShowAddForm] = useState(false); diff --git a/frontend/src/pages/ErrorPage.tsx b/frontend/src/pages/ErrorPage.tsx index e060b1cc..fb4e6481 100644 --- a/frontend/src/pages/ErrorPage.tsx +++ b/frontend/src/pages/ErrorPage.tsx @@ -1,5 +1,5 @@ import { useRouteError } from 'react-router-dom'; -import importColours from '../configuration/colours/getColours'; +import useColours from '../configuration/colours/useColours'; // This is not always the correct response type ErrorType = { @@ -9,7 +9,7 @@ type ErrorType = { const ErrorPage = () => { const error = useRouteError() as ErrorType; - importColours(); + useColours(); console.error('ErrorPage', error); diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index 315c41fe..636e02b8 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -146,6 +146,7 @@ const Home = () => { setContinueVideoResponse(continueVideoResponse); } catch (error) { console.log('Server error on continue vids?'); + console.error(error); } setVideoReponse(videos); @@ -153,7 +154,6 @@ const Home = () => { setRefreshVideoList(false); } })(); - // eslint-disable-next-line react-hooks/exhaustive-deps }, [ refreshVideoList, userMeConfig.sort_by, diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx index 43a211e8..ac6ac55a 100644 --- a/frontend/src/pages/Login.tsx +++ b/frontend/src/pages/Login.tsx @@ -1,7 +1,7 @@ import { useState } from 'react'; import Routes from '../configuration/routes/RouteList'; import { useNavigate } from 'react-router-dom'; -import importColours from '../configuration/colours/getColours'; +import useColours from '../configuration/colours/useColours'; import Button from '../components/Button'; import signIn from '../api/actions/signIn'; @@ -11,7 +11,7 @@ const Login = () => { const [saveLogin, setSaveLogin] = useState(false); const navigate = useNavigate(); - importColours(); + useColours(); const form_error = false; diff --git a/frontend/src/pages/Playlist.tsx b/frontend/src/pages/Playlist.tsx index 0365b96e..ff8816de 100644 --- a/frontend/src/pages/Playlist.tsx +++ b/frontend/src/pages/Playlist.tsx @@ -22,7 +22,7 @@ import ScrollToTopOnNavigate from '../components/ScrollToTop'; import EmbeddableVideoPlayer from '../components/EmbeddableVideoPlayer'; import Button from '../components/Button'; import loadVideoListByFilter from '../api/loader/loadVideoListByPage'; -import loadIsAdmin from '../functions/getIsAdmin'; +import useIsAdmin from '../functions/useIsAdmin'; import { useUserConfigStore } from '../stores/UserConfigStore'; export type PlaylistType = { @@ -60,7 +60,7 @@ const Playlist = () => { const { userConfig } = useUserConfigStore(); const { currentPage, setCurrentPage } = useOutletContext() as OutletContextType; - const isAdmin = loadIsAdmin(); + const isAdmin = useIsAdmin(); const userMeConfig = userConfig.config; diff --git a/frontend/src/pages/Playlists.tsx b/frontend/src/pages/Playlists.tsx index adcff299..98c6c321 100644 --- a/frontend/src/pages/Playlists.tsx +++ b/frontend/src/pages/Playlists.tsx @@ -15,7 +15,7 @@ import updatePlaylistSubscription from '../api/actions/updatePlaylistSubscriptio import createCustomPlaylist from '../api/actions/createCustomPlaylist'; import ScrollToTopOnNavigate from '../components/ScrollToTop'; import Button from '../components/Button'; -import loadIsAdmin from '../functions/getIsAdmin'; +import useIsAdmin from '../functions/useIsAdmin'; import { useUserConfigStore } from '../stores/UserConfigStore'; export type PlaylistEntryType = { @@ -35,7 +35,7 @@ export type PlaylistsResponseType = { const Playlists = () => { const { userConfig, setPartialConfig } = useUserConfigStore(); const { currentPage, setCurrentPage } = useOutletContext() as OutletContextType; - const isAdmin = loadIsAdmin(); + const isAdmin = useIsAdmin(); const [showAddForm, setShowAddForm] = useState(false); const [refresh, setRefresh] = useState(false); diff --git a/frontend/src/pages/SettingsUser.tsx b/frontend/src/pages/SettingsUser.tsx index deb4a8b4..d87f0290 100644 --- a/frontend/src/pages/SettingsUser.tsx +++ b/frontend/src/pages/SettingsUser.tsx @@ -1,16 +1,16 @@ import { useNavigate } from 'react-router-dom'; import { ColourVariants } from '../api/actions/updateUserConfig'; -import { ColourConstant } from '../configuration/colours/getColours'; +import { ColourConstant } from '../configuration/colours/useColours'; import SettingsNavigation from '../components/SettingsNavigation'; import Notifications from '../components/Notifications'; import Button from '../components/Button'; -import loadIsAdmin from '../functions/getIsAdmin'; +import useIsAdmin from '../functions/useIsAdmin'; import { useUserConfigStore } from '../stores/UserConfigStore'; import { useEffect, useState } from 'react'; const SettingsUser = () => { const { userConfig, setPartialConfig } = useUserConfigStore(); - const isAdmin = loadIsAdmin(); + const isAdmin = useIsAdmin(); const navigate = useNavigate(); const [styleSheet, setStyleSheet] = useState(userConfig.config.stylesheet); diff --git a/frontend/src/pages/Video.tsx b/frontend/src/pages/Video.tsx index 07a5426c..5c2da1ea 100644 --- a/frontend/src/pages/Video.tsx +++ b/frontend/src/pages/Video.tsx @@ -37,7 +37,7 @@ import CommentBox, { CommentsType } from '../components/CommentBox'; import Button from '../components/Button'; import getApiUrl from '../configuration/getApiUrl'; import loadVideoNav, { VideoNavResponseType } from '../api/loader/loadVideoNav'; -import loadIsAdmin from '../functions/getIsAdmin'; +import useIsAdmin from '../functions/useIsAdmin'; const isInPlaylist = (videoId: string, playlist: PlaylistType) => { return playlist.playlist_entries.some(entry => { @@ -118,7 +118,7 @@ export type VideoCommentsResponseType = { const Video = () => { const { videoId } = useParams() as VideoParams; const navigate = useNavigate(); - const isAdmin = loadIsAdmin(); + const isAdmin = useIsAdmin(); const [loading, setLoading] = useState(false); const [videoEnded, setVideoEnded] = useState(false); @@ -188,6 +188,7 @@ const Video = () => { } } } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [videoEnded, playlistAutoplay]); if (videoResponse === undefined) {