ElixirCLE / CoverMyPingPong

Ping Pong leaderboard
https://covermypingpong.herokuapp.com
0 stars 0 forks source link

Add pagination to matches #19

Closed Serneum closed 7 years ago

Serneum commented 7 years ago

Ideally this would be paginated by date

Total pages is determined by the number of distinct dates When on a page, look up that date and return all matches When on the first page, show matches from the most recent day that had matches

See comments in #17

Serneum commented 7 years ago

I have some thoughts on how to do this with Scrivener. Making some notes here:

from(g in Game, distinct: true, select: g.played_at_date, order_by: [desc: :played_at_date])

This potentially requires Scrivener.List

def index(conn, params) do
  page = from(g in Game, distinct: true, select: g.played_at_date, order_by: [desc: :played_at_date])
  |> CoverMyPingPong.Game.paginate(params)

  games =
    CoverMyPingPong.Game
    |> where(g.played_at_date: page.entries |> List.first)

  render conn, :index,
    games: games
end

The general idea is that we paginate based on the number of unique dates and look up games based on the current page (the currently selected date)