message: Extract function to load an example page
diff: @@ -37,20 +37,7 @@ exampleChannelQuery = """
  #{require '../../components/block_v2/queries/block.coffee'}
  """
  -app.get '/api/examples/:id', (req, res, next) ->
  - example = find(examples, (example) -> example.id is req.params.id)
  - send =
  - query: exampleChannelQuery
  - user: req.user
  - variables:
  - ids: example.channel_ids
  -
  - graphQL(send).then ({ channels }) ->
  - example.channels = channels
  - res.json example
  -
  -app.get '/api/examples', (req, res, next) ->
  - page = req.query.page or 1
  +getExamplePage = (page = 1, user) ->
  offset = (page - 1) * DEFAULT_ARGS.per
  examplesPage = rest(examples, offset).slice(0, DEFAULT_ARGS.per)
  @@ -58,7 +45,7 @@ app.get '/api/examples', (req, res, next) ->
  map examplesPage, (example) ->
  send =
  query: exampleChannelQuery
  - user: req.user
  + user: user
  variables:
  ids: first(example.channel_ids, 2)
  graphQL(send)
  @@ -66,25 +53,28 @@ app.get '/api/examples', (req, res, next) ->
  .then (results) ->
  each results, (result, i) ->
  examplesPage[i].channels = result.channels
  + examplesPage
  - res.json examplesPage
  -app.get '/examples', (req, res, next) ->
  - Promise.all(
  - map first(examples, DEFAULT_ARGS.per), (example) ->
  +app.get '/api/examples/:id', (req, res, next) ->
  + example = find(examples, (example) -> example.id is req.params.id)
  send =
  query: exampleChannelQuery
  user: req.user
  variables:
  - ids: first(example.channel_ids, 2)
  + ids: example.channel_ids
  - graphQL(send)
  - )
  - .then (results) ->
  - each results, (result, i) ->
  - examples[i].channels = result.channels
  + graphQL(send).then ({ channels }) ->
  + example.channels = channels
  + res.json example
  - res.locals.examples = examples
  +app.get '/api/examples', (req, res, next) ->
  + getExamplePage(req.query.page, req.user).then (examplesPage) ->
  + res.json examplesPage
  +
  +app.get '/examples', (req, res, next) ->
  + getExamplePage(1, req.user).then (examplesPage) ->
  + res.locals.examples = examplesPage
  res.locals.totalExamples = examples.length
  res.locals.totalPages = Math.ceil(examples.length / DEFAULT_ARGS.per)
  res.render 'index'
  