From daeab311211b2fd5cca35a015ad0074dc8b30b30 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Wed, 21 May 2025 00:58:28 +0200 Subject: [PATCH] Add button to perform search globally in library --- public/locales/en.json | 1 + src/modules/core/AppRoute.constants.ts | 6 +++++- src/modules/library/screens/Library.tsx | 25 ++++++++++++++++++++++++- src/modules/source/screens/Sources.tsx | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/public/locales/en.json b/public/locales/en.json index 345c535e..53644e68 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -555,6 +555,7 @@ "library": { "action": { "label": { + "search_globally": "Search for \"{{query}}\" globally", "stop_update": "Stop global update", "update_category": "Update category", "update_library": "Update library" diff --git a/src/modules/core/AppRoute.constants.ts b/src/modules/core/AppRoute.constants.ts index 7daef3ba..0d75c45b 100644 --- a/src/modules/core/AppRoute.constants.ts +++ b/src/modules/core/AppRoute.constants.ts @@ -106,7 +106,11 @@ export const AppRoutes = { }, searchAll: { match: 'all/search', - path: '/sources/all/search', + path: (query?: string | null | undefined) => { + const queryParam = query ? `query=${encodeURIComponent(query)}` : ''; + + return `/sources/all/search${queryParam ? `?${queryParam}` : ''}`; + }, }, }, }, diff --git a/src/modules/library/screens/Library.tsx b/src/modules/library/screens/Library.tsx index bb3fcfb8..5de565e4 100644 --- a/src/modules/library/screens/Library.tsx +++ b/src/modules/library/screens/Library.tsx @@ -10,8 +10,11 @@ import Chip, { ChipProps } from '@mui/material/Chip'; import Tab from '@mui/material/Tab'; import { styled } from '@mui/material/styles'; import { useCallback, useMemo, useState } from 'react'; -import { useQueryParam, NumberParam } from 'use-query-params'; +import { useQueryParam, NumberParam, StringParam } from 'use-query-params'; import { useTranslation } from 'react-i18next'; +import Button from '@mui/material/Button'; +import { Link } from 'react-router-dom'; +import Box from '@mui/material/Box'; import { requestManager } from '@/lib/requests/RequestManager.ts'; import { EmptyViewAbsoluteCentered } from '@/modules/core/components/feedback/EmptyViewAbsoluteCentered.tsx'; import { LoadingPlaceholder } from '@/modules/core/components/feedback/LoadingPlaceholder.tsx'; @@ -43,6 +46,7 @@ import { useMetadataServerSettings } from '@/modules/settings/services/ServerSet import { GET_LIBRARY_MANGA_COUNT } from '@/lib/graphql/queries/MangaQuery.ts'; import { useAppTitle } from '@/modules/navigation-bar/hooks/useAppTitle.ts'; import { useAppAction } from '@/modules/navigation-bar/hooks/useAppAction.ts'; +import { AppRoutes } from '@/modules/core/AppRoute.constants.ts'; const TitleWithSizeTag = styled('span')({ display: 'flex', @@ -84,6 +88,7 @@ export function Library() { const librarySize = librarySizeResponse.data?.mangas.totalCount ?? 0; const [tabSearchParam, setTabSearchParam] = useQueryParam('tab', NumberParam); + const [query] = useQueryParam('query', StringParam); const activeTab: (typeof tabs)[number] | undefined = tabs.find((tab) => tab.id === tabSearchParam) ?? tabs[0]; @@ -164,6 +169,22 @@ export function Library() { ); }, [isSelectModeActive, selectedMangas]); + const triggerGlobalSearchButton = useMemo( + () => ( + + + + ), + [query], + ); + useAppTitle( {t('library.title')} @@ -237,6 +258,7 @@ export function Library() { if (tabs.length === 1) { return ( <> + {triggerGlobalSearchButton} ))} + {triggerGlobalSearchButton} {tabs.map((tab) => ( {tab === activeTab && ( diff --git a/src/modules/source/screens/Sources.tsx b/src/modules/source/screens/Sources.tsx index ed911ddc..dd2123b1 100644 --- a/src/modules/source/screens/Sources.tsx +++ b/src/modules/source/screens/Sources.tsx @@ -72,7 +72,7 @@ export function Sources() { useAppAction( <> - navigate(AppRoutes.sources.childRoutes.searchAll.path)} color="inherit"> + navigate(AppRoutes.sources.childRoutes.searchAll.path())} color="inherit">