aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-06-30 01:01:45 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-06-30 01:01:45 +0530
commite9355deabb849a123670e6678427cf33007d01f1 (patch)
treef86f42e8601536a35c4b26be19bfca7720f51be2 /ui
parent5ad76ed2e6e67b421c27ff153e2ae348152eaa40 (diff)
showing number of episodes/chapters watched/read when updating them
Diffstat (limited to 'ui')
-rw-r--r--ui/episodes.go28
1 files changed, 14 insertions, 14 deletions
diff --git a/ui/episodes.go b/ui/episodes.go
index 8b39119..277d52f 100644
--- a/ui/episodes.go
+++ b/ui/episodes.go
@@ -30,6 +30,11 @@ import (
)
func EpisodeInput(anime a.Anime) {
+ // fetch number of total episodes, number of watched episodes from the API
+ animeData := mal.GetAnimeData(anime.Id, []string{"num_episodes", "my_list_status"})
+ epWatchedNum := animeData.MyListStatus.EpWatched
+ epTotalNum := animeData.NumEpisodes
+
validate := func(input string) error {
if _, err := strconv.ParseFloat(input, 64); err != nil {
return errors.New("Input must be a number.")
@@ -44,27 +49,27 @@ func EpisodeInput(anime a.Anime) {
}
prompt := p.Prompt {
- Label: "Set Episode Number: ",
+ Label: fmt.Sprintf("Set Episode Number (%d/%d watched):", epWatchedNum, epTotalNum),
Templates: template,
Validate: validate,
}
- // print current episode number if any
- epNum := anime.MyListStatus.EpWatched
- if epNum != 0 {
- fmt.Printf("\x1b[33mYou currently have watched %d episodes.\n\x1b[0m", epNum)
- }
-
res, err := prompt.Run()
if err != nil {
fmt.Println("Error Running episode input Prompt.", err.Error())
os.Exit(1)
}
+ // TODO: read resp and show confirmation message
mal.SetEpisodes(anime.Id, res)
}
func ChapterInput(manga m.Manga) {
+ // fetch number of total chapters, number of read chapters from the API
+ animeData := mal.GetMangaData(manga.Id, []string{"num_chapters", "my_list_status"})
+ chReadNum := animeData.MyListStatus.ChaptersRead
+ chTotalNum := animeData.NumChapters
+
validate := func(input string) error {
if _, err := strconv.ParseFloat(input, 64); err != nil {
return errors.New("Input must be a number.")
@@ -79,22 +84,17 @@ func ChapterInput(manga m.Manga) {
}
prompt := p.Prompt {
- Label: "Set Chapter Number: ",
+ Label: fmt.Sprintf("Set Chapter Number (%d/%d read):", chReadNum, chTotalNum),
Templates: template,
Validate: validate,
}
- // print current chapter number if any
- chNum := manga.MyListStatus.ChaptersRead
- if chNum != 0 {
- fmt.Printf("\x1b[33mYou currently have read %d chapters.\n\x1b[0m", chNum)
- }
-
res, err := prompt.Run()
if err != nil {
fmt.Println("Error Running chapter input Prompt.", err.Error())
os.Exit(1)
}
+ // TODO: read resp and show confirmation message
mal.SetChapters(manga.Id, res)
}