Commit c3d1c0fecf
Unsigned
Layout: unified · split
internal/curd.go +35 −18
| @@ -531,8 +531,6 @@ func AddNewAnime(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseA | ||
| 531 | 531 | var animeMapPreview map[string]RofiSelectPreview |
| 532 | 532 | var err error |
| 533 | 533 | var anilistSelectedOption SelectionOption |
| 534 | var anilistUserData map[string]interface{} | |
| 535 | var anilistUserDataPreview map[string]interface{} | |
| 536 | 534 | |
| 537 | 535 | if userCurdConfig.RofiSelection { |
| 538 | 536 | userInput, err := GetUserInputFromRofi("Enter the anime name") |
| @@ -573,30 +571,49 @@ func AddNewAnime(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseA | ||
| 573 | 571 | Log(fmt.Sprintf("Failed to convert anime ID to integer: %v", err)) |
| 574 | 572 | ExitCurd(fmt.Errorf("Failed to convert anime ID to integer")) |
| 575 | 573 | } |
| 576 | err = AddAnimeToWatchingList(animeID, user.Token) | |
| 577 | if err != nil { | |
| 578 | Log(fmt.Sprintf("Failed to add anime to watching list: %v", err)) | |
| 579 | ExitCurd(fmt.Errorf("Failed to add anime to watching list")) | |
| 574 | ||
| 575 | // Add category selection before adding to list | |
| 576 | categories := map[string]string{ | |
| 577 | "CURRENT": "Currently Watching", | |
| 578 | "COMPLETED": "Completed", | |
| 579 | "PAUSED": "On Hold", | |
| 580 | "DROPPED": "Dropped", | |
| 581 | "PLANNING": "Plan to Watch", | |
| 580 | 582 | } |
| 581 | if user.Id == 0 { | |
| 582 | user.Id, user.Username, err = GetAnilistUserID(user.Token) | |
| 583 | if err != nil { | |
| 584 | Log(fmt.Sprintf("Failed to get user ID: %v", err)) | |
| 585 | ExitCurd(fmt.Errorf("Failed to get user ID\nYou can reset the token by running `curd -change-token`")) | |
| 586 | } | |
| 583 | ||
| 584 | ClearScreen() | |
| 585 | CurdOut("Select which list to add the anime to:") | |
| 586 | ||
| 587 | categorySelection, err := DynamicSelect(categories, false) | |
| 588 | if err != nil { | |
| 589 | Log(fmt.Sprintf("Failed to select category: %v", err)) | |
| 590 | ExitCurd(fmt.Errorf("Failed to select category")) | |
| 587 | 591 | } |
| 588 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { | |
| 589 | anilistUserDataPreview, err = GetUserDataPreview(user.Token, user.Id) | |
| 590 | } else { | |
| 591 | anilistUserData, err = GetUserData(user.Token, user.Id) | |
| 592 | ||
| 593 | if categorySelection.Key == "-1" { | |
| 594 | ExitCurd(nil) | |
| 592 | 595 | } |
| 596 | ||
| 597 | err = UpdateAnimeStatus(user.Token, animeID, categorySelection.Key) | |
| 593 | 598 | if err != nil { |
| 594 | Log(fmt.Sprintf("Failed to get user data: %v", err)) | |
| 595 | ExitCurd(fmt.Errorf("Failed to get user ID\nYou can reset the token by running `curd -change-token`")) | |
| 599 | Log(fmt.Sprintf("Failed to add anime to list: %v", err)) | |
| 600 | ExitCurd(fmt.Errorf("Failed to add anime to list")) | |
| 596 | 601 | } |
| 602 | ||
| 603 | // Refresh user's anime list after adding | |
| 597 | 604 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 605 | anilistUserDataPreview, err := GetUserDataPreview(user.Token, user.Id) | |
| 606 | if err != nil { | |
| 607 | Log(fmt.Sprintf("Failed to refresh anime list: %v", err)) | |
| 608 | ExitCurd(fmt.Errorf("Failed to refresh anime list")) | |
| 609 | } | |
| 598 | 610 | user.AnimeList = ParseAnimeList(anilistUserDataPreview) |
| 599 | 611 | } else { |
| 612 | anilistUserData, err := GetUserData(user.Token, user.Id) | |
| 613 | if err != nil { | |
| 614 | Log(fmt.Sprintf("Failed to refresh anime list: %v", err)) | |
| 615 | ExitCurd(fmt.Errorf("Failed to refresh anime list")) | |
| 616 | } | |
| 600 | 617 | user.AnimeList = ParseAnimeList(anilistUserData) |
| 601 | 618 | } |
| 602 | 619 | |