mirror of
https://github.com/Apologieze/Benri.git
synced 2026-01-18 17:17:21 +01:00
Working searchbar + new menu
This commit is contained in:
@@ -78,7 +78,7 @@ func GetData(radio *widget.RadioGroup, username string, delete func()) {
|
||||
func FindList(categoryName string) *[]verniy.MediaList {
|
||||
if UserData == nil {
|
||||
log.Error("No data found")
|
||||
return nil
|
||||
return &[]verniy.MediaList{}
|
||||
}
|
||||
categoryIndex, exists := categoriesToInt[categoryName]
|
||||
if !exists {
|
||||
@@ -88,6 +88,30 @@ func FindList(categoryName string) *[]verniy.MediaList {
|
||||
return &UserData[categoryIndex].Entries
|
||||
}
|
||||
|
||||
func FindListWithQuery(categoryName string, query string) *[]verniy.MediaList {
|
||||
fullList := FindList(categoryName)
|
||||
if fullList == nil {
|
||||
return &[]verniy.MediaList{}
|
||||
}
|
||||
if len(*fullList) == 0 {
|
||||
return &[]verniy.MediaList{}
|
||||
}
|
||||
tempMediaList := make([]verniy.MediaList, 0, 25)
|
||||
for _, anime := range *fullList {
|
||||
englishName := AnimeToName(anime.Media)
|
||||
if englishName == nil {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(strings.ToLower(*englishName), strings.ToLower(query)) {
|
||||
tempMediaList = append(tempMediaList, anime)
|
||||
} else if strings.Contains(strings.ToLower(AnimeToRomaji(anime.Media)), strings.ToLower(query)) {
|
||||
tempMediaList = append(tempMediaList, anime)
|
||||
}
|
||||
}
|
||||
|
||||
return &tempMediaList
|
||||
}
|
||||
|
||||
func AnimeToName(anime *verniy.Media) *string {
|
||||
if anime == nil {
|
||||
return nil
|
||||
|
||||
29
src/main.go
29
src/main.go
@@ -47,6 +47,8 @@ func main() {
|
||||
window = appW.NewWindow(AppName)
|
||||
window.Resize(fyne.NewSize(1000, 700))
|
||||
window.CenterOnScreen()
|
||||
|
||||
initMenuOption()
|
||||
window.Show()
|
||||
|
||||
appW.Settings().SetTheme(&forcedVariant{
|
||||
@@ -185,14 +187,13 @@ func initMainApp() {
|
||||
|
||||
input := widget.NewEntry()
|
||||
input.SetPlaceHolder("Filter anime name")
|
||||
input.OnChanged = func(s string) {
|
||||
debounced(func() {
|
||||
fmt.Println(s)
|
||||
})
|
||||
}
|
||||
|
||||
radiobox := widget.NewRadioGroup([]string{"Watching", "Planning", "Completed", "Dropped"}, func(s string) {
|
||||
animeList = anilist.FindList(s)
|
||||
if input.Text == "" {
|
||||
animeList = anilist.FindList(s)
|
||||
} else {
|
||||
animeList = anilist.FindListWithQuery(s, input.Text)
|
||||
}
|
||||
if updateAnimeNames(data) {
|
||||
listDisplay.Unselect(0)
|
||||
listDisplay.Select(0)
|
||||
@@ -202,6 +203,22 @@ func initMainApp() {
|
||||
radiobox.Required = true
|
||||
radiobox.Horizontal = true
|
||||
|
||||
input.OnChanged = func(s string) {
|
||||
debounced(func() {
|
||||
fmt.Println("Search:", s)
|
||||
if s == "" {
|
||||
animeList = anilist.FindList(radiobox.Selected)
|
||||
} else {
|
||||
animeList = anilist.FindListWithQuery(radiobox.Selected, s)
|
||||
}
|
||||
if updateAnimeNames(data) {
|
||||
listDisplay.Unselect(0)
|
||||
listDisplay.Select(0)
|
||||
listDisplay.ScrollToTop()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
toolbar := widget.NewToolbar(
|
||||
widget.NewToolbarAction(theme.ContentAddIcon(), func() {
|
||||
setDialogAddAnime()
|
||||
|
||||
@@ -1,11 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
var dialogMenuOption *dialog.CustomDialog
|
||||
|
||||
func initMenuOption() {
|
||||
rowSkipOpening := container.New(layout.NewFormLayout(),
|
||||
widget.NewLabelWithStyle("Automatically skip Opening", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
|
||||
widget.NewCheck("", func(b bool) { fmt.Println(b) }),
|
||||
widget.NewLabelWithStyle("Automatically skip Ending", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
|
||||
widget.NewCheck("", func(b bool) { fmt.Println(b) }),
|
||||
)
|
||||
//form := container.New(layout.NewFormLayout(), rowSkipOpening)
|
||||
menuOption := container.NewBorder(nil, nil, nil, nil, rowSkipOpening)
|
||||
dialogMenuOption = dialog.NewCustom("Menu", "Close menu", menuOption, window)
|
||||
dialogMenuOption.Resize(fyne.NewSize(200, 300))
|
||||
}
|
||||
|
||||
func openMenuOption() {
|
||||
dialogMenuOption := dialog.NewCustom("Menu", "Go back", container.NewCenter(), window)
|
||||
dialogMenuOption.Show()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user