Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit f53c8bb

Browse files
authored
Merge pull request #1044 from prachi00/feat-random-page
#1036 Taking to random pages in pagination component
2 parents a1979b2 + 4e7263f commit f53c8bb

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

src/components/rmrk/Gallery/Collections.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Loader :value="isLoading" />
44
<!-- TODO: Make it work with graphql -->
55
<b-field class="column">
6-
<Pagination simple :total="total" v-model="currentValue" :perPage="perPage" replace class="is-right" />
6+
<Pagination hasMagicBtn simple :total="total" v-model="currentValue" :perPage="perPage" replace class="is-right" />
77
</b-field>
88

99
<div>

src/components/rmrk/Gallery/Gallery.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- TODO: Make it work with graphql -->
55
<Search v-bind.sync="searchQuery">
66
<b-field class="column">
7-
<Pagination simple :total="total" v-model="currentValue" :perPage=12 replace class="is-right" />
7+
<Pagination hasMagicBtn simple :total="total" v-model="currentValue" :perPage=12 replace class="is-right" />
88
</b-field>
99
</Search>
1010
<!-- <b-button @click="first += 1">Show {{ first }}</b-button> -->

src/components/rmrk/Gallery/Pagination.vue

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<template>
2+
<div class="is-flex is-justify-content-flex-end">
23
<b-pagination
34
:total="total"
45
:current.sync="current"
@@ -15,12 +16,23 @@
1516
@change="onPageChange"
1617
>
1718
</b-pagination>
19+
<b-button
20+
class="ml-2 magicBtn"
21+
title="Go to random page"
22+
v-if="hasMagicBtn"
23+
type="is-primary"
24+
icon-left="magic"
25+
@click="goToRandomPage"
26+
>
27+
</b-button>
28+
</div>
1829
</template>
1930

2031
<script lang="ts" >
2132
import { Component, Prop, Vue } from 'vue-property-decorator'
2233
import { exist } from './Search/exist'
2334
import { Debounce } from 'vue-debounce-decorator'
35+
import { getRandomIntInRange } from '../utils'
2436
2537
@Component({})
2638
export default class Pagination extends Vue {
@@ -30,6 +42,7 @@ export default class Pagination extends Vue {
3042
@Prop({ default: 20 }) public perPage!: number
3143
@Prop(Boolean) replace!: boolean
3244
@Prop(Boolean) preserveScroll!: boolean
45+
@Prop(Boolean) hasMagicBtn!: boolean;
3346
3447
public mounted() {
3548
exist(this.$route.query.page, (val) => {
@@ -50,6 +63,13 @@ export default class Pagination extends Vue {
5063
}
5164
}
5265
66+
public goToRandomPage() {
67+
this.onPageChange()
68+
const pageSize = Math.floor(this.total / this.perPage)
69+
let randomNumber = getRandomIntInRange(1, pageSize)
70+
this.current = randomNumber
71+
}
72+
5373
public scrollTop() {
5474
window.scrollTo({
5575
top: 0,
@@ -66,7 +86,6 @@ export default class Pagination extends Vue {
6686
this.replace && this.replaceUrl(String(value))
6787
}
6888
69-
7089
@Debounce(100)
7190
replaceUrl(value: string, key = 'page') {
7291
this.$router
@@ -78,3 +97,10 @@ export default class Pagination extends Vue {
7897
}
7998
}
8099
</script>
100+
<style lang="scss">
101+
102+
.magicBtn {
103+
border-width: 1px;
104+
}
105+
106+
</style>

src/components/rmrk/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,9 @@ export const isJsonGltf = (value: any): boolean => {
316316
return false
317317
}
318318
}
319+
320+
export const getRandomIntInRange = (min: number, max: number): number => {
321+
min = Math.ceil(min)
322+
max = Math.floor(max)
323+
return Math.floor(Math.random() * (max - min + 1)) + min
324+
}

0 commit comments

Comments
 (0)