Skip to content

Commit fdfc40b

Browse files
committed
Added pagination
1 parent b011e40 commit fdfc40b

File tree

2 files changed

+100
-14
lines changed

2 files changed

+100
-14
lines changed

components/Overview/index.vue

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,37 @@
4242
<p>Daily</p>
4343
<ul>
4444
<li
45-
v-for="(item, index) in result.timeline"
45+
v-for="(item, index) in timeline"
4646
:key="index">
4747
<span class="timestamp">{{ item.timestamp.month }} {{ item.timestamp.date }}, {{ item.timestamp.year }}</span>
4848
<span class="summary" v-html="item.summary" />
4949
</li>
5050
</ul>
51+
<div class="pagination">
52+
<button
53+
class="controls prev"
54+
:class="{ 'is-disabled': currentPage <= 1 }"
55+
:disabled="currentPage <= 1"
56+
@click="previous">
57+
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
58+
width="40" height="40"
59+
viewBox="0 0 172 172"
60+
style=" fill:#000000;"><g fill="none" fill-rule="nonzero" stroke="none" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" font-family="none" font-weight="none" font-size="none" text-anchor="none" style="mix-blend-mode: normal"><path d="M0,172v-172h172v172z" fill="none"></path><g fill="#000000"><path d="M86,14.33333c-39.5815,0 -71.66667,32.08517 -71.66667,71.66667c0,39.5815 32.08517,71.66667 71.66667,71.66667c39.5815,0 71.66667,-32.08517 71.66667,-71.66667c0,-39.5815 -32.08517,-71.66667 -71.66667,-71.66667zM78.83333,122.34217l-10.75,-10.75l25.59217,-25.59217l-25.59217,-25.59217l10.75,-10.75l36.34217,36.34217z"></path></g></g>
61+
</svg>
62+
</button>
63+
<span>{{ currentPage }} / {{ totalPage }}</span>
64+
<button
65+
class="controls next"
66+
:class="{ 'is-disabled': currentPage >= totalPage }"
67+
:disabled="currentPage >= totalPage"
68+
@click="next">
69+
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
70+
width="40" height="40"
71+
viewBox="0 0 172 172"
72+
style=" fill:#000000;"><g fill="none" fill-rule="nonzero" stroke="none" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" font-family="none" font-weight="none" font-size="none" text-anchor="none" style="mix-blend-mode: normal"><path d="M0,172v-172h172v172z" fill="none"></path><g fill="#000000"><path d="M86,14.33333c-39.5815,0 -71.66667,32.08517 -71.66667,71.66667c0,39.5815 32.08517,71.66667 71.66667,71.66667c39.5815,0 71.66667,-32.08517 71.66667,-71.66667c0,-39.5815 -32.08517,-71.66667 -71.66667,-71.66667zM78.83333,122.34217l-10.75,-10.75l25.59217,-25.59217l-25.59217,-25.59217l10.75,-10.75l36.34217,36.34217z"></path></g></g>
73+
</svg>
74+
</button>
75+
</div>
5176
</div>
5277
</div>
5378
</div>
@@ -102,12 +127,44 @@ export default {
102127
horizontalAlign: 'left'
103128
}
104129
}
130+
},
131+
getTimeline() {
132+
return this.result.timeline
133+
},
134+
totalDaily() {
135+
return this.result.timeline.length
136+
},
137+
totalPage() {
138+
return this.totalDaily / this.perPage
139+
}
140+
},
141+
data() {
142+
return {
143+
perPage: 6,
144+
currentPage: 1,
145+
timeline: []
105146
}
106147
},
107148
methods: {
108149
onClose() {
109150
this.$emit('close')
151+
},
152+
paginate(a, perPage, page) {
153+
return a.slice(perPage * (page - 1), perPage * page)
154+
},
155+
previous() {
156+
if (this.currentPage >= 1) {
157+
this.timeline = this.paginate(this.getTimeline, this.perPage, --this.currentPage)
158+
}
159+
},
160+
next() {
161+
if (this.currentPage <= this.totalDaily) {
162+
this.timeline = this.paginate(this.getTimeline, this.perPage, ++this.currentPage)
163+
}
110164
}
165+
},
166+
mounted() {
167+
this.timeline = this.paginate(this.getTimeline, this.perPage, 1)
111168
}
112169
}
113170
</script>
@@ -309,6 +366,41 @@ export default {
309366
font-weight: 700;
310367
color: #66a266;
311368
}
369+
370+
.pagination {
371+
text-align: center;
372+
373+
span {
374+
display: inline-block;
375+
margin: 8px 0;
376+
line-height: 40px;
377+
vertical-align: top;
378+
}
379+
}
380+
381+
.controls {
382+
border: 0;
383+
margin: 8px 4px;
384+
padding: 0;
385+
width: 40px;
386+
height: 40px;
387+
display: inline-block;
388+
vertical-align: top;
389+
background: none;
390+
cursor: pointer;
391+
outline: none;
392+
393+
&.is-disabled {
394+
opacity: 0.6;
395+
}
396+
397+
&.prev {
398+
399+
svg {
400+
transform: rotate(-180deg);
401+
}
402+
}
403+
}
312404
}
313405
}
314406
</style>

store/state.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ export default () => ({
33
latest: {},
44
countries: {},
55
result: {
6-
country: '',
7-
province: '',
8-
timelines: {
9-
confirmed: {
10-
timeline: {}
11-
},
12-
deaths: {
13-
timeline: {}
14-
},
15-
recovered: {
16-
timeline: {}
17-
}
18-
}
6+
title: '',
7+
latest: {},
8+
last_updated: '',
9+
series: [],
10+
timeline: [],
11+
mortality_rate: 0,
12+
recovered_rate: 0
1913
}
2014
})

0 commit comments

Comments
 (0)