Skip to content

Commit

Permalink
feat(Posts Controls): add "minimumPage" prop and logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Apr 12, 2022
1 parent 165b554 commit d4f3a00
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
27 changes: 22 additions & 5 deletions components/pages/posts/navigation/page/PostsControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class="link"
title="Load specific page"
type="button"
@click="getSpecificPage"
@click="setSpecificPage"
>
{{ currentPage }}
</button>
Expand Down Expand Up @@ -92,6 +92,11 @@ export default {
required: true,
},
minimumPage: {
type: Number,
required: true,
},
forceNormalControls: {
type: Boolean,
default: false,
Expand All @@ -104,14 +109,14 @@ export default {
methods: {
getNextPage() {
this.$emit('setPage', this.currentPage + 1)
this.setPage(this.currentPage + 1)
},
getPrevPage() {
this.$emit('setPage', this.currentPage - 1)
this.setPage(this.currentPage - 1)
},
getSpecificPage() {
setSpecificPage() {
const specificPage = Number.parseInt(
prompt('What page do you want to go to?'),
10
Expand All @@ -122,7 +127,19 @@ export default {
return
}
this.$emit('setPage', specificPage)
this.setPage(specificPage)
},
isBelowMinimumPage(page) {
return page < this.minimumPage
},
setPage(page) {
if (this.isBelowMinimumPage(page)) {
return
}
this.$emit('setPage', page)
},
InfiniteLoadHandler(entries, observer) {
Expand Down
15 changes: 10 additions & 5 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class="flex flex-col max-w-3xl min-h-screen px-4 mx-auto sm:px-6 lg:px-8"
>
<portal to="side-nav-area">
<SearchToggler :tag-count="getTags.length"/>
<SearchToggler :tag-count="getTags.length" />
</portal>

<portal to="search">
Expand All @@ -26,18 +26,18 @@
@domainChange="onDomainChange"
/>

<Notifications/>
<Notifications />
</nav>

<!-- Content -->
<main class="flex flex-col flex-auto min-h-full pb-4 space-y-4">

<ErrorManager/>
<ErrorManager />

<ul class="flex-auto space-y-4">
<template v-if="getPosts.length">
<li v-for="POST in getPosts" :key="POST.id">
<Post :post="POST"/>
<Post :post="POST" />
</li>
</template>

Expand All @@ -48,7 +48,11 @@
</template>
</ul>

<PostsControls :current-page="getPageID" @setPage="onPageChange"/>
<PostsControls
:current-page="getPageID"
:minimum-page="getActiveBooruType.initialPageID"
@setPage="onPageChange"
/>
</main>
</div>
</template>
Expand Down Expand Up @@ -100,6 +104,7 @@ export default {
computed: {
...mapGetters('booru', [
'getActiveBooru',
'getActiveBooruType',
'getDefaultBooruList',
'getPremiumBooruList',
'getPosts',
Expand Down
5 changes: 3 additions & 2 deletions pages/premium/saved-posts.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<main class="flex flex-col max-w-3xl min-h-screen p-4 mx-auto sm:p-6 lg:p-8">
<portal to="side-nav-area">
<SearchToggler :tag-count="searchActiveTags.length"/>
<SearchToggler :tag-count="searchActiveTags.length" />
</portal>

<portal to="search">
Expand All @@ -16,7 +16,7 @@
</SearchWrapper>
</portal>

<ContentSeparator title="Saved posts"/>
<ContentSeparator title="Saved posts" />

<nav class="flex flex-row items-center justify-between py-4">
<DomainSelector
Expand Down Expand Up @@ -47,6 +47,7 @@
<PostsControls
:current-page="currentPage"
:force-normal-controls="true"
:minimum-page="0"
@setPage="onPageChange"
/>
</main>
Expand Down

0 comments on commit d4f3a00

Please sign in to comment.