Create Component Library (#43)

* Move src under playlet-lib

* Update configuration

* Update script

* Update script

* Working version

* Vs code config WIP

* Package lock sync

* Lint fix

* Fix images

* Reuse config files

* Kind of a working setup

* Lock node version

* Rename scripts to tools

* Fix build scripts, lib url system

* Lint fix

* rale

* Fix args and web server

* Load fallbacks and build script cleanups

* Remove unused method

* no message

* no message

* Remove generic message field

* Lint fix

* no message

* Use loading indicator on main app

* Add playlet lib version to settings

---------

Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
Brahim Hadricheandgithub-action linter authored and GitHub committed 2023-01-29 16:50:28 -05:00
1 parent 90df81df4b
commit 9d8a3d1cea
156 files changed
+3341 -213

No files matched your search

@@ -0,0 +1,231 @@
import "pkg:/source/asyncTask/asyncTask.bs"
import "pkg:/components/VideoPlayer/Video.bs"
import "pkg:/components/SearchScreen/SearchHistory.bs"
import "pkg:/components/SearchScreen/SearchSuggestionsTask.bs"
import "pkg:/components/SearchScreen/SearchTask.bs"
function Init()
m.container = m.top.FindNode("container")
m.scrollAnimation = m.top.FindNode("scrollAnimation")
m.scrollAnimationInterpolator = m.top.FindNode("scrollAnimationInterpolator")
m.keyboard = m.top.FindNode("keyboard")
m.suggestions = m.top.FindNode("suggestions")
m.rowList = m.top.FindNode("rowList")
m.keyboard.ObserveField("text", "OnTextChange")
m.suggestions.ObserveField("buttonSelected", "OnSearchButtonSelected")
m.suggestions.ObserveField("buttonFocused", "OnSearchButtonFocused")
m.rowList.ObserveField("rowItemSelected", "OnSearchVideoSelected")
m.top.ObserveField("focus", "OnFocusChange")
m.top.ObserveField("visible", "OnVisibilityChange")
' Trigger suggestions
OnTextChange()
end function
function OnFocusChange() as void
if m.top.focus <> true
return
end if
if m.rowlist.content <> invalid
m.rowlist.SetFocus(true)
ScrollDown()
return
end if
if m.suggestions.buttons.Count() > 0
if m.suggestions.buttonFocused >= m.suggestions.buttons.Count()
m.suggestions.focusButton = 0
end if
m.suggestions.SetFocus(true)
return
end if
m.keyboard.SetFocus(true)
end function
function OnTextChange() as void
if IsNodeFocused("suggestions")
return
end if
if m.searchSuggestionsTask <> invalid
m.searchSuggestionsTask.control = "stop"
end if
m.searchSuggestionsTask = StartAsyncTask(SearchSuggestionsTask, {
q: m.keyboard.text
}, OnSearchSuggestionsTaskResults)
end function
function OnSearchSuggestionsTaskResults(output as object) as void
' In case this is an old request, discard suggestions
q = output.result.q
if q <> m.keyboard.text
return
end if
suggestions = output.result.response
if suggestions = invalid
return
end if
if q.len() > 0 and ArrayIndexOf(suggestions, q) = -1
suggestions.Unshift(q)
end if
' Capture current focused button and restore it after resetting the buttons
buttonFocused = -1
if IsNodeFocused("suggestions")
buttonFocused = m.suggestions.buttonFocused
end if
if buttonFocused >= m.suggestions.buttons.Count()
buttonFocused = m.suggestions.buttons.Count() - 1
end if
m.suggestions.buttons = suggestions
if buttonFocused <> -1
m.suggestions.focusButton = buttonFocused
end if
end function
function OnSearchButtonSelected()
selected = m.suggestions.buttonSelected
text = m.suggestions.buttons[selected]
SaveSearchHistory(text)
Search(text)
end function
function OnSearchButtonFocused() as void
if not IsNodeFocused("suggestions")
return
end if
selected = m.suggestions.buttonFocused
text = m.suggestions.buttons[selected]
m.keyboard.text = text
end function
function Search(text as string)
if m.searchTask <> invalid
m.searchTask.control = "stop"
end if
m.global.loadingIndicator.visible = true
m.searchTask = StartAsyncTask(SearchTask, {
q: text
}, OnSearchTaskResults)
end function
function OnSearchTaskResults(output as object)
rootChildren = output.result.rootChildren
contentNode = CreateObject("roSGNode", "ContentNode")
contentNode.Update({
children: rootChildren
}, true)
m.rowList.content = contentNode
m.rowList.SetFocus(true)
m.rowList.jumpToRowItem = [0, 0]
ScrollDown()
m.global.loadingIndicator.visible = false
end function
function OnVisibilityChange()
if m.top.visible = false
ClearSearch()
end if
end function
function ClearSearch()
m.keyboard.text = ""
m.rowlist.content = invalid
ScrollUp()
end function
function IsNodeFocused(id as string) as boolean
return m.top.focusedChild?.id = id or m.container.focusedChild?.id = id
end function
function ScrollUp() as void
destination = m.scrollAnimationInterpolator.keyValue[0][1]
current = m.container.translation[1]
if current = destination
return
end if
m.scrollAnimationInterpolator.reverse = true
m.scrollAnimation.control = "start"
end function
function ScrollDown() as void
destination = m.scrollAnimationInterpolator.keyValue[2][1]
current = m.container.translation[1]
if current = destination
return
end if
m.scrollAnimationInterpolator.reverse = false
m.scrollAnimation.control = "start"
end function
function OnSearchVideoSelected(event as object)
grid = event.GetRoSGNode()
selectedPair = event.GetData()
selectedRow = selectedPair[0]
selectedRowItem = selectedPair[1]
rowContent = grid.content.GetChild(selectedRow)
itemContent = rowContent.GetChild(selectedRowItem)
videoId = itemContent.videoId
PlayVideo(videoId, {
metadata: itemContent,
sender: m.top
})
end function
function OnkeyEvent(key as string, press as boolean) as boolean
if press = false
return false
end if
if key = "options"
if ToggleVideoPictureInPicture(m.top)
return true
end if
end if
if key = "back"
ScrollUp()
m.top.escape = key
return true
end if
if key = "left"
if IsNodeFocused("keyboard") and m.suggestions.buttons.Count() > 0
m.suggestions.SetFocus(true)
return true
end if
ScrollUp()
m.top.escape = key
return true
end if
if key = "right"
if IsNodeFocused("suggestions")
m.keyboard.SetFocus(true)
return true
end if
return false
end if
if key = "down"
if m.rowlist.content <> invalid
ScrollDown()
m.rowlist.SetFocus(true)
return true
end if
return false
end if
if key = "up"
if IsNodeFocused("rowList")
ScrollUp()
m.suggestions.SetFocus(true)
return true
end if
return false
end if
return false
end function