diff --git a/.eslintrc b/.eslintrc index 8371c72d..ff27eecb 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,7 +8,6 @@ }, "ignorePatterns": ["src/service*.ts"], "rules": { - "react-hooks/rules-of-hooks": "off", - "react-hooks/exhaustive-deps": "off" + "react-hooks/rules-of-hooks": "off" } } diff --git a/package-lock.json b/package-lock.json index 3a2adf85..40082368 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@fortawesome/react-fontawesome": "^0.2.0", "@json2csv/plainjs": "^7.0.3", "@reduxjs/toolkit": "^1.9.5", - "@shlinkio/shlink-frontend-kit": "^0.2.0", + "@shlinkio/shlink-frontend-kit": "^0.2.1", "@shlinkio/shlink-js-sdk": "^0.1.0", "@shlinkio/shlink-web-component": "^0.3.3", "bootstrap": "5.2.3", @@ -2801,9 +2801,9 @@ } }, "node_modules/@shlinkio/shlink-frontend-kit": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@shlinkio/shlink-frontend-kit/-/shlink-frontend-kit-0.2.0.tgz", - "integrity": "sha512-8kGaae0bTiGzbLzPsolLvJ5ud37BR2b1WeDy8lyXIiwoFiSAMIgWpqro0nMdBVBQXovjmMbtiS6BFYsaoBo9/g==", + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@shlinkio/shlink-frontend-kit/-/shlink-frontend-kit-0.2.1.tgz", + "integrity": "sha512-5mRpQII9bGHAJQ1ghgGY+jFC5tD0y0ufgPqco9vLVGXGVf+BSNQrTiw/Cx6f9eCInqFPgFo8CdJzWUHbIzvC+Q==", "dependencies": { "classnames": "^2.3.2", "qs": "^6.11.2", @@ -12390,9 +12390,9 @@ } }, "@shlinkio/shlink-frontend-kit": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@shlinkio/shlink-frontend-kit/-/shlink-frontend-kit-0.2.0.tgz", - "integrity": "sha512-8kGaae0bTiGzbLzPsolLvJ5ud37BR2b1WeDy8lyXIiwoFiSAMIgWpqro0nMdBVBQXovjmMbtiS6BFYsaoBo9/g==", + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@shlinkio/shlink-frontend-kit/-/shlink-frontend-kit-0.2.1.tgz", + "integrity": "sha512-5mRpQII9bGHAJQ1ghgGY+jFC5tD0y0ufgPqco9vLVGXGVf+BSNQrTiw/Cx6f9eCInqFPgFo8CdJzWUHbIzvC+Q==", "requires": { "classnames": "^2.3.2", "qs": "^6.11.2", diff --git a/package.json b/package.json index 0c79b7a6..a064e41e 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "@fortawesome/react-fontawesome": "^0.2.0", "@json2csv/plainjs": "^7.0.3", "@reduxjs/toolkit": "^1.9.5", - "@shlinkio/shlink-frontend-kit": "^0.2.0", + "@shlinkio/shlink-frontend-kit": "^0.2.1", "@shlinkio/shlink-js-sdk": "^0.1.0", "@shlinkio/shlink-web-component": "^0.3.3", "bootstrap": "5.2.3", diff --git a/src/app/App.tsx b/src/app/App.tsx index b27811a7..bb9d4022 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -1,7 +1,7 @@ import { changeThemeInMarkup } from '@shlinkio/shlink-frontend-kit'; import classNames from 'classnames'; import type { FC } from 'react'; -import { useEffect } from 'react'; +import { useEffect, useRef } from 'react'; import { Route, Routes, useLocation } from 'react-router-dom'; import { AppUpdateBanner } from '../common/AppUpdateBanner'; import { NotFound } from '../common/NotFound'; @@ -29,16 +29,20 @@ export const App = ( ShlinkVersionsContainer: FC, ) => ({ fetchServers, servers, settings, appUpdated, resetAppUpdate }: AppProps) => { const location = useLocation(); + const initialServers = useRef(servers); const isHome = location.pathname === '/'; useEffect(() => { - // On first load, try to fetch the remote servers if the list is empty - if (Object.keys(servers).length === 0) { + // Try to fetch the remote servers if the list is empty at first + // We use a ref because we don't care if the servers list becomes empty later + if (Object.keys(initialServers.current).length === 0) { fetchServers(); } + }, [fetchServers]); + useEffect(() => { changeThemeInMarkup(settings.ui?.theme ?? 'light'); - }, []); + }, [settings.ui?.theme]); return (
diff --git a/src/common/Home.tsx b/src/common/Home.tsx index 4029e39b..bf7b79bd 100644 --- a/src/common/Home.tsx +++ b/src/common/Home.tsx @@ -23,7 +23,7 @@ export const Home = ({ servers }: HomeProps) => { // Try to redirect to the first server marked as auto-connect const autoConnectServer = serversList.find(({ autoConnect }) => autoConnect); autoConnectServer && navigate(`/server/${autoConnectServer.id}`); - }, []); + }, [serversList, navigate]); return (
diff --git a/src/common/MainHeader.tsx b/src/common/MainHeader.tsx index 74cd028a..750ba744 100644 --- a/src/common/MainHeader.tsx +++ b/src/common/MainHeader.tsx @@ -10,14 +10,15 @@ import { ShlinkLogo } from './img/ShlinkLogo'; import './MainHeader.scss'; export const MainHeader = (ServersDropdown: FC) => () => { - const [isOpen, toggleOpen, , close] = useToggle(); + const [isNotCollapsed, toggleCollapse, , collapse] = useToggle(); const location = useLocation(); const { pathname } = location; - useEffect(close, [location]); + // In mobile devices, collapse the navbar when location changes + useEffect(collapse, [location, collapse]); const settingsPath = '/settings'; - const toggleClass = classNames('main-header__toggle-icon', { 'main-header__toggle-icon--opened': isOpen }); + const toggleClass = classNames('main-header__toggle-icon', { 'main-header__toggle-icon--opened': isNotCollapsed }); return ( @@ -25,11 +26,11 @@ export const MainHeader = (ServersDropdown: FC) => () => { Shlink - + - +