Feature/update dependency react router dom to v6.x (#340)

* Update dependency "react-router-dom" to v6.x

Update to v6.11.2

* Update dependency "react-router-dom" to v6.x - Replace "Switch" with "Routes"

* Update dependency "react-router-dom" to v6.x - Relative paths

* Update dependency "react-router-dom" to v6.x - Nested routes

* Update dependency "react-router-dom" to v6.x - Prevent route warnings

 - Route without an element causes a warning message.
 - Routes with non-matching Route causes a warning message.

* Update dependency "react-router-dom" to v6.x - Replace "useHistory" with "useNavigate"

* Update dependency "react-router-dom" to v6.x - Fix "Link" usage

* Update dependency "react-router-dom" to v6.x - Overwrite "useParams" and "useLocations" typing

For both functions it's the users fault if they are getting used incorrectly.
It's inconvenient to always have to make sure the params exist (useParam) or to cast the return object to a specific type (useLocation)

 - "useParams": Make generic type non-optional
 - "useLocation": Add generic type

* Update dependency "react-router-dom" to v6.x - Fix use-query-params provider
This commit is contained in:
schroda
2023-06-04 21:30:15 +02:00
committed by GitHub
parent fd5a1e240a
commit 4e8813b526
15 changed files with 114 additions and 224 deletions

View File

@@ -11,7 +11,7 @@ import AppBar from '@mui/material/AppBar';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import IconButton from '@mui/material/IconButton';
import { useMediaQuery, Box } from '@mui/material';
import { Box, useMediaQuery } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import CollectionsBookmarkIcon from '@mui/icons-material/CollectionsBookmark';
import CollectionsOutlinedBookmarkIcon from '@mui/icons-material/CollectionsBookmarkOutlined';
@@ -24,7 +24,7 @@ import GetAppIcon from '@mui/icons-material/GetApp';
import GetAppOutlinedIcon from '@mui/icons-material/GetAppOutlined';
import SettingsIcon from '@mui/icons-material/Settings';
import ArrowBack from '@mui/icons-material/ArrowBack';
import { Link, useHistory } from 'react-router-dom';
import { Link, useLocation, useNavigate } from 'react-router-dom';
import NavBarContext from 'components/context/NavbarContext';
import ExtensionOutlinedIcon from 'components/util/CustomExtensionOutlinedIcon';
import { createPortal } from 'react-dom';
@@ -90,10 +90,11 @@ export default function DefaultNavBar() {
const backTo = useBackTo();
const theme = useTheme();
const history = useHistory();
const navigate = useNavigate();
const { pathname } = useLocation();
const isMobileWidth = useMediaQuery(theme.breakpoints.down('sm'));
const isMainRoute = navbarItems.some(({ path }) => path === history.location.pathname);
const isMainRoute = navbarItems.some(({ path }) => path === pathname);
// Allow default navbar to be overrided
if (override.status) return override.value;
@@ -109,7 +110,7 @@ export default function DefaultNavBar() {
const handleBack = () => {
if (backTo.url != null) return;
history.goBack();
navigate(-1);
};
return (

View File

@@ -14,7 +14,7 @@ import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
import React, { useEffect, useState } from 'react';
import Typography from '@mui/material/Typography';
import { useHistory, useLocation } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import Slide from '@mui/material/Slide';
import Fade from '@mui/material/Fade';
import Zoom from '@mui/material/Zoom';
@@ -125,7 +125,7 @@ interface IProps {
export default function ReaderNavBar(props: IProps) {
const { t } = useTranslation();
const history = useHistory();
const navigate = useNavigate();
const backTo = useBackTo();
const location = useLocation<{
prevDrawerOpen?: boolean;
@@ -188,9 +188,9 @@ export default function ReaderNavBar(props: IProps) {
}, [handleScroll]); // handleScroll changes on every render
const handleClose = () => {
if (backTo.back) history.goBack();
else if (backTo.url) history.push(backTo.url);
else history.push(`/manga/${manga.id}`);
if (backTo.back) navigate(-1);
else if (backTo.url) navigate(backTo.url);
else navigate(`/manga/${manga.id}`);
};
return (
@@ -300,8 +300,8 @@ export default function ReaderNavBar(props: IProps) {
disabled={disableChapterNavButtons || chapter.index <= 1}
onClick={() =>
openNextChapter(ChapterOffset.PREV, (prevChapterIndex) => {
history.replace({
pathname: `/manga/${manga.id}/chapter/${prevChapterIndex}`,
navigate(`/manga/${manga.id}/chapter/${prevChapterIndex}`, {
replace: true,
state: {
prevDrawerOpen: drawerOpen,
prevSettingsCollapseOpen: settingsCollapseOpen,
@@ -322,8 +322,8 @@ export default function ReaderNavBar(props: IProps) {
value={chapter.index >= 1 ? chapter.index : ''}
displayEmpty
onChange={({ target: { value: selectedChapter } }) => {
history.replace({
pathname: `/manga/${manga.id}/chapter/${selectedChapter}`,
navigate(`/manga/${manga.id}/chapter/${selectedChapter}`, {
replace: true,
state: {
prevDrawerOpen: drawerOpen,
prevSettingsCollapseOpen: settingsCollapseOpen,
@@ -350,8 +350,8 @@ export default function ReaderNavBar(props: IProps) {
}
onClick={() => {
openNextChapter(ChapterOffset.NEXT, (nextChapterIndex) =>
history.replace({
pathname: `/manga/${manga.id}/chapter/${nextChapterIndex}`,
navigate(`/manga/${manga.id}/chapter/${nextChapterIndex}`, {
replace: true,
state: {
prevDrawerOpen: drawerOpen,
prevSettingsCollapseOpen: settingsCollapseOpen,