2018-03-19 11:25:31 +00:00
|
|
|
package profilequotes
|
|
|
|
|
2018-12-04 23:49:21 +00:00
|
|
|
// import (
|
|
|
|
// "net/http"
|
|
|
|
|
|
|
|
// "github.com/aerogo/aero"
|
2019-06-03 09:32:43 +00:00
|
|
|
// "github.com/animenotifier/notify.moe/arn"
|
2018-12-04 23:49:21 +00:00
|
|
|
// "github.com/animenotifier/notify.moe/components"
|
|
|
|
// "github.com/animenotifier/notify.moe/utils"
|
|
|
|
// "github.com/animenotifier/notify.moe/utils/infinitescroll"
|
|
|
|
// )
|
|
|
|
|
|
|
|
// const (
|
|
|
|
// quotesFirstLoad = 12
|
|
|
|
// quotesPerScroll = 9
|
|
|
|
// )
|
|
|
|
|
|
|
|
// // render renders the quotes on user profiles.
|
2019-06-01 04:55:49 +00:00
|
|
|
// func render(ctx aero.Context, fetch func(userID string) []*arn.Quote) string {
|
2018-12-04 23:49:21 +00:00
|
|
|
// nick := ctx.Get("nick")
|
|
|
|
// index, _ := ctx.GetInt("index")
|
2019-11-17 07:59:34 +00:00
|
|
|
// user := arn.GetUserFromContext(ctx)
|
2018-12-04 23:49:21 +00:00
|
|
|
// viewUser, err := arn.GetUserByNick(nick)
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
// return ctx.Error(http.StatusNotFound, "User not found", err)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // Fetch all eligible quotes
|
|
|
|
// allQuotes := fetch(viewUser.ID)
|
|
|
|
|
|
|
|
// // Sort the quotes by publication date
|
|
|
|
// arn.SortQuotesLatestFirst(allQuotes)
|
|
|
|
|
|
|
|
// // Slice the part that we need
|
|
|
|
// quotes := allQuotes[index:]
|
|
|
|
// maxLength := quotesFirstLoad
|
|
|
|
|
|
|
|
// if index > 0 {
|
|
|
|
// maxLength = quotesPerScroll
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if len(quotes) > maxLength {
|
|
|
|
// quotes = quotes[:maxLength]
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // Next index
|
|
|
|
// nextIndex := infinitescroll.NextIndex(ctx, len(allQuotes), maxLength, index)
|
|
|
|
|
|
|
|
// // In case we're scrolling, send quotes only (without the page frame)
|
|
|
|
// if index > 0 {
|
|
|
|
// return ctx.HTML(components.QuotesScrollable(quotes, user))
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // Otherwise, send the full page
|
2019-06-01 04:55:49 +00:00
|
|
|
// return ctx.HTML(components.ProfileQuotes(quotes, viewUser, nextIndex, user, ctx.Path()))
|
2018-12-04 23:49:21 +00:00
|
|
|
// }
|