Improve search functionality and navigation on the blog
Update search endpoint to use Bunny API's search parameter for efficiency, refactor client-side search query handling to use window.location.search for better query parameter retrieval, and update header navigation to use window.location.href for consistent routing. Also, update gallery image URLs in gallery-data.json. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: bdfa6652-3a31-4f32-a642-d62bd1746159 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/517dfa7b-26ac-463d-a6e1-a58c6df97188/jdAEdU5 Replit-Helium-Checkpoint-Created: true
This commit is contained in:
parent
ff34633ea6
commit
a7493e4279
@ -29,10 +29,11 @@ export default function Header() {
|
||||
const handleSearch = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (searchQuery.trim().length >= 2) {
|
||||
navigate(`/search?q=${encodeURIComponent(searchQuery.trim())}`);
|
||||
const url = `/search?q=${encodeURIComponent(searchQuery.trim())}`;
|
||||
setSearchOpen(false);
|
||||
setSearchQuery("");
|
||||
setMobileOpen(false);
|
||||
window.location.href = url;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -26,18 +26,18 @@ interface SearchResult {
|
||||
}
|
||||
|
||||
export default function SearchPage() {
|
||||
const [location] = useLocation();
|
||||
const params = new URLSearchParams(location.split("?")[1] || "");
|
||||
const initialQuery = params.get("q") || "";
|
||||
const qs = typeof window !== "undefined" ? window.location.search : "";
|
||||
const initialQuery = new URLSearchParams(qs).get("q") || "";
|
||||
const [query, setQuery] = useState(initialQuery);
|
||||
const [searchTerm, setSearchTerm] = useState(initialQuery);
|
||||
|
||||
useEffect(() => {
|
||||
const p = new URLSearchParams(location.split("?")[1] || "");
|
||||
const q = p.get("q") || "";
|
||||
setQuery(q);
|
||||
setSearchTerm(q);
|
||||
}, [location]);
|
||||
const q = new URLSearchParams(window.location.search).get("q") || "";
|
||||
if (q && q !== searchTerm) {
|
||||
setQuery(q);
|
||||
setSearchTerm(q);
|
||||
}
|
||||
}, [qs]);
|
||||
|
||||
const { data, isLoading } = useQuery<SearchResult>({
|
||||
queryKey: ["/api/search", searchTerm],
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user