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 | var animeMapPreview map[string]RofiSelectPreview | 531 | var animeMapPreview map[string]RofiSelectPreview |
| 532 | var err error | 532 | var err error |
| 533 | var anilistSelectedOption SelectionOption | 533 | var anilistSelectedOption SelectionOption |
| 534 | var anilistUserData map[string]interface{} | ||
| 535 | var anilistUserDataPreview map[string]interface{} | ||
| 536 | 534 | ||
| 537 | if userCurdConfig.RofiSelection { | 535 | if userCurdConfig.RofiSelection { |
| 538 | userInput, err := GetUserInputFromRofi("Enter the anime name") | 536 | userInput, err := GetUserInputFromRofi("Enter the anime name") |
| @@ -573,30 +571,49 @@ func AddNewAnime(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseA | |||
| 573 | Log(fmt.Sprintf("Failed to convert anime ID to integer: %v", err)) | 571 | Log(fmt.Sprintf("Failed to convert anime ID to integer: %v", err)) |
| 574 | ExitCurd(fmt.Errorf("Failed to convert anime ID to integer")) | 572 | ExitCurd(fmt.Errorf("Failed to convert anime ID to integer")) |
| 575 | } | 573 | } |
| 576 | err = AddAnimeToWatchingList(animeID, user.Token) | 574 | |
| 577 | if err != nil { | 575 | // Add category selection before adding to list |
| 578 | Log(fmt.Sprintf("Failed to add anime to watching list: %v", err)) | 576 | categories := map[string]string{ |
| 579 | ExitCurd(fmt.Errorf("Failed to add anime to watching list")) | 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 { | 583 | |
| 582 | user.Id, user.Username, err = GetAnilistUserID(user.Token) | 584 | ClearScreen() |
| 583 | if err != nil { | 585 | CurdOut("Select which list to add the anime to:") |
| 584 | Log(fmt.Sprintf("Failed to get user ID: %v", err)) | 586 | |
| 585 | ExitCurd(fmt.Errorf("Failed to get user ID\nYou can reset the token by running `curd -change-token`")) | 587 | categorySelection, err := DynamicSelect(categories, false) |
| 586 | } | 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 { | 592 | |
| 589 | anilistUserDataPreview, err = GetUserDataPreview(user.Token, user.Id) | 593 | if categorySelection.Key == "-1" { |
| 590 | } else { | 594 | ExitCurd(nil) |
| 591 | anilistUserData, err = GetUserData(user.Token, user.Id) | ||
| 592 | } | 595 | } |
| 596 | |||
| 597 | err = UpdateAnimeStatus(user.Token, animeID, categorySelection.Key) | ||
| 593 | if err != nil { | 598 | if err != nil { |
| 594 | Log(fmt.Sprintf("Failed to get user data: %v", err)) | 599 | Log(fmt.Sprintf("Failed to add anime to list: %v", err)) |
| 595 | ExitCurd(fmt.Errorf("Failed to get user ID\nYou can reset the token by running `curd -change-token`")) | 600 | ExitCurd(fmt.Errorf("Failed to add anime to list")) |
| 596 | } | 601 | } |
| 602 | |||
| 603 | // Refresh user's anime list after adding | ||
| 597 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { | 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 | user.AnimeList = ParseAnimeList(anilistUserDataPreview) | 610 | user.AnimeList = ParseAnimeList(anilistUserDataPreview) |
| 599 | } else { | 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 | user.AnimeList = ParseAnimeList(anilistUserData) | 617 | user.AnimeList = ParseAnimeList(anilistUserData) |
| 601 | } | 618 | } |
| 602 | 619 | ||