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:
@@ -118,10 +118,8 @@ const DownloadQueue: React.FC = () => {
|
||||
>
|
||||
<CardActionArea
|
||||
component={Link}
|
||||
to={{
|
||||
pathname: `/manga/${item.chapter.mangaId}`,
|
||||
state: { backLink: BACK },
|
||||
}}
|
||||
to={`/manga/${item.chapter.mangaId}`}
|
||||
state={{ backLink: BACK }}
|
||||
sx={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import CircularProgress from '@mui/material/CircularProgress';
|
||||
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
||||
import { useHistory, useParams } from 'react-router-dom';
|
||||
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
||||
import HorizontalPager from 'components/reader/pager/HorizontalPager';
|
||||
import PageNumber from 'components/reader/PageNumber';
|
||||
import PagedPager from 'components/reader/pager/PagedPager';
|
||||
@@ -89,7 +89,8 @@ const initialChapter = {
|
||||
|
||||
export default function Reader() {
|
||||
const { t } = useTranslation();
|
||||
const history = useHistory();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
const { chapterIndex, mangaId } = useParams<{ chapterIndex: string; mangaId: string }>();
|
||||
const {
|
||||
@@ -214,9 +215,9 @@ export default function Reader() {
|
||||
});
|
||||
|
||||
openNextChapter(ChapterOffset.NEXT, (nextChapterIndex) =>
|
||||
history.replace({
|
||||
pathname: `/manga/${manga.id}/chapter/${nextChapterIndex}`,
|
||||
state: history.location.state,
|
||||
navigate(`/manga/${manga.id}/chapter/${nextChapterIndex}`, {
|
||||
replace: true,
|
||||
state: location.state,
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -225,9 +226,9 @@ export default function Reader() {
|
||||
const prevChapter = useCallback(() => {
|
||||
if (chapter.index > 1) {
|
||||
openNextChapter(ChapterOffset.PREV, (prevChapterIndex) =>
|
||||
history.replace({
|
||||
pathname: `/manga/${manga.id}/chapter/${prevChapterIndex}`,
|
||||
state: history.location.state,
|
||||
navigate(`/manga/${manga.id}/chapter/${prevChapterIndex}`, {
|
||||
replace: true,
|
||||
state: location.state,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { useParams, useHistory } from 'react-router-dom';
|
||||
import { useParams, useNavigate, useLocation } from 'react-router-dom';
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
import SourceMangaGrid from 'components/source/SourceMangaGrid';
|
||||
import NavbarContext from 'components/context/NavbarContext';
|
||||
@@ -162,8 +162,10 @@ export default function SourceMangas() {
|
||||
|
||||
const { sourceId } = useParams<{ sourceId: string }>();
|
||||
|
||||
const history = useHistory<{ contentType: SourceContentType }>();
|
||||
const { contentType: currentLocationContentType = SourceContentType.POPULAR } = history.location.state ?? {};
|
||||
const navigate = useNavigate();
|
||||
const { state: { contentType: currentLocationContentType = SourceContentType.POPULAR } = {} } = useLocation<{
|
||||
contentType: SourceContentType;
|
||||
}>();
|
||||
|
||||
const { options } = useLibraryOptionsContext();
|
||||
const [query] = useQueryParam('query', StringParam);
|
||||
@@ -233,7 +235,7 @@ export default function SourceMangas() {
|
||||
|
||||
const updateContentType = useCallback(
|
||||
(newContentType: SourceContentType) => {
|
||||
history.replace(sourceId, { contentType: newContentType });
|
||||
navigate('', { replace: true, state: { contentType: newContentType } });
|
||||
setContentType(newContentType);
|
||||
},
|
||||
[setContentType],
|
||||
@@ -267,7 +269,7 @@ export default function SourceMangas() {
|
||||
<SourceGridLayout />
|
||||
{source?.isConfigurable && (
|
||||
<IconButton
|
||||
onClick={() => history.push(`/sources/${sourceId}/configure/`)}
|
||||
onClick={() => navigate(`/sources/${sourceId}/configure/`)}
|
||||
aria-label="display more actions"
|
||||
edge="end"
|
||||
color="inherit"
|
||||
|
||||
@@ -15,7 +15,7 @@ import useLocalStorage from 'util/useLocalStorage';
|
||||
import LoadingPlaceholder from 'components/util/LoadingPlaceholder';
|
||||
import { IconButton } from '@mui/material';
|
||||
import TravelExploreIcon from '@mui/icons-material/TravelExplore';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { ISource } from 'typings';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { translateExtensionLanguage } from 'screens/util/Extensions';
|
||||
@@ -55,7 +55,7 @@ export default function Sources() {
|
||||
|
||||
const { data: sources, isLoading } = requestManager.useGetSourceList();
|
||||
|
||||
const history = useHistory();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
// make sure all of forcedDefaultLangs() exists in shownLangs
|
||||
@@ -77,7 +77,7 @@ export default function Sources() {
|
||||
setTitle(t('source.title'));
|
||||
setAction(
|
||||
<>
|
||||
<IconButton onClick={() => history.push('/sources/all/search/')} size="large">
|
||||
<IconButton onClick={() => navigate('/sources/all/search/')} size="large">
|
||||
<TravelExploreIcon />
|
||||
</IconButton>
|
||||
<LangSelect
|
||||
|
||||
@@ -18,7 +18,7 @@ import DownloadStateIndicator from 'components/molecules/DownloadStateIndicator'
|
||||
import EmptyView from 'components/util/EmptyView';
|
||||
import LoadingPlaceholder from 'components/util/LoadingPlaceholder';
|
||||
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { Link, useHistory } from 'react-router-dom';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { IChapter, IMangaChapter, IQueue } from 'typings';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { t as translate } from 'i18next';
|
||||
@@ -102,7 +102,7 @@ const initialQueue = {
|
||||
|
||||
const Updates: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
const history = useHistory();
|
||||
const location = useLocation();
|
||||
|
||||
const { setTitle, setAction } = useContext(NavbarContext);
|
||||
const {
|
||||
@@ -187,10 +187,8 @@ const Updates: React.FC = () => {
|
||||
<Card>
|
||||
<CardActionArea
|
||||
component={Link}
|
||||
to={{
|
||||
pathname: `/manga/${chapter.mangaId}/chapter/${chapter.index}`,
|
||||
state: history.location.state,
|
||||
}}
|
||||
to={`/manga/${chapter.mangaId}/chapter/${chapter.index}`}
|
||||
state={location.state}
|
||||
>
|
||||
<CardContent
|
||||
sx={{
|
||||
|
||||
Reference in New Issue
Block a user