From 0cb47524cd7fa775ac8d5ce4faaba38e8cc5187d Mon Sep 17 00:00:00 2001 From: ozdentarikcan Date: Mon, 16 Dec 2024 13:42:58 +0300 Subject: [PATCH] Integrate with frontend --- frontend/src/components/SearchBar.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/src/components/SearchBar.tsx b/frontend/src/components/SearchBar.tsx index ac352793..2f8efd71 100644 --- a/frontend/src/components/SearchBar.tsx +++ b/frontend/src/components/SearchBar.tsx @@ -2,6 +2,7 @@ import { Hash, MessageSquare, Search } from "lucide-react"; import { useEffect, useId, useRef, useState } from "react"; import { useNavigate, useSearchParams } from "react-router-dom"; import { Button } from "./ui/button"; +import useAuthStore from "@/services/auth"; import { DropdownMenu, DropdownMenuContent, @@ -23,6 +24,7 @@ const searchTypes = [ { id: "questions", label: "Questions", icon: MessageSquare }, ] as const; + export const SearchBar = () => { const id = useId(); const [params] = useSearchParams(); @@ -35,6 +37,8 @@ export const SearchBar = () => { const inputRef = useRef(null); const navigate = useNavigate(); + const { selfProfile } = useAuthStore(); + // Get current search type info const currentSearchType = searchTypes.find((type) => type.id === searchType); const SearchTypeIcon = currentSearchType?.icon || Hash; @@ -97,6 +101,10 @@ export const SearchBar = () => { const params = new URLSearchParams(); params.append("type", searchType); params.append("q", search); + // Safely append currentUserId only if selfProfile is available + if (selfProfile?.id) { + params.append("currentUserId", selfProfile.id.toString()); + } navigate("/search?" + params.toString()); };