added pagination! (at least on the timeline)
This commit is contained in:
parent
6c4bff5346
commit
c279026ce0
|
@ -0,0 +1,15 @@
|
|||
jQuery ->
|
||||
if $('#pagination').size() > 0
|
||||
$('#pagination').hide()
|
||||
loading_posts = false
|
||||
|
||||
$('#load-more-btn').show().click ->
|
||||
unless loading_posts
|
||||
loading_posts = true
|
||||
more_posts_url = $('#pagination .pagination .next a').attr('href')
|
||||
$this = $(this)
|
||||
$this.html('<i class="fa fa-spinner fa-spin"></i>').addClass('disabled')
|
||||
$.getScript more_posts_url, ->
|
||||
$this.text('Load more').removeClass('disabled') if $this
|
||||
loading_posts = false
|
||||
return
|
|
@ -12,6 +12,7 @@ class Ajax::AnswerController < ApplicationController
|
|||
end
|
||||
|
||||
answer.user.decrement! :answered_count
|
||||
answer.question.decrement! :answer_count
|
||||
if answer.user == current_user
|
||||
Inbox.create!(user: answer.user, question: answer.question, new: true)
|
||||
end # TODO: decide what happens with the question
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
class StaticController < ApplicationController
|
||||
def index
|
||||
if user_signed_in?
|
||||
@timeline = current_user.timeline.paginate(page: params[:page])
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def about
|
||||
|
|
|
@ -36,8 +36,15 @@
|
|||
.col-md-9.col-xs-12.col-sm-9
|
||||
= render 'layouts/messages'
|
||||
|
||||
- current_user.timeline.each do |answer|
|
||||
= render 'shared/answerbox', a: answer
|
||||
#timeline
|
||||
- @timeline.each do |answer|
|
||||
= render 'shared/answerbox', a: answer
|
||||
|
||||
#pagination= will_paginate @timeline, renderer: BootstrapPagination::Rails, page_links: false
|
||||
|
||||
- if @timeline.next_page
|
||||
%button#load-more-btn.btn.btn-default{type: :button, 'data-current-page' => @timeline.current_page, 'data-type' => 'timeline'}
|
||||
Load more
|
||||
= render "shared/links"
|
||||
- else
|
||||
.jumbotron
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
$('#timeline').append('<% @timeline.each do |answer|
|
||||
%><%= j render 'shared/answerbox', a: answer
|
||||
%><% end %>');
|
||||
<% if @timeline.next_page %>
|
||||
var _p = $('#pagination');
|
||||
_p.replaceWith('<%= j will_paginate @timeline, renderer: BootstrapPagination::Rails, page_links: false %>');
|
||||
_p.hide();
|
||||
<% else %>
|
||||
$('#pagination, #load-more-btn').remove();
|
||||
<% end %>
|
Loading…
Reference in New Issue