From 45cb2e6c26e1307034527c6033eb4ec089592cc8 Mon Sep 17 00:00:00 2001 From: Jarmo Riikonen Date: Mon, 2 Jul 2018 16:36:06 +0300 Subject: [PATCH 1/9] Check key string also. Keycode is not reliable for checking anything else than letters. --- scripts/AnimeNotifier.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index e9f96420..9caad55d 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -1054,14 +1054,15 @@ export default class AnimeNotifier { return preventDefault() } + // "+" = Audio speed up - if(e.keyCode === 107 || e.keyCode === 187) { + if(e.keyCode === 107 || e.keyCode === 187 || e.key == "+") { this.audioPlayer.addSpeed(0.05) return preventDefault() } // "-" = Audio speed down - if(e.keyCode === 109 || e.keyCode === 189) { + if(e.keyCode === 109 || e.keyCode === 189 || e.key == "-") { this.audioPlayer.addSpeed(-0.05) return preventDefault() } From ec2d9d98fdbc39e8cbc464ca431cebe723eefa5e Mon Sep 17 00:00:00 2001 From: Jarmo Riikonen Date: Mon, 2 Jul 2018 17:15:17 +0300 Subject: [PATCH 2/9] Show twist.moe eye in Planning and Dropped --- mixins/AnimeList.pixy | 2 +- scripts/AnimeNotifier.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mixins/AnimeList.pixy b/mixins/AnimeList.pixy index ecf4b009..303ab3f9 100644 --- a/mixins/AnimeList.pixy +++ b/mixins/AnimeList.pixy @@ -17,7 +17,7 @@ component AnimeListScrollable(animeListItems []*arn.AnimeListItem, viewUser *arn a(href=item.Link(viewUser.Nick))= item.Anime().Title.ByUser(user) .anime-list-item-actions - if user != nil && item.Status == arn.AnimeListStatusWatching && user.Location.CountryName != "Japan" + if user != nil && item.Status != arn.AnimeListStatusCompleted && user.Location.CountryName != "Japan" //- if user.ID == "KpdWUlPzR" //- a(href=arn.Nyaa.GetLink(item.Anime()), title="Search on Nyaa", target="_blank", rel="noopener") //- RawIcon("download") diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 9caad55d..2e99223a 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -992,6 +992,8 @@ export default class AnimeNotifier { } onKeyDown(e: KeyboardEvent) { + console.log(e.keyCode) + let activeElement = document.activeElement // Ignore hotkeys on input elements From 54e0f4fc094516a125ba48313e76206469879eb6 Mon Sep 17 00:00:00 2001 From: Jarmo Riikonen Date: Mon, 2 Jul 2018 20:57:44 +0300 Subject: [PATCH 3/9] Overall score for Genre for user Requires styling work (out of my skills 100%) Basic mechanics added and someone should continue for styles. --- pages/genre/genre.go | 24 +++++++++++++++++++++++- pages/genre/genre.pixy | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pages/genre/genre.go b/pages/genre/genre.go index bdd7dc76..264212b5 100644 --- a/pages/genre/genre.go +++ b/pages/genre/genre.go @@ -1,6 +1,7 @@ package genre import ( + "strconv" "strings" "github.com/aerogo/aero" @@ -23,13 +24,15 @@ func Get(ctx *aero.Context) string { } } + userScore := averageGenreScore(user, animes) + arn.SortAnimeByQuality(animes) if len(animes) > animePerPage { animes = animes[:animePerPage] } - return ctx.HTML(components.Genre(genreName, animes, user)) + return ctx.HTML(components.Genre(genreName, animes, user, userScore)) } // containsLowerCase tells you whether the given element exists when all elements are lowercased. @@ -42,3 +45,22 @@ func containsLowerCase(array []string, search string) bool { return false } + +func averageGenreScore(user *arn.User, animes []*arn.Anime) string { + if user == nil { + return "" + } + + counter := 0.0 + scores := 0.0 + + for _, anime := range animes { + + if user.AnimeList().Contains(anime.ID) { + scores = scores + user.AnimeList().Find(anime.ID).Rating.Overall + counter = counter + 1 + } + } + + return strconv.FormatFloat(scores/counter, 'f', 6, 64) +} diff --git a/pages/genre/genre.pixy b/pages/genre/genre.pixy index 2174cda4..809d1e5a 100644 --- a/pages/genre/genre.pixy +++ b/pages/genre/genre.pixy @@ -1,5 +1,6 @@ -component Genre(genre string, animes []*arn.Anime, user *arn.User) +component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore string) h1(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre) + h2()= userScore .corner-buttons-hide-on-mobile if user != nil From 25cc163ab37e3c39e781d7ab8acb0b78c6c7eba7 Mon Sep 17 00:00:00 2001 From: Jarmo Riikonen Date: Mon, 2 Jul 2018 21:06:42 +0300 Subject: [PATCH 4/9] Hups, forgot merge right Too sleepy --- scripts/AnimeNotifier.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index f17ef00b..6c5dc098 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -1058,21 +1058,13 @@ export default class AnimeNotifier { // "+" = Audio speed up -<<<<<<< HEAD - if(e.keyCode === 107 || e.keyCode === 187 || e.key == "+") { -======= if(e.key == "+") { ->>>>>>> bd6291290bff210ed9ae2e70fc3820181899470d this.audioPlayer.addSpeed(0.05) return preventDefault() } // "-" = Audio speed down -<<<<<<< HEAD - if(e.keyCode === 109 || e.keyCode === 189 || e.key == "-") { -======= if(e.key == "-") { ->>>>>>> bd6291290bff210ed9ae2e70fc3820181899470d this.audioPlayer.addSpeed(-0.05) return preventDefault() } From 524c39b283d5ffe59b6cc3f9b671eaa601456512 Mon Sep 17 00:00:00 2001 From: Jarmo Riikonen Date: Mon, 2 Jul 2018 21:08:11 +0300 Subject: [PATCH 5/9] For one last time --- scripts/AnimeNotifier.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 6c5dc098..ec86f409 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -992,8 +992,6 @@ export default class AnimeNotifier { } onKeyDown(e: KeyboardEvent) { - console.log(e.keyCode) - let activeElement = document.activeElement // Ignore hotkeys on input elements From 1e5f6549289094ad826b34c538f4a9655d58e434 Mon Sep 17 00:00:00 2001 From: Jarmo Riikonen Date: Tue, 3 Jul 2018 13:13:38 +0300 Subject: [PATCH 6/9] Show only float with 1 decimal for consistency. --- pages/genre/genre.go | 26 ++++++++++++++++---------- pages/genre/genre.pixy | 7 ++++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pages/genre/genre.go b/pages/genre/genre.go index 264212b5..7cb4ad22 100644 --- a/pages/genre/genre.go +++ b/pages/genre/genre.go @@ -1,7 +1,6 @@ package genre import ( - "strconv" "strings" "github.com/aerogo/aero" @@ -24,7 +23,7 @@ func Get(ctx *aero.Context) string { } } - userScore := averageGenreScore(user, animes) + userScore := averageScore(user, animes) arn.SortAnimeByQuality(animes) @@ -46,21 +45,28 @@ func containsLowerCase(array []string, search string) bool { return false } -func averageGenreScore(user *arn.User, animes []*arn.Anime) string { +// Counts users average score in genre +func averageScore(user *arn.User, animes []*arn.Anime) float64 { if user == nil { - return "" + return 0 } - counter := 0.0 + count := 0.0 scores := 0.0 - for _, anime := range animes { + animeList := user.AnimeList() - if user.AnimeList().Contains(anime.ID) { - scores = scores + user.AnimeList().Find(anime.ID).Rating.Overall - counter = counter + 1 + for _, anime := range animes { + userAnime := animeList.Find(anime.ID) + if userAnime != nil && !userAnime.Rating.IsNotRated() { + scores += userAnime.Rating.Overall + count += 1 } } - return strconv.FormatFloat(scores/counter, 'f', 6, 64) + if count == 0.0 || scores == 0.0 { + return 0 + } + + return scores / count } diff --git a/pages/genre/genre.pixy b/pages/genre/genre.pixy index 809d1e5a..d7d7dd50 100644 --- a/pages/genre/genre.pixy +++ b/pages/genre/genre.pixy @@ -1,7 +1,8 @@ -component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore string) +component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore float64) h1(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre) - h2()= userScore - + if user != nil + h2= fmt.Sprintf("%.1f", userScore) + .corner-buttons-hide-on-mobile if user != nil button.action(data-trigger="click", data-action="hideAddedAnime", title="Hide anime in my collection") From 9c80f8dd7e9203acbc92483dc3350ad04fb9cd50 Mon Sep 17 00:00:00 2001 From: Jarmo Riikonen Date: Tue, 3 Jul 2018 13:31:49 +0300 Subject: [PATCH 7/9] Fixed lint error Ok, now I will install linter. --- pages/genre/genre.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/genre/genre.go b/pages/genre/genre.go index 7cb4ad22..6732b018 100644 --- a/pages/genre/genre.go +++ b/pages/genre/genre.go @@ -60,7 +60,7 @@ func averageScore(user *arn.User, animes []*arn.Anime) float64 { userAnime := animeList.Find(anime.ID) if userAnime != nil && !userAnime.Rating.IsNotRated() { scores += userAnime.Rating.Overall - count += 1 + count++ } } From a45b2598391aa4a5ba3f6439a66dbacd95e4923e Mon Sep 17 00:00:00 2001 From: Jarmo Riikonen Date: Tue, 3 Jul 2018 15:46:32 +0300 Subject: [PATCH 8/9] Better comment for averageScore --- pages/genre/genre.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/genre/genre.go b/pages/genre/genre.go index 6732b018..3712e2b4 100644 --- a/pages/genre/genre.go +++ b/pages/genre/genre.go @@ -45,7 +45,7 @@ func containsLowerCase(array []string, search string) bool { return false } -// Counts users average score in genre +// Counts users average score for selected animes func averageScore(user *arn.User, animes []*arn.Anime) float64 { if user == nil { return 0 From ed58f31ba204f7dbd4f2ac598257339715581b54 Mon Sep 17 00:00:00 2001 From: Jarmo Riikonen Date: Tue, 3 Jul 2018 16:33:35 +0300 Subject: [PATCH 9/9] Fixes --- pages/genre/genre.go | 3 ++- pages/genre/genre.pixy | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pages/genre/genre.go b/pages/genre/genre.go index 3712e2b4..43383d22 100644 --- a/pages/genre/genre.go +++ b/pages/genre/genre.go @@ -58,13 +58,14 @@ func averageScore(user *arn.User, animes []*arn.Anime) float64 { for _, anime := range animes { userAnime := animeList.Find(anime.ID) + if userAnime != nil && !userAnime.Rating.IsNotRated() { scores += userAnime.Rating.Overall count++ } } - if count == 0.0 || scores == 0.0 { + if count == 0.0 { return 0 } diff --git a/pages/genre/genre.pixy b/pages/genre/genre.pixy index d7d7dd50..7224ed06 100644 --- a/pages/genre/genre.pixy +++ b/pages/genre/genre.pixy @@ -1,5 +1,6 @@ component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore float64) h1(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre) + if user != nil h2= fmt.Sprintf("%.1f", userScore)