Skip to content

Commit

Permalink
🐛 Fixed searchbar crash
Browse files Browse the repository at this point in the history
Still the searching not working very well...
  • Loading branch information
Mario-SO committed Aug 2, 2024
1 parent 8baee69 commit bff9156
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions packages/app/components/misc/SearchBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,33 @@ export default function SearchBar({
useEffect(() => {
if (debouncedSearchQuery) {
setIsLoading(true)
fetch(
`${apiUrl()}/sessions/${organizationSlug}/search?search=${debouncedSearchQuery}&onlyVideos=true`
)
.then((res) => res.json())
.then((data) => {
const items = data.data
.map((obj: any) => obj.item)
.slice(0, 10)
if (organizationSlug) {
fetch(
`${apiUrl()}/sessions/${organizationSlug}/search?search=${debouncedSearchQuery}&onlyVideos=true`
)
.then((res) => res.json())
.then((data) => {
const items = data.data
.map((obj: any) => obj.item)
.slice(0, 10)

setSearchResults(items)
setIsLoading(false)
})
setSearchResults(items)
setIsLoading(false)
})
} else {
fetch(
`${apiUrl()}/sessions/search?search=${debouncedSearchQuery}&onlyVideos=true`
)
.then((res) => res.json())
.then((data) => {
const items = data.data
.map((obj: any) => obj.item)
.slice(0, 10)

setSearchResults(items)
setIsLoading(false)
})
}
}
}, [debouncedSearchQuery])

Expand All @@ -81,7 +96,7 @@ export default function SearchBar({
router.push(
isStudio
? `/studio/${organizationSlug}/library/${session._id.toString()}`
: `/${organizationSlug}/watch?session=${session._id.toString()}`
: `/${organizationSlug || session.organizationId}/watch?session=${session._id.toString()}`
)
return
}
Expand Down

0 comments on commit bff9156

Please sign in to comment.