From 5b2f2869aeae50018a4a557221d5f8a2d44e3bb3 Mon Sep 17 00:00:00 2001 From: mukimovd <41473651-mukimovd@users.noreply.replit.com> Date: Thu, 1 May 2025 22:58:05 +0000 Subject: [PATCH] Provide a user-friendly page to find literary works and authors quickly Implements a new `/search` page with search bar and filters, using `react-query` to fetch and display results for works and authors. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cbacfb18-842a-4116-a907-18c0105ad8ec Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/39b5c689-6e8a-4d5a-9792-69cc81a56534/e42e7a4c-9018-4b11-b9fe-49652fbf9978.jpg --- client/src/App.tsx | 2 + client/src/components/common/SearchBar.tsx | 22 +- client/src/pages/Search.tsx | 510 +++++++++++++++++++++ 3 files changed, 523 insertions(+), 11 deletions(-) create mode 100644 client/src/pages/Search.tsx diff --git a/client/src/App.tsx b/client/src/App.tsx index 9fcfeaf..eb52246 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -6,6 +6,7 @@ import { TooltipProvider } from "@/components/ui/tooltip"; import NotFound from "@/pages/not-found"; import Home from "@/pages/Home"; import Explore from "@/pages/Explore"; +import Search from "@/pages/Search"; import AuthorProfile from "@/pages/authors/AuthorProfile"; import Authors from "@/pages/authors/Authors"; import WorkReading from "@/pages/works/WorkReading"; @@ -21,6 +22,7 @@ function Router() { + diff --git a/client/src/components/common/SearchBar.tsx b/client/src/components/common/SearchBar.tsx index 7e4e0b9..cd8d92d 100644 --- a/client/src/components/common/SearchBar.tsx +++ b/client/src/components/common/SearchBar.tsx @@ -81,12 +81,12 @@ export function SearchBar({ setQuery(e.target.value)} onFocus={() => setIsFocused(true)} /> - + {query && ( + )} + + + + + + {/* Tab Navigation */} +
+ + + All Results + Works + Authors + Advanced + + + +
+ +
+ View: + + +
+
+
+ +
+ {/* Show filter sidebar in Advanced tab */} + {(activeTab === 'advanced' || showFilters) && ( + + )} + + {/* Results area */} +
+ {/* Query info */} + {query && query.length >= 2 && ( +
+ {isLoading ? ( +

Searching for "{query}"...

+ ) : ( +

+ Showing results for "{query}" + {activeTab !== 'advanced' && searchResults && ( + - {searchResults.works.length} works, {searchResults.authors.length} authors found + )} + {activeTab === 'advanced' && filteredWorks && ( + - {filteredWorks.length} works match your filters + )} +

+ )} +
+ )} + + {/* Authors section in all or authors tab */} + {(activeTab === 'all' || activeTab === 'authors') && query.length >= 2 && ( + <> + {activeTab === 'all' && searchResults?.authors && searchResults.authors.length > 0 && ( +

Authors

+ )} + + {isLoading ? ( +
+ {Array.from({ length: 3 }).map((_, i) => ( + + +
+
+
+
+
+
+
+
+
+
+ ))} +
+ ) : ( + <> + {searchResults?.authors && searchResults.authors.length > 0 && ( +
+ {searchResults.authors.map((author) => ( + + + +

+ {author.biography?.slice(0, 120)}... +

+ +
+
+ ))} +
+ )} + + {hasNoAuthors && activeTab === 'authors' && ( +
+

No authors found matching "{query}"

+

Try a different search term or check your spelling

+
+ )} + + )} + + )} + + {/* Works section */} + {(activeTab === 'all' || activeTab === 'works' || activeTab === 'advanced') && ( + <> + {activeTab === 'all' && searchResults?.works && searchResults.works.length > 0 && ( +

Works

+ )} + + {isLoading ? ( + viewMode === 'list' ? ( +
+ {Array.from({ length: 5 }).map((_, i) => ( +
+ ))} +
+ ) : ( +
+ {Array.from({ length: 6 }).map((_, i) => ( +
+ ))} +
+ ) + ) : ( + <> + {displayWorks.length > 0 ? ( + viewMode === 'list' ? ( +
+ {displayWorks.map((work) => ( + + ))} +
+ ) : ( +
+ {displayWorks.map((work) => ( + + ))} +
+ ) + ) : hasNoResults && ( +
+

No works found matching "{query}"

+

+ {activeTab === 'advanced' + ? 'Try adjusting your filters or using different search terms' + : 'Try a different search term or check your spelling'} +

+
+ )} + + )} + + )} + + {/* Entry prompt when search is empty */} + {query.length < 2 && ( +
+ +

Start Your Literary Journey

+

+ Enter a search term above to discover works by title, author, or keyword +

+
+ {['Poetry', 'Novel', 'Tolstoy', 'Shakespeare', 'Modernism', 'Love'].map((term) => ( + + ))} +
+
+ )} + + {/* Pagination */} + {totalPages > 1 && !isLoading && ( +
+ +
+ )} +
+
+ + + ); +} \ No newline at end of file