2021-03-26 04:17:02 +04:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2021-01-26 23:32:12 +03:30
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2021-01-26 23:32:12 +03:30
|
|
|
|
2023-08-14 21:43:06 +02:00
|
|
|
import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
2023-06-04 21:30:15 +02:00
|
|
|
import { useParams, useNavigate, useLocation } from 'react-router-dom';
|
2021-09-09 22:57:19 +04:30
|
|
|
import IconButton from '@mui/material/IconButton';
|
|
|
|
|
import SettingsIcon from '@mui/icons-material/Settings';
|
2022-03-04 01:25:10 +00:00
|
|
|
import { useQueryParam, StringParam } from 'use-query-params';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-05-12 11:52:00 +02:00
|
|
|
import Link from '@mui/material/Link';
|
2024-04-14 15:50:12 +02:00
|
|
|
import Box from '@mui/material/Box';
|
|
|
|
|
import Button from '@mui/material/Button';
|
|
|
|
|
import Tooltip from '@mui/material/Tooltip';
|
|
|
|
|
import { styled } from '@mui/material/styles';
|
2023-05-28 12:16:06 +02:00
|
|
|
import FavoriteIcon from '@mui/icons-material/Favorite';
|
|
|
|
|
import NewReleasesIcon from '@mui/icons-material/NewReleases';
|
|
|
|
|
import FilterListIcon from '@mui/icons-material/FilterList';
|
2024-05-08 04:01:23 +02:00
|
|
|
import { IPos, TPartialManga, TPartialSource, TranslationKey } from '@/typings';
|
2023-11-11 23:43:22 +01:00
|
|
|
import {
|
|
|
|
|
requestManager,
|
|
|
|
|
AbortableApolloUseMutationPaginatedResponse,
|
|
|
|
|
SPECIAL_ED_SOURCES,
|
|
|
|
|
} from '@/lib/requests/RequestManager.ts';
|
2023-06-05 01:42:39 +02:00
|
|
|
import { useLibraryOptionsContext } from '@/components/context/LibraryOptionsContext';
|
2024-01-26 20:50:51 +01:00
|
|
|
import { SourceGridLayout } from '@/components/source/SourceGridLayout';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { AppbarSearch } from '@/components/util/AppbarSearch';
|
|
|
|
|
import { SourceOptions } from '@/components/source/SourceOptions';
|
|
|
|
|
import { SourceMangaGrid } from '@/components/source/SourceMangaGrid';
|
2023-09-12 02:36:11 +02:00
|
|
|
import {
|
|
|
|
|
GetSourceMangasFetchMutation,
|
|
|
|
|
GetSourceMangasFetchMutationVariables,
|
|
|
|
|
} from '@/lib/graphql/generated/graphql.ts';
|
2024-06-05 23:04:13 +02:00
|
|
|
import { NavBarContext } from '@/components/context/NavbarContext.tsx';
|
2024-03-23 23:44:46 +01:00
|
|
|
import { useMetadataServerSettings } from '@/lib/metadata/metadataServerSettings.ts';
|
2024-04-07 15:22:03 +02:00
|
|
|
import { useSessionStorage } from '@/util/useStorage.tsx';
|
2024-04-16 02:49:08 +02:00
|
|
|
import { AppStorage } from '@/util/AppStorage.ts';
|
|
|
|
|
import { getGridSnapshotKey } from '@/components/MangaGrid.tsx';
|
2024-05-08 04:01:23 +02:00
|
|
|
import { createUpdateSourceMetadata, getSourceMetadata } from '@/lib/metadata/sourceMetadata.ts';
|
|
|
|
|
import { makeToast } from '@/components/util/Toast.tsx';
|
2023-05-28 12:16:06 +02:00
|
|
|
|
|
|
|
|
const ContentTypeMenu = styled('div')(({ theme }) => ({
|
|
|
|
|
display: 'flex',
|
|
|
|
|
position: 'fixed',
|
|
|
|
|
top: '64px',
|
|
|
|
|
width: '100%',
|
|
|
|
|
zIndex: 1,
|
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
|
[theme.breakpoints.down('sm')]: {
|
|
|
|
|
top: '56px', // header height
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const ContentTypeButton = styled(Button)(() => ({
|
|
|
|
|
marginTop: '13px',
|
|
|
|
|
marginBottom: '13px',
|
|
|
|
|
marginLeft: '13px',
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const StyledGridWrapper = styled(Box, { shouldForwardProp: (prop) => prop !== 'hasContent' })<{ hasContent: boolean }>(
|
|
|
|
|
({ theme, hasContent }) => ({
|
|
|
|
|
// 62.5px ContentTypeMenu height (- padding of grid + grid item)
|
2023-06-17 16:50:17 +02:00
|
|
|
marginTop: `calc(62.5px ${hasContent ? '- 8px' : ''})`,
|
2023-05-28 12:16:06 +02:00
|
|
|
// header height - ContentTypeMenu height
|
|
|
|
|
minHeight: 'calc(100vh - 64px - 62.5px)',
|
|
|
|
|
position: 'relative',
|
|
|
|
|
[theme.breakpoints.down('sm')]: {
|
2023-06-17 16:50:17 +02:00
|
|
|
// 62.5px ContentTypeMenu - 8px margin diff header height (56px) (- padding of grid item)
|
|
|
|
|
marginTop: `calc(62.5px - 8px ${hasContent ? '- 8px' : ''})`,
|
2023-05-28 12:16:06 +02:00
|
|
|
// header height (+ 8px margin) - footer height - ContentTypeMenu height
|
|
|
|
|
minHeight: 'calc(100vh - 64px - 64px - 62.5px)',
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export enum SourceContentType {
|
|
|
|
|
POPULAR,
|
|
|
|
|
LATEST,
|
|
|
|
|
SEARCH,
|
|
|
|
|
}
|
2022-03-04 01:25:10 +00:00
|
|
|
|
2023-05-28 12:16:06 +02:00
|
|
|
const SOURCE_CONTENT_TYPE_TO_ERROR_MSG_KEY: { [contentType in SourceContentType]: TranslationKey } = {
|
|
|
|
|
[SourceContentType.POPULAR]: 'manga.error.label.no_mangas_found',
|
|
|
|
|
[SourceContentType.LATEST]: 'manga.error.label.no_mangas_found',
|
2024-01-11 02:57:56 +01:00
|
|
|
[SourceContentType.SEARCH]: 'manga.error.label.no_matches',
|
2023-05-28 12:16:06 +02:00
|
|
|
};
|
|
|
|
|
|
2023-10-15 16:03:08 +02:00
|
|
|
const getUniqueMangas = (mangas: TPartialManga[]): TPartialManga[] => {
|
2024-05-05 23:27:52 +02:00
|
|
|
const mangaIdToManga: Record<TPartialManga['id'], TPartialManga> = {};
|
2023-10-15 16:03:08 +02:00
|
|
|
const uniqueMangas: TPartialManga[] = [];
|
2023-05-28 12:16:06 +02:00
|
|
|
|
|
|
|
|
mangas.forEach((manga) => {
|
2024-05-05 23:27:52 +02:00
|
|
|
const isDuplicate = !!mangaIdToManga[manga.id];
|
2023-05-28 12:16:06 +02:00
|
|
|
if (!isDuplicate) {
|
2024-05-05 23:27:52 +02:00
|
|
|
mangaIdToManga[manga.id] = manga;
|
2023-05-28 12:16:06 +02:00
|
|
|
uniqueMangas.push(manga);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return uniqueMangas;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const useSourceManga = (
|
|
|
|
|
sourceId: string,
|
|
|
|
|
contentType: SourceContentType,
|
|
|
|
|
searchTerm: string | null | undefined,
|
|
|
|
|
filters: IPos[],
|
2023-09-12 02:36:11 +02:00
|
|
|
initialPages: number,
|
2024-03-23 23:44:46 +01:00
|
|
|
hideLibraryEntries: boolean,
|
2023-09-12 02:36:11 +02:00
|
|
|
): [
|
|
|
|
|
AbortableApolloUseMutationPaginatedResponse<GetSourceMangasFetchMutation, GetSourceMangasFetchMutationVariables>[0],
|
|
|
|
|
AbortableApolloUseMutationPaginatedResponse<
|
|
|
|
|
GetSourceMangasFetchMutation,
|
|
|
|
|
GetSourceMangasFetchMutationVariables
|
2024-03-23 23:44:46 +01:00
|
|
|
>[1][number] & { filteredOutAllItemsOfFetchedPage: boolean },
|
2023-09-12 02:36:11 +02:00
|
|
|
] => {
|
|
|
|
|
let result: AbortableApolloUseMutationPaginatedResponse<
|
|
|
|
|
GetSourceMangasFetchMutation,
|
|
|
|
|
GetSourceMangasFetchMutationVariables
|
|
|
|
|
>;
|
2023-05-28 12:16:06 +02:00
|
|
|
switch (contentType) {
|
|
|
|
|
case SourceContentType.POPULAR:
|
2023-06-17 16:50:17 +02:00
|
|
|
result = requestManager.useGetSourcePopularMangas(sourceId, initialPages);
|
2023-05-28 12:16:06 +02:00
|
|
|
break;
|
|
|
|
|
case SourceContentType.LATEST:
|
2023-06-17 16:50:17 +02:00
|
|
|
result = requestManager.useGetSourceLatestMangas(sourceId, initialPages);
|
2023-05-28 12:16:06 +02:00
|
|
|
break;
|
|
|
|
|
case SourceContentType.SEARCH:
|
2023-09-24 21:32:23 +02:00
|
|
|
result = requestManager.useSourceSearch(
|
|
|
|
|
sourceId,
|
2024-01-11 02:57:56 +01:00
|
|
|
searchTerm ?? '',
|
2023-09-24 21:32:23 +02:00
|
|
|
filters.map((filter) => {
|
|
|
|
|
const { position, state, group } = filter;
|
|
|
|
|
|
|
|
|
|
const isPartOfGroup = group !== undefined;
|
|
|
|
|
if (isPartOfGroup) {
|
|
|
|
|
return {
|
|
|
|
|
position: group,
|
|
|
|
|
groupChange: {
|
|
|
|
|
position,
|
|
|
|
|
[filter.type]: state,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
position,
|
|
|
|
|
[filter.type]: state,
|
|
|
|
|
};
|
|
|
|
|
}),
|
|
|
|
|
initialPages,
|
|
|
|
|
);
|
2023-05-28 12:16:06 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new Error(`Unknown ContentType "${contentType}"`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-12 02:36:11 +02:00
|
|
|
const pages = result[1]!;
|
|
|
|
|
const lastLoadedPageIndex = pages.findLastIndex((page) => !!page.data?.fetchSourceManga);
|
|
|
|
|
const lastLoadedPage = pages[lastLoadedPageIndex];
|
2023-05-28 12:16:06 +02:00
|
|
|
|
2024-03-23 23:44:46 +01:00
|
|
|
const isPageLoading = pages.slice(-1)[0].isLoading;
|
|
|
|
|
let filteredOutAllItemsOfFetchedPage = !isPageLoading;
|
|
|
|
|
const items = useMemo(() => {
|
2024-06-02 15:24:29 +02:00
|
|
|
type FetchItemsResult = NonNullable<GetSourceMangasFetchMutation['fetchSourceManga']>['mangas'];
|
2024-03-23 23:44:46 +01:00
|
|
|
let allItems: FetchItemsResult = [];
|
|
|
|
|
|
|
|
|
|
pages.forEach((page, index) => {
|
2024-06-02 15:24:29 +02:00
|
|
|
const pageItems = page.data?.fetchSourceManga?.mangas ?? ([] as FetchItemsResult);
|
2024-05-05 23:27:52 +02:00
|
|
|
const nonLibraryPageItems = pageItems.filter((item) => !hideLibraryEntries || !item.inLibrary);
|
|
|
|
|
const uniqueItems = getUniqueMangas([...allItems, ...nonLibraryPageItems]);
|
2024-03-23 23:44:46 +01:00
|
|
|
|
|
|
|
|
const isLastPage = !isPageLoading && pages.length === index + 1;
|
2024-05-05 23:27:52 +02:00
|
|
|
filteredOutAllItemsOfFetchedPage = isLastPage && !nonLibraryPageItems.length && !!pageItems.length;
|
|
|
|
|
allItems = uniqueItems;
|
2024-03-23 23:44:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return allItems;
|
|
|
|
|
}, [pages, hideLibraryEntries]);
|
|
|
|
|
|
|
|
|
|
if (lastLoadedPageIndex === -1) {
|
|
|
|
|
return [result[0], { ...result[1][result[1].length - 1], filteredOutAllItemsOfFetchedPage }];
|
2023-09-12 02:36:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
result[0],
|
|
|
|
|
{
|
|
|
|
|
...pages[pages.length - 1],
|
|
|
|
|
data: {
|
|
|
|
|
...lastLoadedPage!.data,
|
|
|
|
|
fetchSourceManga: {
|
|
|
|
|
...lastLoadedPage!.data!.fetchSourceManga,
|
|
|
|
|
hasNextPage:
|
|
|
|
|
pages.length > lastLoadedPageIndex + 1
|
|
|
|
|
? false
|
2024-06-02 15:24:29 +02:00
|
|
|
: !!lastLoadedPage!.data!.fetchSourceManga?.hasNextPage,
|
2024-03-23 23:44:46 +01:00
|
|
|
mangas: items,
|
2023-09-12 02:36:11 +02:00
|
|
|
},
|
|
|
|
|
},
|
2024-03-23 23:44:46 +01:00
|
|
|
filteredOutAllItemsOfFetchedPage,
|
2023-09-12 02:36:11 +02:00
|
|
|
},
|
|
|
|
|
];
|
2023-05-28 12:16:06 +02:00
|
|
|
};
|
|
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export function SourceMangas() {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
2023-10-28 00:32:02 +02:00
|
|
|
const { setTitle, setAction } = useContext(NavBarContext);
|
2023-11-12 03:21:26 +01:00
|
|
|
|
2021-05-13 17:46:40 +04:30
|
|
|
const { sourceId } = useParams<{ sourceId: string }>();
|
2023-05-18 13:25:19 +02:00
|
|
|
|
2023-06-04 21:30:15 +02:00
|
|
|
const navigate = useNavigate();
|
2024-04-16 02:49:08 +02:00
|
|
|
const location = useLocation();
|
|
|
|
|
const { key: locationKey, state: locationState } = location;
|
2024-04-07 15:22:03 +02:00
|
|
|
const { contentType: initialContentType = SourceContentType.POPULAR, clearCache = false } =
|
|
|
|
|
useLocation<{
|
|
|
|
|
contentType: SourceContentType;
|
|
|
|
|
clearCache: boolean;
|
|
|
|
|
}>().state ?? {};
|
2023-11-12 03:21:26 +01:00
|
|
|
|
2024-01-11 02:57:56 +01:00
|
|
|
const [isFirstRender, setIsFirstRender] = useState(true);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setIsFirstRender(false);
|
|
|
|
|
}, []);
|
|
|
|
|
|
2024-03-23 23:44:46 +01:00
|
|
|
const {
|
|
|
|
|
settings: { hideLibraryEntries },
|
|
|
|
|
} = useMetadataServerSettings();
|
|
|
|
|
|
2023-05-28 12:16:06 +02:00
|
|
|
const { options } = useLibraryOptionsContext();
|
|
|
|
|
const [query] = useQueryParam('query', StringParam);
|
2024-04-14 15:18:51 +02:00
|
|
|
const [currentFiltersToApply, setCurrentFiltersToApply] = useSessionStorage<IPos[] | undefined>(
|
|
|
|
|
`source-mangas-${sourceId}-filters`,
|
2024-04-07 15:22:03 +02:00
|
|
|
[],
|
|
|
|
|
);
|
2024-04-14 15:18:51 +02:00
|
|
|
const [filtersToApply, setLocationFiltersToApply] = useSessionStorage<IPos[]>(
|
|
|
|
|
`source-mangas-location-${locationKey}-${sourceId}-filters`,
|
|
|
|
|
currentFiltersToApply ?? [],
|
|
|
|
|
);
|
2024-04-07 15:22:03 +02:00
|
|
|
const [dialogFiltersToApply, setDialogFiltersToApply] = useState<IPos[]>(filtersToApply);
|
2024-04-14 15:22:35 +02:00
|
|
|
const [currentContentType, setCurrentContentType] = useSessionStorage<SourceContentType | undefined>(
|
|
|
|
|
`source-mangas-${sourceId}-content-type`,
|
|
|
|
|
initialContentType,
|
|
|
|
|
);
|
|
|
|
|
const [contentType, setLocationContentType] = useSessionStorage(
|
2024-04-07 15:22:03 +02:00
|
|
|
`source-mangas-location-${locationKey}-${sourceId}-content-type`,
|
2024-04-14 15:22:35 +02:00
|
|
|
query ? SourceContentType.SEARCH : currentContentType!,
|
2024-04-07 15:22:03 +02:00
|
|
|
);
|
|
|
|
|
|
2024-04-14 15:18:51 +02:00
|
|
|
useEffect(
|
|
|
|
|
() => () => {
|
|
|
|
|
setCurrentFiltersToApply(undefined);
|
2024-04-14 15:22:35 +02:00
|
|
|
setCurrentContentType(undefined);
|
2024-04-14 15:18:51 +02:00
|
|
|
},
|
|
|
|
|
[sourceId],
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-16 02:49:08 +02:00
|
|
|
const scrollToTop = useCallback(() => {
|
2024-04-16 02:49:57 +02:00
|
|
|
AppStorage.session.setItem(getGridSnapshotKey(location), undefined, false);
|
2024-04-16 02:49:08 +02:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
|
}, [locationKey]);
|
|
|
|
|
|
2024-04-14 15:18:51 +02:00
|
|
|
const setFiltersToApply = (filters: IPos[]) => {
|
|
|
|
|
setCurrentFiltersToApply(filters);
|
|
|
|
|
setLocationFiltersToApply(filters);
|
2024-04-16 02:49:08 +02:00
|
|
|
scrollToTop();
|
2024-04-14 15:18:51 +02:00
|
|
|
};
|
|
|
|
|
|
2024-04-14 15:22:35 +02:00
|
|
|
const setContentType = (newContentType: SourceContentType) => {
|
|
|
|
|
setCurrentContentType(newContentType);
|
|
|
|
|
setLocationContentType(newContentType);
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-23 23:44:46 +01:00
|
|
|
const [loadPage, { data, isLoading: loading, size: lastPageNum, abortRequest, filteredOutAllItemsOfFetchedPage }] =
|
2024-04-07 15:22:03 +02:00
|
|
|
useSourceManga(sourceId, contentType, query, filtersToApply, 1, hideLibraryEntries);
|
2024-03-23 23:44:46 +01:00
|
|
|
const isLoading = loading || filteredOutAllItemsOfFetchedPage;
|
2024-06-02 15:24:29 +02:00
|
|
|
const mangas = data?.fetchSourceManga?.mangas ?? [];
|
|
|
|
|
const hasNextPage = !!data?.fetchSourceManga?.hasNextPage;
|
2023-09-12 02:36:11 +02:00
|
|
|
const { data: sourceData } = requestManager.useGetSource(sourceId);
|
|
|
|
|
const source = sourceData?.source;
|
2024-05-08 04:01:23 +02:00
|
|
|
|
2023-09-24 21:32:23 +02:00
|
|
|
const filters = source?.filters ?? [];
|
2024-05-08 04:01:23 +02:00
|
|
|
const { savedSearches = {} } = useMemo(() => getSourceMetadata(source), [source, source?.meta]);
|
|
|
|
|
const updateSourceMetadata = createUpdateSourceMetadata<'savedSearches'>(
|
|
|
|
|
source ?? ({ id: sourceId } as TPartialSource),
|
|
|
|
|
() => makeToast(t('global.error.label.failed_to_save_changes'), 'error'),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const selectSavedSearch = useCallback(
|
|
|
|
|
(savedSearch: string) => {
|
|
|
|
|
const { query: savedSearchQuery, filters: savedSearchFilters } = savedSearches[savedSearch];
|
|
|
|
|
|
|
|
|
|
if (savedSearchFilters) {
|
|
|
|
|
setDialogFiltersToApply(savedSearchFilters);
|
|
|
|
|
setFiltersToApply(savedSearchFilters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
navigate(
|
|
|
|
|
{
|
|
|
|
|
pathname: '',
|
|
|
|
|
search: savedSearchQuery ? `query=${savedSearchQuery}` : undefined,
|
|
|
|
|
},
|
|
|
|
|
{ state: { ...locationState, contentType: SourceContentType.SEARCH } },
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
[savedSearches, locationState],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const handleSavedSearchesUpdate = useCallback(
|
|
|
|
|
(savedSearch: string, updateType: 'create' | 'delete') => {
|
|
|
|
|
if (updateType === 'delete') {
|
|
|
|
|
const savedSearchesCopy = { ...savedSearches };
|
|
|
|
|
delete savedSearchesCopy[savedSearch];
|
|
|
|
|
updateSourceMetadata('savedSearches', savedSearchesCopy);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const updatedSavedSearches = {
|
|
|
|
|
...savedSearches,
|
|
|
|
|
[savedSearch]: { query: query ?? undefined, filters: filtersToApply },
|
|
|
|
|
};
|
|
|
|
|
updateSourceMetadata('savedSearches', updatedSavedSearches);
|
|
|
|
|
},
|
|
|
|
|
[savedSearches, query, filtersToApply],
|
|
|
|
|
);
|
2022-03-04 01:25:10 +00:00
|
|
|
|
2023-07-04 21:53:25 +02:00
|
|
|
const message = !isLoading ? t(SOURCE_CONTENT_TYPE_TO_ERROR_MSG_KEY[contentType]) : undefined;
|
2023-05-28 12:16:06 +02:00
|
|
|
const isLocalSource = sourceId === '0';
|
|
|
|
|
const messageExtra = isLocalSource ? (
|
|
|
|
|
<>
|
|
|
|
|
<span>{t('source.local_source.label.checkout')} </span>
|
2024-05-04 23:54:33 +02:00
|
|
|
<Link href="https://github.com/Suwayomi/Suwayomi-Server/wiki/Local-Source" target="_blank" rel="noreferrer">
|
2023-05-28 12:16:06 +02:00
|
|
|
{t('source.local_source.label.guide')}
|
|
|
|
|
</Link>
|
|
|
|
|
</>
|
|
|
|
|
) : undefined;
|
2022-03-06 21:02:06 +00:00
|
|
|
|
2023-06-17 16:29:55 +02:00
|
|
|
const updateContentType = useCallback(
|
2024-04-07 15:22:03 +02:00
|
|
|
(newContentType: SourceContentType, newSearch?: string | null) => {
|
|
|
|
|
setContentType(newContentType);
|
2024-04-16 02:49:08 +02:00
|
|
|
scrollToTop();
|
2024-04-07 15:22:03 +02:00
|
|
|
|
|
|
|
|
if (query && !newSearch) {
|
2024-01-11 02:57:56 +01:00
|
|
|
navigate(
|
|
|
|
|
{
|
2024-04-07 15:22:03 +02:00
|
|
|
pathname: '',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
state: { ...locationState, contentType: newContentType },
|
2024-01-11 02:57:56 +01:00
|
|
|
},
|
|
|
|
|
);
|
2023-06-17 16:29:55 +02:00
|
|
|
}
|
|
|
|
|
},
|
2024-04-16 02:49:08 +02:00
|
|
|
[setContentType, query, scrollToTop],
|
2023-09-24 22:34:37 +02:00
|
|
|
);
|
|
|
|
|
|
2024-04-07 15:22:03 +02:00
|
|
|
const setSearchContentType = !!query && contentType !== SourceContentType.SEARCH;
|
2023-05-28 12:16:06 +02:00
|
|
|
if (setSearchContentType) {
|
2024-04-07 15:22:03 +02:00
|
|
|
updateContentType(SourceContentType.SEARCH, query);
|
2023-05-28 12:16:06 +02:00
|
|
|
}
|
2021-09-13 19:18:21 +04:30
|
|
|
|
2023-06-17 16:50:17 +02:00
|
|
|
const loadMore = useCallback(() => {
|
|
|
|
|
if (!hasNextPage) {
|
2023-05-18 13:25:19 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-12 02:36:11 +02:00
|
|
|
loadPage(lastPageNum + 1);
|
|
|
|
|
}, [lastPageNum, hasNextPage, contentType]);
|
2022-03-04 01:25:10 +00:00
|
|
|
|
2024-05-08 04:01:23 +02:00
|
|
|
const resetFilters = () => {
|
2023-05-28 12:16:06 +02:00
|
|
|
setDialogFiltersToApply([]);
|
|
|
|
|
setFiltersToApply([]);
|
2024-05-08 04:01:23 +02:00
|
|
|
};
|
2023-05-28 12:16:06 +02:00
|
|
|
|
2024-03-23 23:44:46 +01:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (filteredOutAllItemsOfFetchedPage && hasNextPage && !loading) {
|
|
|
|
|
loadPage(lastPageNum + 1);
|
|
|
|
|
}
|
|
|
|
|
}, [filteredOutAllItemsOfFetchedPage, loading]);
|
|
|
|
|
|
2023-11-11 23:43:22 +01:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (!clearCache) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const requiresClear = SPECIAL_ED_SOURCES.REVALIDATION.includes(sourceId);
|
|
|
|
|
if (!requiresClear) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
requestManager.clearBrowseCacheFor(sourceId);
|
|
|
|
|
}, [clearCache]);
|
|
|
|
|
|
2023-05-28 12:16:06 +02:00
|
|
|
useEffect(
|
|
|
|
|
() => () => {
|
2024-01-11 02:57:56 +01:00
|
|
|
if (contentType !== SourceContentType.SEARCH || isFirstRender) {
|
2023-05-28 12:16:06 +02:00
|
|
|
return;
|
2023-02-06 10:06:33 +01:00
|
|
|
}
|
2023-06-10 00:42:26 +02:00
|
|
|
// INFO:
|
|
|
|
|
// with strict mode + dev mode the first request will be aborted. due to using SWR there won't be an
|
|
|
|
|
// immediate second request since it's the same key. instead the "second" request will be the error handling of SWR
|
2023-05-28 12:16:06 +02:00
|
|
|
abortRequest(new Error(`SourceMangas(${sourceId}): search string changed`));
|
2024-04-16 02:49:08 +02:00
|
|
|
scrollToTop();
|
2023-05-28 12:16:06 +02:00
|
|
|
},
|
2024-04-07 15:22:03 +02:00
|
|
|
[query],
|
2023-05-28 12:16:06 +02:00
|
|
|
);
|
2022-03-04 01:25:10 +00:00
|
|
|
|
2021-09-13 19:18:21 +04:30
|
|
|
useEffect(() => {
|
2023-05-28 12:16:06 +02:00
|
|
|
setTitle(source?.displayName ?? t('source.title'));
|
2021-09-09 22:57:19 +04:30
|
|
|
setAction(
|
|
|
|
|
<>
|
2022-03-04 01:25:10 +00:00
|
|
|
<AppbarSearch />
|
2023-05-28 12:16:06 +02:00
|
|
|
<SourceGridLayout />
|
|
|
|
|
{source?.isConfigurable && (
|
2023-11-05 17:22:29 +01:00
|
|
|
<Tooltip title={t('settings.title')}>
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => navigate(`/sources/${sourceId}/configure/`)}
|
|
|
|
|
aria-label="display more actions"
|
|
|
|
|
edge="end"
|
|
|
|
|
color="inherit"
|
|
|
|
|
size="large"
|
|
|
|
|
>
|
|
|
|
|
<SettingsIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Tooltip>
|
2021-09-09 22:57:19 +04:30
|
|
|
)}
|
2023-02-06 10:06:33 +01:00
|
|
|
</>,
|
2021-09-09 22:57:19 +04:30
|
|
|
);
|
2024-01-26 20:50:51 +01:00
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
setTitle('');
|
|
|
|
|
setAction(null);
|
|
|
|
|
};
|
2023-05-28 12:16:06 +02:00
|
|
|
}, [t, source]);
|
2021-09-18 00:05:00 +04:30
|
|
|
|
2021-01-22 21:11:00 +03:30
|
|
|
return (
|
2023-05-28 12:16:06 +02:00
|
|
|
<StyledGridWrapper hasContent={!!mangas.length}>
|
|
|
|
|
<ContentTypeMenu>
|
|
|
|
|
<ContentTypeButton
|
|
|
|
|
variant={contentType === SourceContentType.POPULAR ? 'contained' : 'outlined'}
|
|
|
|
|
startIcon={<FavoriteIcon />}
|
|
|
|
|
onClick={() => updateContentType(SourceContentType.POPULAR)}
|
|
|
|
|
>
|
|
|
|
|
{t('global.button.popular')}
|
|
|
|
|
</ContentTypeButton>
|
2023-11-05 17:22:16 +01:00
|
|
|
{source?.supportsLatest === undefined || source.supportsLatest ? (
|
|
|
|
|
<ContentTypeButton
|
|
|
|
|
disabled={!source?.supportsLatest}
|
|
|
|
|
variant={contentType === SourceContentType.LATEST ? 'contained' : 'outlined'}
|
|
|
|
|
startIcon={<NewReleasesIcon />}
|
|
|
|
|
onClick={() => updateContentType(SourceContentType.LATEST)}
|
|
|
|
|
>
|
|
|
|
|
{t('global.button.latest')}
|
|
|
|
|
</ContentTypeButton>
|
|
|
|
|
) : null}
|
2023-05-28 12:16:06 +02:00
|
|
|
<ContentTypeButton
|
2024-01-11 02:57:56 +01:00
|
|
|
variant={contentType === SourceContentType.SEARCH ? 'contained' : 'outlined'}
|
2023-05-28 12:16:06 +02:00
|
|
|
startIcon={<FilterListIcon />}
|
2024-04-07 15:22:03 +02:00
|
|
|
onClick={() => updateContentType(SourceContentType.SEARCH, query)}
|
2023-05-28 12:16:06 +02:00
|
|
|
>
|
|
|
|
|
{t('global.button.filter')}
|
|
|
|
|
</ContentTypeButton>
|
|
|
|
|
</ContentTypeMenu>
|
2022-03-04 01:25:10 +00:00
|
|
|
<SourceMangaGrid
|
2023-09-12 02:36:11 +02:00
|
|
|
key={contentType}
|
2023-06-17 15:45:18 +02:00
|
|
|
mangas={mangas}
|
2022-03-04 01:25:10 +00:00
|
|
|
hasNextPage={hasNextPage}
|
2023-06-17 16:50:17 +02:00
|
|
|
loadMore={loadMore}
|
2022-03-04 01:25:10 +00:00
|
|
|
message={message}
|
|
|
|
|
messageExtra={messageExtra}
|
2023-06-17 15:45:18 +02:00
|
|
|
isLoading={isLoading}
|
2022-03-06 21:02:06 +00:00
|
|
|
gridLayout={options.SourcegridLayout}
|
2022-03-04 01:25:10 +00:00
|
|
|
/>
|
2024-01-11 02:57:56 +01:00
|
|
|
{contentType === SourceContentType.SEARCH && (
|
2022-03-04 01:25:10 +00:00
|
|
|
<SourceOptions
|
2024-05-08 04:01:23 +02:00
|
|
|
savedSearches={savedSearches}
|
|
|
|
|
selectSavedSearch={selectSavedSearch}
|
|
|
|
|
updateSavedSearches={handleSavedSearchesUpdate}
|
2023-05-28 12:16:06 +02:00
|
|
|
sourceFilter={filters}
|
|
|
|
|
updateFilterValue={setDialogFiltersToApply}
|
|
|
|
|
setTriggerUpdate={() => {
|
|
|
|
|
setFiltersToApply(dialogFiltersToApply);
|
|
|
|
|
}}
|
|
|
|
|
resetFilterValue={resetFilters}
|
|
|
|
|
update={dialogFiltersToApply}
|
2022-03-04 01:25:10 +00:00
|
|
|
/>
|
|
|
|
|
)}
|
2023-05-28 12:16:06 +02:00
|
|
|
</StyledGridWrapper>
|
2021-01-22 21:11:00 +03:30
|
|
|
);
|
2021-01-19 14:47:07 +03:30
|
|
|
}
|