Skip to content

Commit

Permalink
Fix empty search results bug
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Feb 28, 2024
1 parent aebdc57 commit 8e03ca0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- When a video error dialog shows, a timer with 10 seconds starts to play the next video

### Fixed

- A bug where the loading screen does not disappear if search results are empty.

## [0.20.2] - 2024-02-26

### Added
Expand Down
12 changes: 9 additions & 3 deletions playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "pkg:/components/Dialog/DialogUtils.bs"
import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
import "pkg:/source/AsyncTask/AsyncTask.bs"
Expand Down Expand Up @@ -203,8 +204,6 @@ end function

function Search(text as string)
m.rowlist.UnobserveFieldScoped("someContentReady")
' TODO:P1 someContentReady only fires if there are search results.
' The case where search results are empty is not handled.
m.rowlist.ObserveFieldScoped("someContentReady", FuncName(OnSearchContentReady))
ShowLoadingScreen()

Expand Down Expand Up @@ -238,10 +237,16 @@ function Search(text as string)
end function

function OnSearchContentReady() as void
m.rowlist.UnobserveFieldScoped("someContentReady")

if not m.rowlist.someContentReady
DialogUtils.ShowDialog("We didn't find any results for your search. Please try again with a different query or different filters.", "No results found")
m.rowlist.feeds = invalid
m.rowlist.focusable = false
HideLoadingScreen()
return
end if
m.rowlist.UnobserveFieldScoped("someContentReady")

m.rowlist.focusable = true
m.currentNavigtionNode = m.rowList
NodeSetFocus(m.rowlist, true)
Expand All @@ -253,6 +258,7 @@ function OnSearchContentReady() as void
end function

function OnSearchError()
' Note: we don't display an error dialog, VideoRowListRowContentTask will do that.
m.rowlist.feeds = invalid
m.rowlist.focusable = false
HideLoadingScreen()
Expand Down
1 change: 0 additions & 1 deletion playlet-lib/src/components/VideoFeed/VideoRowList.bs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ end function

function InitContent() as void
CancelCurrentTasks()
m.top.someContentReady = false

if m.top.feeds = invalid
m.top.content = invalid
Expand Down
8 changes: 7 additions & 1 deletion playlet-lib/src/components/VideoFeed/VideoRowList.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
<field id="bookmarks" type="node" bind="/Bookmarks" />
<field id="screen" type="node" />
<field id="feeds" type="array" onChange="OnFeedsChange" />
<field id="someContentReady" type="bool" />
<!--
someContentReady is a field specifically for the search screen.
It is set to true when there are some search results
and set to false when there are no search results.
It a signal to make sure to hide the loading indicator.
-->
<field id="someContentReady" type="bool" alwaysNotify="true" />
<field id="onError" type="string" alwaysNotify="true" />
<function name="OpenPlaylist" />
<function name="OpenChannel" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function VideoRowListRowContentTask(input as object) as object

totalfetchedItems = 0

someContentReadySet = false

while true
if m.top.cancel
feedContentNode.loadState = FeedLoadState.None
Expand All @@ -25,6 +27,10 @@ function VideoRowListRowContentTask(input as object) as object

if feedSourcesIndex >= feedSources.Count()
feedContentNode.loadState = FeedLoadState.Loaded

if not someContentReadySet
rowList.someContentReady = false
end if
return {
success: true
}
Expand All @@ -36,6 +42,9 @@ function VideoRowListRowContentTask(input as object) as object
feedSourcesIndex += 1
if feedSourcesIndex >= feedSources.Count()
feedContentNode.loadState = FeedLoadState.Loaded
if not someContentReadySet
rowList.someContentReady = false
end if
return {
success: true
}
Expand Down Expand Up @@ -130,7 +139,8 @@ function VideoRowListRowContentTask(input as object) as object
feedContentNode.loadState = FeedLoadState.LoadedPage
end if

if itemNodes.Count() > 0
if itemNodes.Count() > 0 and not someContentReadySet
someContentReadySet = true
rowList.someContentReady = true
end if

Expand Down

0 comments on commit 8e03ca0

Please sign in to comment.