Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit e1d751f

Browse files
committed
Add pagination to avoid extremely slow load times
1 parent 1ea26d7 commit e1d751f

File tree

8 files changed

+72
-4
lines changed

8 files changed

+72
-4
lines changed

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ gem 'rails_12factor'
3636

3737
gem 'gemoji'
3838

39+
gem 'will_paginate'
40+
3941
# Use ActiveModel has_secure_password
4042
# gem 'bcrypt', '~> 3.1.7'
4143

Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ GEM
204204
binding_of_caller (>= 0.7.2)
205205
railties (>= 4.0)
206206
sprockets-rails (>= 2.0, < 4.0)
207+
will_paginate (3.1.0)
207208

208209
PLATFORMS
209210
ruby
@@ -229,6 +230,7 @@ DEPENDENCIES
229230
turbolinks
230231
uglifier (>= 1.3.0)
231232
web-console (~> 2.0)
233+
will_paginate
232234

233235
RUBY VERSION
234236
ruby 2.3.4p301

app/assets/stylesheets/application.sass

+49
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,52 @@ body, main
9292

9393
.well--l
9494
margin-bottom: $b-space-xl
95+
96+
.pagination
97+
border: 1px solid #e5e5e5
98+
text-align: center
99+
margin: 0 0 1em 0
100+
padding: 1em 0
101+
cursor: default
102+
103+
a, span
104+
padding: 0 0.4em
105+
106+
.disabled
107+
color: #aaaaaa
108+
109+
.current
110+
font-style: normal
111+
font-weight: bold
112+
background-color: $c-primary
113+
color: $white
114+
display: inline-block
115+
width: 1.4em
116+
height: 1.4em
117+
line-height: 1.4
118+
border-radius: $b-borderRadius
119+
120+
a
121+
width: 1.4em
122+
text-decoration: none
123+
color: black
124+
border-radius: $b-borderRadius
125+
&:hover, &:focus
126+
background-color: $c-primary
127+
color: white
128+
129+
.previous_page, .next_page
130+
width: auto
131+
background-color: $c-primary
132+
border-radius: $b-borderRadius
133+
border: 1px solid transparent
134+
color: $c-text-invert
135+
cursor: pointer
136+
display: inline-block
137+
font-size: $b-fontSize
138+
line-height: 2.5
139+
padding: 0 $b-space
140+
text-align: center
141+
text-decoration: none
142+
transition: $b-transition
143+
white-space: nowrap

app/assets/stylesheets/foundation/_config.sass

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ $b-lineHeight: 1.5
8383

8484
// ----- Settings ----- //
8585
86-
$b-transition: 0.3s ease-in-out
86+
$b-transition: 0.2s ease-in-out
8787

8888
// ----- Sizing ----- //
8989
@@ -92,6 +92,7 @@ $b-maxWidth-s: em(700px)
9292
$b-space: em(20px)
9393
$b-space-xs: $b-space * 0.25
9494
$b-space-s: $b-space * 0.5
95+
$b-space-m: $b-space * 1
9596
$b-space-l: $b-space * 2
9697
$b-space-xl: $b-space * 4
9798

app/assets/stylesheets/foundation/_tools.sass

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
.mbl
1515
margin-bottom: $b-space-l
1616

17+
.mbm
18+
margin-bottom: $b-space-m
19+
1720
// -------------------------------------
1821
// Padding
1922
// -------------------------------------

app/controllers/compliments_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ComplimentsController < ApplicationController
99
def index
1010
@compliments = Compliment.includes(
1111
:complimenter, :complimentee, :uphearts
12-
).public
12+
).public.paginate(page: params[:page], per_page: 30)
1313
end
1414

1515
def given

app/views/compliments/index.html.haml

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.split.mbl
1+
.split.mbm
22
.split-cell
33

44
%ul.list.list--inline.list--inline--l
@@ -11,10 +11,16 @@
1111
= link_to "New Compliment", new_compliment_path, class: "btn"
1212
= link_to "Download My Compliments", received_compliments_path(format: :csv), class: "btn"
1313

14-
- unless @compliments.empty?
14+
- if @compliments.any?
15+
= will_paginate @compliments
16+
1517
.g.collection.collection--1of2
18+
1619
- @compliments.each do |compliment|
1720
.g-b.g-b--1of2.collection-item
1821
= render compliment
22+
23+
24+
= will_paginate @compliments
1925
- else
2026
%p.pal.tac.tcs.tsi There are no compliments currently. Say something nice :)

config/locales/en.yml

+5
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@
2121

2222
en:
2323
hello: "Hello world"
24+
25+
will_paginate:
26+
previous_label: "Previous"
27+
next_label: "Next"
28+
page_gap: "&hellip;"

0 commit comments

Comments
 (0)