Skip to content

Commit

Permalink
Merge pull request #41 from rkshaon/rkshaon
Browse files Browse the repository at this point in the history
frontend
  • Loading branch information
rkshaon authored Sep 13, 2024
2 parents be41e91 + 8e68f3e commit 5f93640
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 0 additions & 2 deletions frontend/src/components/PaginationComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
Previous
</button>
</div>

<!-- Spacer to balance layout -->
<div class="flex-1"></div>

<!-- Next button -->
<div v-if="nextPage" class="flex-1 text-right">
<button @click="changePage(nextPage)" class="bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600">
Expand Down
24 changes: 13 additions & 11 deletions frontend/src/pages/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@
Explore a vast collection of books, share your reviews, and connect with other book lovers.
</p>
</div>

<!-- PaginationComponent for navigation -->
<PaginationComponent :previousPage="previousPageUrl" :nextPage="nextPageUrl" :pageSize="pageSize"
@fetch-page="changePage" />

<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
<BookCardComponent v-for="(book, index) in books" :key="index" :book="book" />
</div>

<!-- PaginationComponent at the bottom -->
<PaginationComponent :previousPage="previousPageUrl" :nextPage="nextPageUrl" :pageSize="pageSize"
@fetch-page="changePage" />
</main>
Expand Down Expand Up @@ -45,23 +40,30 @@ export default {
'$route.query.page': {
immediate: true,
handler (newPage) {
const page = newPage || 1
let page = parseInt(newPage, 10)
if (!page || isNaN(page)) {
this.$router.replace({ query: { page: 1 } })
page = 1
return
}
this.fetchBooks({ page, pageSize: this.pageSize })
}
}
},
mounted () {
// this.fetchBooks()
const currentPage = this.$route.query.page || 1
if (!this.$route.query.page) {
this.fetchBooks({ page: currentPage, pageSize: this.pageSize })
const currentPage = this.$route.query.page
if (!currentPage || isNaN(currentPage)) {
this.$router.replace({ query: { page: 1 } })
}
},
methods: {
...mapActions(['fetchBooks']),
changePage (page) {
this.$router.push({ query: { page } })
// this.fetchBooks({ page, pageSize: this.pageSize })
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/services/v1/bookAPIService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ export default {
async fetchV1Books (page = 1, pageSize = 8) {
page = page ?? 1
pageSize = pageSize ?? 8
console.log(page, pageSize)

const URL = `${API_BASE_URL}/book/v1/?page_size=${pageSize}&page=${page}`
console.log('Book API:', URL, page, pageSize)

try {
const response = await axios.get(URL)
Expand Down

0 comments on commit 5f93640

Please sign in to comment.