Skip to content

refactor(searchApi): simplify title search logic and remove unused types#222

Merged
tenkus47 merged 1 commit into
devfrom
text-v1
Jun 8, 2026
Merged

refactor(searchApi): simplify title search logic and remove unused types#222
tenkus47 merged 1 commit into
devfrom
text-v1

Conversation

@tenkus47

@tenkus47 tenkus47 commented Jun 8, 2026

Copy link
Copy Markdown
Member
  • Removed the TextSearchItem and TitleSearchResponse types as they were no longer needed.
  • Updated the searchTitles function to directly fetch data without checking for minimum title length.
  • Adjusted the SourceSelectorSheet component to remove dependency on MIN_TITLE_SEARCH_LENGTH and simplified source selection logic.

- Removed the TextSearchItem and TitleSearchResponse types as they were no longer needed.
- Updated the searchTitles function to directly fetch data without checking for minimum title length.
- Adjusted the SourceSelectorSheet component to remove dependency on MIN_TITLE_SEARCH_LENGTH and simplified source selection logic.
@tenkus47 tenkus47 requested review from Tech-lo and removed request for Tech-lo June 8, 2026 12:23
@tenkus47 tenkus47 merged commit 4ff604d into dev Jun 8, 2026
2 of 3 checks passed
@tenkus47 tenkus47 deleted the text-v1 branch June 8, 2026 12:24
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown

Confidence Score: 3/5

Two independent behavioral regressions — a likely runtime crash when rendering title search results and an unexplained HTTP method change in fetchTextDetails — should be resolved before merging.

The direct use of titleData as an array breaks sources.map() if the API still returns a response envelope, causing an immediate crash on the title-search path. Separately, silently flipping fetchTextDetails from GET to POST will return 405 errors if the server route only handles GET. Both regressions sit on active user-facing flows.

src/components/api/searchApi.ts (GET→POST change and missing return type) and src/components/ui/molecules/webuddhist-source/SourceSelectorSheet.tsx (unsafe titleData || [] array assumption) both need a second look.

Reviews (1): Last reviewed commit: "refactor(searchApi): simplify title sear..." | Re-trigger Greptile

Comment on lines +130 to +132
const sources = searchOnlyTitles
? titleData || []
: multilingualData?.sources || [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The titleData variable holds whatever the API returns — previously it was a TitleSearchResponse wrapper with a .texts array, accessed via titleData?.texts. Now titleData is used directly as if it is an array, but if the /api/v1/texts/title-search endpoint still returns a paginated envelope (e.g. { texts: [...], has_more: ... }), sources will be a plain object. Calling sources.map(...) (line 177) and sources.length === 0 (line 158) will then throw TypeError: sources.map is not a function at runtime. Even if the endpoint now returns a flat array, the function's implicit any return type provides no compile-time guard against future shape regressions.

Suggested change
const sources = searchOnlyTitles
? titleData || []
: multilingualData?.sources || [];
const sources = searchOnlyTitles
? (Array.isArray(titleData) ? titleData : titleData?.texts ?? [])
: multilingualData?.sources || [];

Comment on lines +60 to 65
const { data } = await axiosInstance.post(`/api/v1/texts/${textId}/details`, {
...(contentId && { content_id: contentId }),
...(segmentId && { segment_id: segmentId }),
direction,
size,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 fetchTextDetails was silently changed from a GET to a POST. A GET → POST switch is a breaking change if the server-side route only handles GET for this endpoint. This will silently fail with a 405 or wrong-method error. The PR description does not mention this change, which makes it easy to miss during review.

Suggested change
const { data } = await axiosInstance.post(`/api/v1/texts/${textId}/details`, {
...(contentId && { content_id: contentId }),
...(segmentId && { segment_id: segmentId }),
direction,
size,
});
const { data } = await axiosInstance.get(`/api/v1/texts/${textId}/details`, {
params: {
...(contentId && { content_id: contentId }),
...(segmentId && { segment_id: segmentId }),
direction,
size,
},
});

};

export type { SearchCommon };
export type { SearchCommon }; No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Four files in this PR are missing a trailing newline. This will produce noisy diffs in future git operations and typically triggers linter/editor warnings. The same issue appears in SourceDetail.tsx, SourceSelectorSheet.tsx, and sourceItem.tsx.

Suggested change
export type { SearchCommon };
export type { SearchCommon };

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant