-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from openobserve/feature-blogdata
Feature blogdata
- Loading branch information
Showing
17 changed files
with
657 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,102 @@ | ||
<template> | ||
<div class="flex justify-center mt-8"> | ||
<!-- Previous Button --> | ||
<section class="container mx-auto flex justify-center mt-8"> | ||
<!-- Previous Button --> | ||
<button | ||
class="px-4 py-2 mx-2 border border-blue-400 text-blue-400 rounded-lg disabled:opacity-50 hover:bg-blue-50" | ||
:disabled="currentPage === 1" | ||
@click="changePage(currentPage - 1)" | ||
> | ||
Previous | ||
</button> | ||
|
||
<!-- Page Number Buttons --> | ||
<div class="flex items-center"> | ||
<button | ||
class="px-4 py-2 mx-2 border border-blue-400 text-blue-400 rounded-lg disabled:opacity-50" | ||
:disabled="currentPage === 1" | ||
@click="changePage(currentPage - 1)" | ||
v-for="page in displayedPages" | ||
:key="page" | ||
:class="[ | ||
'px-4 py-2 mx-1 rounded-lg', | ||
page === currentPage | ||
? 'bg-blue-400 text-white' | ||
: 'text-gray-500 hover:bg-blue-50' | ||
]" | ||
@click="changePage(page)" | ||
> | ||
Previous | ||
</button> | ||
|
||
<!-- Page Number Buttons --> | ||
<div class="flex items-center"> | ||
<button | ||
v-for="page in pages" | ||
:key="page" | ||
:class="['px-4 py-2 mx-1', { 'text-blue-400': page === currentPage, 'text-gray-500': page !== currentPage }]" | ||
@click="changePage(page)" | ||
> | ||
{{ page }} | ||
</button> | ||
</div> | ||
|
||
<!-- Next Button --> | ||
<button | ||
class="px-4 py-2 mx-2 border border-blue-400 text-blue-400 rounded-lg disabled:opacity-50" | ||
:disabled="currentPage === totalPages" | ||
@click="changePage(currentPage + 1)" | ||
> | ||
Next | ||
{{ page }} | ||
</button> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, computed } from "vue"; | ||
|
||
<!-- Next Button --> | ||
<button | ||
class="px-4 py-2 mx-2 border border-blue-400 text-blue-400 rounded-lg disabled:opacity-50 hover:bg-blue-50" | ||
:disabled="currentPage === totalPages" | ||
@click="changePage(currentPage + 1)" | ||
> | ||
Next | ||
</button> | ||
</section> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, computed, onMounted } from "vue"; | ||
const props = defineProps({ | ||
totalItems: { | ||
type: Number, | ||
required: true, | ||
}, | ||
itemsPerPage: { | ||
type: Number, | ||
required: true, | ||
}, | ||
currentPage: { | ||
type: Number, | ||
required: true, | ||
default: 1, | ||
}, | ||
}); | ||
const emit = defineEmits(["page-changed"]); | ||
const currentPageRef = ref(props.currentPage); | ||
const totalPages = computed(() => Math.ceil(props.totalItems / props.itemsPerPage)); | ||
// Compute the pages to display (show 5 pages at a time) | ||
const displayedPages = computed(() => { | ||
const pages = []; | ||
let start = Math.max(1, currentPageRef.value - 2); | ||
let end = Math.min(totalPages.value, start + 4); | ||
// Pagination state | ||
const props = defineProps({ | ||
totalItems: { | ||
type: Number, | ||
required: true, | ||
}, | ||
itemsPerPage: { | ||
type: Number, | ||
required: true, | ||
}, | ||
}); | ||
const emit = defineEmits(["page-changed"]); | ||
const currentPage = ref(1); | ||
const totalPages = ref(Math.ceil(props.totalItems / props.itemsPerPage)); | ||
// Computed property to generate page numbers | ||
const pages = computed(() => { | ||
const pageNumbers = []; | ||
for (let i = 1; i <= totalPages.value; i++) { | ||
pageNumbers.push(i); | ||
} | ||
return pageNumbers; | ||
}); | ||
// Change page function | ||
const changePage = (newPage) => { | ||
if (newPage >= 1 && newPage <= totalPages.value) { | ||
currentPage.value = newPage; | ||
emit("page-changed", currentPage.value); | ||
} | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
button { | ||
transition: background-color 0.2s ease; | ||
// Adjust start if we're near the end | ||
if (end === totalPages.value) { | ||
start = Math.max(1, end - 4); | ||
} | ||
for (let i = start; i <= end; i++) { | ||
pages.push(i); | ||
} | ||
button:hover { | ||
background-color: #1e40af; | ||
return pages; | ||
}); | ||
// Change page function | ||
const changePage = async (newPage) => { | ||
if (newPage >= 1 && newPage <= totalPages.value) { | ||
currentPageRef.value = newPage; | ||
// Update URL | ||
const newUrl = newPage === 1 | ||
? '/blog' | ||
: `/blog/page/${newPage}`; | ||
console.log('newUrl', newUrl) | ||
window.location.assign(newUrl); | ||
// Emit event for parent component | ||
emit("page-changed", newPage); | ||
window.scrollTo({ top: 0, behavior: 'smooth' }); | ||
} | ||
</style> | ||
|
||
}; | ||
// Update local state when prop changes | ||
onMounted(() => { | ||
currentPageRef.value = props.currentPage; | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.