diff --git a/app/controllers/public_controller.rb b/app/controllers/public_controller.rb new file mode 100644 index 00000000..677ef4eb --- /dev/null +++ b/app/controllers/public_controller.rb @@ -0,0 +1,9 @@ +class PublicController < ApplicationController + def index + @timeline = Answer.all.reverse_order.paginate(page: params[:page]) + respond_to do |format| + format.html + format.js + end + end +end diff --git a/app/helpers/public_helper.rb b/app/helpers/public_helper.rb new file mode 100644 index 00000000..0d8e188e --- /dev/null +++ b/app/helpers/public_helper.rb @@ -0,0 +1,2 @@ +module PublicHelper +end diff --git a/app/views/public/index.html.haml b/app/views/public/index.html.haml new file mode 100644 index 00000000..fafb67e1 --- /dev/null +++ b/app/views/public/index.html.haml @@ -0,0 +1,16 @@ +.container.j2-page + .col-md-3.col-sm-3.hidden-xs + = render 'shared/links' + .col-md-9.col-xs-12.col-sm-9 + = render 'layouts/messages' + + #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 }} + Load more +.visible-xs= render 'shared/links' diff --git a/app/views/public/index.js.erb b/app/views/public/index.js.erb new file mode 100644 index 00000000..9ce16da7 --- /dev/null +++ b/app/views/public/index.js.erb @@ -0,0 +1,8 @@ +$('#timeline').append('<% @timeline.each do |answer| + %><%= j render 'shared/answerbox', a: answer +%><% end %>'); +<% if @timeline.next_page %> + $('#pagination').html('<%= j will_paginate @timeline, renderer: BootstrapPagination::Rails, page_links: false %>'); +<% else %> + $('#pagination, #load-more-btn').remove(); +<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index f99b8c19..9023408f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -40,6 +40,8 @@ Rails.application.routes.draw do match '/create_comment', to: 'comment#create', via: :post, as: :create_comment end + match '/public', to: 'public#index', via: :get, as: :public_timeline + match '/inbox', to: 'inbox#show', via: 'get' match '/user/:username(/p/:page)', to: 'user#show', via: 'get', defaults: {page: 1}