diff --git a/arn/AnimeList.go b/arn/AnimeList.go index 2dbb4db7..fe287170 100644 --- a/arn/AnimeList.go +++ b/arn/AnimeList.go @@ -226,31 +226,12 @@ func (list *AnimeList) WithoutPrivateItems() *AnimeList { // SplitByStatus splits the anime list into multiple ones by status. func (list *AnimeList) SplitByStatus() map[string]*AnimeList { - statusToList := map[string]*AnimeList{} - - statusToList[AnimeListStatusWatching] = &AnimeList{ - UserID: list.UserID, - Items: []*AnimeListItem{}, - } - - statusToList[AnimeListStatusCompleted] = &AnimeList{ - UserID: list.UserID, - Items: []*AnimeListItem{}, - } - - statusToList[AnimeListStatusPlanned] = &AnimeList{ - UserID: list.UserID, - Items: []*AnimeListItem{}, - } - - statusToList[AnimeListStatusHold] = &AnimeList{ - UserID: list.UserID, - Items: []*AnimeListItem{}, - } - - statusToList[AnimeListStatusDropped] = &AnimeList{ - UserID: list.UserID, - Items: []*AnimeListItem{}, + statusToList := map[string]*AnimeList{ + AnimeListStatusWatching: {UserID: list.UserID}, + AnimeListStatusCompleted: {UserID: list.UserID}, + AnimeListStatusPlanned: {UserID: list.UserID}, + AnimeListStatusHold: {UserID: list.UserID}, + AnimeListStatusDropped: {UserID: list.UserID}, } list.Lock() diff --git a/mixins/StatusTabs.pixy b/mixins/StatusTabs.pixy index 7732ab3b..00f9e2ae 100644 --- a/mixins/StatusTabs.pixy +++ b/mixins/StatusTabs.pixy @@ -1,7 +1,7 @@ -component StatusTabs(urlPrefix string) +component StatusTabs(urlPrefix string, statusLists map[string]*arn.AnimeList) .tabs - Tab("Watching", "play", urlPrefix + "/watching") - Tab("Completed", "check", urlPrefix + "/completed") - Tab("Planned", "forward", urlPrefix + "/planned") - Tab("On Hold", "pause", urlPrefix + "/hold") - Tab("Dropped", "stop", urlPrefix + "/dropped") \ No newline at end of file + TabWithCount("Watching", len(statusLists[arn.AnimeListStatusWatching].Items), "play", urlPrefix + "/watching") + TabWithCount("Completed", len(statusLists[arn.AnimeListStatusCompleted].Items), "check", urlPrefix + "/completed") + TabWithCount("Planned", len(statusLists[arn.AnimeListStatusPlanned].Items), "forward", urlPrefix + "/planned") + TabWithCount("On Hold", len(statusLists[arn.AnimeListStatusHold].Items), "pause", urlPrefix + "/hold") + TabWithCount("Dropped", len(statusLists[arn.AnimeListStatusDropped].Items), "stop", urlPrefix + "/dropped") \ No newline at end of file diff --git a/mixins/Tab.pixy b/mixins/Tab.pixy index 9b1faac4..4555492e 100644 --- a/mixins/Tab.pixy +++ b/mixins/Tab.pixy @@ -1,4 +1,10 @@ component Tab(label string, icon string, url string) a.tab.action(href=url, data-action="diff", data-trigger="click", aria-label=label, dropzone="move") Icon(icon) - span.tab-text= label \ No newline at end of file + span.tab-text= label + +component TabWithCount(label string, count int, icon string, url string) + a.tab.action(href=url, data-action="diff", data-trigger="click", aria-label=label, dropzone="move") + Icon(icon) + span.tab-text= label + span.tab-count= count \ No newline at end of file diff --git a/pages/animelist/animelist.go b/pages/animelist/animelist.go index 1cec14b4..01600ab3 100644 --- a/pages/animelist/animelist.go +++ b/pages/animelist/animelist.go @@ -48,18 +48,19 @@ func AnimeList(ctx aero.Context, user *arn.User, status string, sortBy string) e return ctx.Error(http.StatusNotFound, "Anime list not found") } - statusList := animeList.FilterStatus(status) - // Filter private items if user == nil || user.ID != viewUser.ID { - statusList = statusList.WithoutPrivateItems() + animeList = animeList.WithoutPrivateItems() } - // Sort the items - statusList.Sort(sortBy) + statusLists := animeList.SplitByStatus() + + // Sort the items for the requested status only + animeList = statusLists[status] + animeList.Sort(sortBy) // These are all anime list items for the given status - allItems := statusList.Items + allItems := statusLists[status].Items // Slice the part that we need items := allItems[index:] @@ -102,5 +103,5 @@ func AnimeList(ctx aero.Context, user *arn.User, status string, sortBy string) e } // Otherwise, send the full page - return ctx.HTML(components.AnimeListPage(items, nextIndex, viewUser, user, status)) + return ctx.HTML(components.AnimeListPage(items, nextIndex, viewUser, user, statusLists)) } diff --git a/pages/animelist/animelist.pixy b/pages/animelist/animelist.pixy index 44a9de8e..2029a18c 100644 --- a/pages/animelist/animelist.pixy +++ b/pages/animelist/animelist.pixy @@ -1,9 +1,9 @@ -component AnimeListPage(animeListItems []*arn.AnimeListItem, nextIndex int, viewUser *arn.User, user *arn.User, status string) +component AnimeListPage(animeListItems []*arn.AnimeListItem, nextIndex int, viewUser *arn.User, user *arn.User, statusLists map[string]*arn.AnimeList) h1.page-title= viewUser.Nick + "'s anime list" if user == nil || user.ID != viewUser.ID .anime-list-user-avatar AvatarNoTip(viewUser) - StatusTabs("/+" + viewUser.Nick + "/animelist") + StatusTabs("/+" + viewUser.Nick + "/animelist", statusLists) AnimeListItems(animeListItems, nextIndex, viewUser, user) \ No newline at end of file diff --git a/styles/tabs.scarlet b/styles/tabs.scarlet index 75262de8..c382cd83 100644 --- a/styles/tabs.scarlet +++ b/styles/tabs.scarlet @@ -31,6 +31,10 @@ const tab-padding-x = 1rem border-top-right-radius ui-element-border-radius border-bottom-right-radius ui-element-border-radius +.tab-count + margin-left typography-margin + opacity 0.5 + < 920px .tab padding 0.75rem tab-padding-x @@ -38,7 +42,8 @@ const tab-padding-x = 1rem .padded-icon margin-right 0 - .tab-text + .tab-text, + .tab-count display none .tabs