Added number of list items for status tabs
This commit is contained in:
parent
af63870850
commit
384f966524
@ -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()
|
||||
|
@ -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")
|
||||
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")
|
@ -2,3 +2,9 @@ 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
|
||||
|
||||
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
|
@ -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))
|
||||
}
|
||||
|
@ -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)
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user