From e993ac3b59c1ad5f275ad6538bcfb01eb6b79aed Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sat, 16 Sep 2023 18:47:53 -0400 Subject: [PATCH] Search filters (#145) --- CHANGELOG.md | 1 + .../components/ChannelView/ChannelView.xml | 2 +- .../SearchFilters/SearchFilters.bs | 273 ++++++++++++++++++ .../SearchFilters/SearchFilters.xml | 124 ++++++++ .../Screens/SearchScreen/SearchScreen.bs | 68 ++++- .../Screens/SearchScreen/SearchScreen.xml | 13 + .../src/images/icons/filters-black.png | Bin 0 -> 316 bytes .../src/images/icons/filters-white.png | Bin 0 -> 321 bytes .../src/images/vector/icons/filters-black.svg | 3 + .../src/images/vector/icons/filters-white.svg | 3 + .../src/images/vector/icons/home.svg | 0 .../src/images/vector/icons/info.svg | 0 .../src/images/vector/icons/phone.svg | 0 .../src/images/vector/icons/search.svg | 0 .../src/images/vector/icons/settings.svg | 0 tools/generate-images.js | 2 +- 16 files changed, 485 insertions(+), 4 deletions(-) create mode 100644 playlet-lib/src/components/Screens/SearchScreen/SearchFilters/SearchFilters.bs create mode 100644 playlet-lib/src/components/Screens/SearchScreen/SearchFilters/SearchFilters.xml create mode 100644 playlet-lib/src/images/icons/filters-black.png create mode 100644 playlet-lib/src/images/icons/filters-white.png create mode 100644 playlet-lib/src/images/vector/icons/filters-black.svg create mode 100644 playlet-lib/src/images/vector/icons/filters-white.svg rename {playlet-app => playlet-lib}/src/images/vector/icons/home.svg (100%) rename {playlet-app => playlet-lib}/src/images/vector/icons/info.svg (100%) rename {playlet-app => playlet-lib}/src/images/vector/icons/phone.svg (100%) rename {playlet-app => playlet-lib}/src/images/vector/icons/search.svg (100%) rename {playlet-app => playlet-lib}/src/images/vector/icons/settings.svg (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f81592a2..f1eaeb3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - A field to indicate when a playlist was last updated - Voice search in search page - Basic support for channels (open channel, see latest videos) +- Search filters (Upload date, type, duration, features, and sort by) ### Changed diff --git a/playlet-lib/src/components/ChannelView/ChannelView.xml b/playlet-lib/src/components/ChannelView/ChannelView.xml index 02f293df..b7863562 100644 --- a/playlet-lib/src/components/ChannelView/ChannelView.xml +++ b/playlet-lib/src/components/ChannelView/ChannelView.xml @@ -21,7 +21,7 @@ width="104" height="104" uri="pkg:/images/circle-mask-500.png"> - + = 0) + end for + control.checkedState = checkedState +end function + +function OnFocusChange() as void + if not m.top.focus + return + end if + + NodeSetFocus(m.controls.date, true) +end function + +function OnListChecked(event as object) + control = event.getRoSGNode() + filterKey = control.filterKey + + state = m.searchScreen.filters + if IsString(state[filterKey]) + SetFilterString(control) + else if IsArray(state[filterKey]) + SetFilterArray(control) + end if +end function + +function SetFilterString(control as object) as void + content = control.content + selectedNode = content.getChild(control.checkedItem) + value = selectedNode.value + + filterKey = control.filterKey + state = m.searchScreen.filters + state[filterKey] = value + m.searchScreen.filters = state +end function + +function SetFilterArray(control as object) as void + content = control.content + checkedState = control.checkedState + + values = [] + for i = 0 to checkedState.count() - 1 + if checkedState[i] + node = content.getChild(i) + values.push(node.value) + end if + end for + + filterKey = control.filterKey + state = m.searchScreen.filters + state[filterKey] = values + m.searchScreen.filters = state +end function + +function OnkeyEvent(key as string, press as boolean) as boolean + navigation = NavigationKeyHandler(key, press) + if navigation.handled + m.currentNavigtionNode = navigation.node + return true + end if + + if key = "options" and press + ' A pass-through to the app controller, so it can toggle picture-in-picture + return false + end if + + if key = "back" and press + Close() + return true + end if + + return true +end function + +function Close() + m.appController@.PopScreen(invalid) +end function diff --git a/playlet-lib/src/components/Screens/SearchScreen/SearchFilters/SearchFilters.xml b/playlet-lib/src/components/Screens/SearchScreen/SearchFilters/SearchFilters.xml new file mode 100644 index 00000000..06540cc9 --- /dev/null +++ b/playlet-lib/src/components/Screens/SearchScreen/SearchFilters/SearchFilters.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs index 894ff7f8..df5dfb66 100644 --- a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs +++ b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs @@ -14,10 +14,21 @@ function Init() m.scrollAnimation = m.top.FindNode("scrollAnimation") m.scrollAnimationInterpolator = m.top.FindNode("scrollAnimationInterpolator") m.suggestions = m.top.FindNode("suggestions") + m.filtersButton = m.top.FindNode("filtersButton") textEditBox = m.keyboard.textEditBox textEditBox.voiceEntryType = "generic" textEditBox.voiceEnabled = true + + m.top.filters = { + date: "", + type: "", + duration: "", + features: [], + sort_by: "" + } + + m.top.ObserveField("filters", FuncName(OnFiltersChange)) end function function OnNodeReady() @@ -27,6 +38,8 @@ function OnNodeReady() m.keyboard.ObserveField("text", FuncName(OnTextChange)) m.suggestions.ObserveField("buttonFocused", FuncName(OnSearchButtonFocused)) m.suggestions.ObserveField("buttonSelected", FuncName(OnSearchButtonSelected)) + m.filtersButton.ObserveField("buttonSelected", FuncName(OnFiltersButtonSelected)) + m.top.ObserveField("visible", FuncName(OnVisibilityChange)) m.rowlist.ObserveFieldScoped("onError", FuncName(OnSearchError)) @@ -34,12 +47,17 @@ function OnNodeReady() ScrollUp() end function) SetNavigation(m.suggestions, "right", m.keyboard) + SetNavigation(m.filtersButton, "right", m.keyboard) SetNavigation(m.keyboard, "left", m.suggestions) SetNavigation(m.suggestions, "left", m.navBar) + SetNavigation(m.filtersButton, "left", m.navBar) SetNavigation(m.keyboard, "left", m.navBar) SetNavigation(m.rowList, "left", m.navBar, function() ScrollUp() end function) + SetNavigation(m.filtersButton, "down", m.suggestions) + SetNavigation(m.filtersButton, "down", m.keyboard) + SetNavigation(invalid, "down", m.rowList, function() ScrollDown() end function) @@ -47,6 +65,8 @@ function OnNodeReady() ScrollUp() end function) + SetNavigation(m.suggestions, "up", m.filtersButton) + m.currentNavigtionNode = m.suggestions ' Trigger suggestions OnTextChange() @@ -123,6 +143,13 @@ function OnSearchSuggestionsTaskResults(output as object) as void m.suggestions.focusable = m.suggestions.buttons.Count() > 0 end function +function OnFiltersButtonSelected() + searchFilters = CreateObject("roSGNode", "SearchFilters") + m.appController@.PushScreen(searchFilters) + searchFilters.searchScreen = m.top + searchFilters@.BindNode(invalid) +end function + function OnSearchButtonSelected() selected = m.suggestions.buttonSelected text = m.suggestions.buttons[selected] @@ -149,19 +176,56 @@ function OnSearchButtonFocused() as void m.keyboard.text = text end function +function OnFiltersChange() + filterCount = 0 + filters = m.top.filters + for each filter in filters + value = filters[filter] + if IsString(value) and value.len() > 0 + filterCount++ + else if IsArray(value) and value.Count() > 0 + filterCount += value.Count() + end if + end for + if filterCount > 0 + m.filtersButton.text = `Filters (${filterCount})` + else + m.filtersButton.text = "Filters" + end if +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() - m.rowList.contentData = [{ + requestData = { title: `Search - ${text}`, apiType: "Invidious", endpoint: "search", queryParams: { q: text } - }] + } + + filters = m.top.filters + for each filter in filters + value = filters[filter] + if IsString(value) and value.len() > 0 + requestData.queryParams[filter] = value + else if IsArray(value) and value.Count() > 0 + ' TODO:P1 this is http client implementation details leaking + ' We need a declarative way to set array types + requestData.queryParams[filter] = { + value: value, + __arrayType: HttpClient.QueryParamArrayType.CommaSeparated + } + end if + end for + + m.rowList.contentData = [requestData] end function function OnSearchContentReady() as void diff --git a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.xml b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.xml index c625e2cb..29b7dc56 100644 --- a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.xml +++ b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.xml @@ -4,9 +4,22 @@ + + + + nexWNt1qrz|Ks|dN1UNK#{#2#SGt92&LZ0&vVRKOAP;vvu{MNT$4Nc zwP6;6oMWp`V{WVGeO9Fpas_En%S8YjN|;m~+)JE1m#A1p=qaf1MLNs$U;J0Dy3t)(HKOkSLe-6!z3-{M|evvkVmNAE?2bN;Et1$jlDk$Bqu&i_9L zPiLuvyT}5*1=IF56v!$R8E*EJWm@qdf3wwT{Y(2++aR-x!{?l@3;9t PA2E2k`njxgN@xNAu-1T| literal 0 HcmV?d00001 diff --git a/playlet-lib/src/images/vector/icons/filters-black.svg b/playlet-lib/src/images/vector/icons/filters-black.svg new file mode 100644 index 00000000..18eda655 --- /dev/null +++ b/playlet-lib/src/images/vector/icons/filters-black.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/playlet-lib/src/images/vector/icons/filters-white.svg b/playlet-lib/src/images/vector/icons/filters-white.svg new file mode 100644 index 00000000..a81e0702 --- /dev/null +++ b/playlet-lib/src/images/vector/icons/filters-white.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/playlet-app/src/images/vector/icons/home.svg b/playlet-lib/src/images/vector/icons/home.svg similarity index 100% rename from playlet-app/src/images/vector/icons/home.svg rename to playlet-lib/src/images/vector/icons/home.svg diff --git a/playlet-app/src/images/vector/icons/info.svg b/playlet-lib/src/images/vector/icons/info.svg similarity index 100% rename from playlet-app/src/images/vector/icons/info.svg rename to playlet-lib/src/images/vector/icons/info.svg diff --git a/playlet-app/src/images/vector/icons/phone.svg b/playlet-lib/src/images/vector/icons/phone.svg similarity index 100% rename from playlet-app/src/images/vector/icons/phone.svg rename to playlet-lib/src/images/vector/icons/phone.svg diff --git a/playlet-app/src/images/vector/icons/search.svg b/playlet-lib/src/images/vector/icons/search.svg similarity index 100% rename from playlet-app/src/images/vector/icons/search.svg rename to playlet-lib/src/images/vector/icons/search.svg diff --git a/playlet-app/src/images/vector/icons/settings.svg b/playlet-lib/src/images/vector/icons/settings.svg similarity index 100% rename from playlet-app/src/images/vector/icons/settings.svg rename to playlet-lib/src/images/vector/icons/settings.svg diff --git a/tools/generate-images.js b/tools/generate-images.js index c4142f56..f465542f 100644 --- a/tools/generate-images.js +++ b/tools/generate-images.js @@ -48,7 +48,7 @@ const logoOutput = { }, }; -const iconsInput = './playlet-app/src/images/vector/icons'; +const iconsInput = './playlet-lib/src/images/vector/icons'; const iconsOutput = './playlet-lib/src/images/icons'; (async () => {