-
-
Notifications
You must be signed in to change notification settings - Fork 98
Issue 478 add agency search page #485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Issue 478 add agency search page #485
Conversation
14d219e to
eba6116
Compare
eba6116 to
c7e4f5f
Compare
| import { useSearchParams } from "next/navigation" | ||
| import { SearchResponse, AgencyResponse } from "@/utils/api" | ||
| import { useSearch } from "@/providers/SearchProvider" | ||
| import { useEffect } from "react" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add this to line 3 to consolidate imports?
| useEffect(() => { | ||
| const performAgencySearch = async () => { | ||
| if (tab !== 3 || !currentQuery) return | ||
|
|
||
| setAgencyLoading(true) | ||
| try { | ||
| const response = await searchAgencies({ name: currentQuery }) | ||
| setAgencyResults(response.results || []) | ||
| setAgencyTotal(response.total || 0) | ||
| } catch (error) { | ||
| console.error('Agency search failed:', error) | ||
| setAgencyResults([]) | ||
| setAgencyTotal(0) | ||
| } finally { | ||
| setAgencyLoading(false) | ||
| } | ||
| } | ||
| performAgencySearch() | ||
| }, [currentQuery, tab, searchAgencies]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I'm going to be adding a unit search on the same page, I'm wondering if this is the best place to have all the logic.
Could you move performAgencySearch outside the useEffect and then do the tab check?
useEffect(() => {
if (tab === 3) performAgencySearch();
if (tab === other_tabs) performOtherTabSearch(); // so we can list all the functions clearly
}, [currentQuery, tab]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also would probably be good to have a debounce for currentQuery changes so we aren't calling search for every keystroke.
| <CustomTabPanel value={tab} index={3}> | ||
| {agencyLoading ? ( | ||
| <Typography>Searching agencies...</Typography> | ||
| ) : ( | ||
| <> | ||
| <Typography sx={{ marginBottom: "1rem", fontWeight: "bold" }}> | ||
| {agencyTotal} agency results | ||
| </Typography> | ||
| {agencyResults.map((result) => ( | ||
| <CardHeader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to my other comment:
I'm wondering if we can move this into another component that can be customized according to what's being searched. That way we don't have all these hardcoded (by agency, but unit, etc) CustomTabPanels.
I don't know if you want to do this or I can make that change when I start my Unit Search task.
Add more debug logs to observe results data structure Add Agency tab with basic result filtering - Filter existing search results by content_type === 'Agency' - Does not handle officer-to-agency searches yet Add agencies API integration Implement Agency tab with a dedicated agencies API endpoint - Add /agencies endpoint to apiRoutes - Add searchAgencies function to SearchProvider - Update Agency tab to call agencies API when selected - Encountered CORS error Fix Agency search results - Fixed agency endpoint - Return proper agency information - Adjust Agency info card rendering in search results Add useEffect for reactive agency search state and remove debug logs
- Better scalability for future tab functions - Also consolidated React imports
c7e4f5f to
adcd2f5
Compare
Implements agency tab functionality with dedicated '/agencies/' API endpoint.