Commit 20bb501c7f
Unsigned
Layout: unified · split
internal/curd.go +4 −11
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | package internal |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | "bufio" | |
| 4 | 5 | "crypto/md5" |
| 5 | 6 | "encoding/json" |
| 6 | 7 | "fmt" |
| @@ -14,7 +15,7 @@ import ( | ||
| 14 | 15 | "strconv" |
| 15 | 16 | "strings" |
| 16 | 17 | "time" |
| 17 | "bufio" | |
| 18 | ||
| 18 | 19 | "github.com/gen2brain/beeep" |
| 19 | 20 | ) |
| 20 | 21 | |
| @@ -592,7 +593,7 @@ func UpdateCurd(repo, fileName string) error { | ||
| 592 | 593 | |
| 593 | 594 | func AddNewAnime(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAnimes *[]Anime) SelectionOption { |
| 594 | 595 | var query string |
| 595 | var animeOptions []SelectionOption | |
| 596 | // Remove the redeclared variable declaration since animeOptions is already declared above | |
| 596 | 597 | var animeMapPreview map[string]RofiSelectPreview |
| 597 | 598 | var animeOptions []SelectionOption |
| 598 | 599 | var err error |
| @@ -614,19 +615,11 @@ func AddNewAnime(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseA | ||
| 614 | 615 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 615 | 616 | animeMapPreview, err = SearchAnimeAnilistPreview(query, user.Token) |
| 616 | 617 | } else { |
| 617 | animeMap, err := SearchAnimeAnilist(query, user.Token) | |
| 618 | animeOptions, err = SearchAnimeAnilist(query, user.Token) | |
| 618 | 619 | if err != nil { |
| 619 | 620 | Log(fmt.Sprintf("Failed to search anime: %v", err)) |
| 620 | 621 | ExitCurd(fmt.Errorf("Failed to search anime")) |
| 621 | 622 | } |
| 622 | // Convert map to []SelectionOption | |
| 623 | animeOptions = make([]SelectionOption, 0, len(animeMap)) | |
| 624 | for key, label := range animeMap { | |
| 625 | animeOptions = append(animeOptions, SelectionOption{ | |
| 626 | Key: key, | |
| 627 | Label: label, | |
| 628 | }) | |
| 629 | } | |
| 630 | 623 | } |
| 631 | 624 | if err != nil { |
| 632 | 625 | Log(fmt.Sprintf("Failed to search anime: %v", err)) |
internal/selection_menu.go +3 −20
| @@ -388,30 +388,13 @@ func RofiSelect(options []SelectionOption) (SelectionOption, error) { | ||
| 388 | 388 | |
| 389 | 389 | func DynamicSelectFromSlice(options []SelectionOption) (SelectionOption, error) { |
| 390 | 390 | if GetGlobalConfig().RofiSelection { |
| 391 | optionsMap := make(map[string]string) | |
| 392 | for _, option := range options { | |
| 393 | optionsMap[option.Key] = option.Label | |
| 394 | } | |
| 395 | return RofiSelect(optionsMap) | |
| 396 | } | |
| 397 | ||
| 398 | // slice to maintain order | |
| 399 | var orderedOptions []SelectionOption | |
| 400 | for _, option := range options { | |
| 401 | orderedOptions = append(orderedOptions, option) | |
| 391 | return RofiSelect(options) | |
| 402 | 392 | } |
| 403 | 393 | |
| 404 | 394 | model := &Model{ |
| 405 | options: make(map[string]string), // empty map since we're using slice | |
| 406 | filteredKeys: orderedOptions, | |
| 407 | useSliceMode: true, // slice-based filtering | |
| 408 | originalOptions: orderedOptions, // store original options for filtering | |
| 395 | allOptions: options, | |
| 409 | 396 | } |
| 410 | ||
| 411 | model.filteredKeys = append(model.filteredKeys, SelectionOption{ | |
| 412 | Label: "Quit", | |
| 413 | Key: "-1", | |
| 414 | }) | |
| 397 | model.filterOptions() // Initialize filtered options | |
| 415 | 398 | |
| 416 | 399 | p := tea.NewProgram(model) |
| 417 | 400 | |