Skip to content

Commit

Permalink
Integrate with frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
ozdentarikcan committed Dec 16, 2024
1 parent 9ee8728 commit 0cb4752
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions frontend/src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,6 +24,7 @@ const searchTypes = [
{ id: "questions", label: "Questions", icon: MessageSquare },
] as const;


export const SearchBar = () => {
const id = useId();
const [params] = useSearchParams();
Expand All @@ -35,6 +37,8 @@ export const SearchBar = () => {
const inputRef = useRef<HTMLInputElement>(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;
Expand Down Expand Up @@ -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());
};

Expand Down

0 comments on commit 0cb4752

Please sign in to comment.