Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Loading for tables #419

Merged
merged 8 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@

<the-header/>
<NuxtLayout>
<NuxtLoadingIndicator
:duration="3000"
:throttle="300"
:color="false"/>
<NuxtPage/>
</NuxtLayout>
<the-footer class="app__footer"/>
Expand All @@ -80,7 +76,7 @@ import TheHeader from '@/components/TheHeader'
import TheFooter from '@/components/TheFooter'
import { initializeStores } from '@/stores'
import { useWebSocket } from '@/stores/webSocket'
import { APP_CREATOR, APP_DESCRIPTION, APP_TITLE, APP_URL, APP_KEYWORDS } from '@/utils/constants'
import { APP_CREATOR, APP_DESCRIPTION, APP_KEYWORDS, APP_TITLE, APP_URL } from '@/utils/constants'

await useAsyncData(() => initializeStores())

Expand Down
71 changes: 71 additions & 0 deletions src/assets/loader.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions src/components/AccountNamesPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ const accountStore = useAccountStore()
const { fetchAccountNames } = accountStore
const { accountNames } = storeToRefs(accountStore)

function loadPrevAccountNames() {
fetchAccountNames({ queryParameters: accountNames.value.prev })
async function loadPrevAccountNames() {
await fetchAccountNames({ queryParameters: accountNames.value.prev })
}
function loadNextAccountNames() {
fetchAccountNames({ queryParameters: accountNames.value.next })

async function loadNextAccountNames() {
await fetchAccountNames({ queryParameters: accountNames.value.next })
}
</script>

Expand Down
4 changes: 1 addition & 3 deletions src/components/ContractCallTransactionsPanel.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<template>
<app-panel
v-if="contractCallTransactions"
class="contract-call-transactions-panel">
<app-panel class="contract-call-transactions-panel">
<paginated-content
v-model:page-index="pageIndex"
:total-count="contractCallsCount"
Expand Down
4 changes: 1 addition & 3 deletions src/components/ContractsPanel.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<template>
<app-panel
v-if="contracts"
class="contracts-panel">
<app-panel class="contracts-panel">
<paginated-content
v-model:page-index="pageIndex"
:entities="contracts"
Expand Down
4 changes: 1 addition & 3 deletions src/components/KeyblockMicroblocksPanel.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<template>
<app-panel
v-if="microblocks"
class="keyblock-microblock-panel">
<app-panel class="keyblock-microblock-panel">
<paginated-content
v-model:page-index="pageIndex"
pagination-style="history"
Expand Down
4 changes: 1 addition & 3 deletions src/components/MicroblockTransactionsPanel.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<template>
<app-panel
v-if="transactions"
class="microblock-transactions-panel">
<app-panel class="microblock-transactions-panel">
<paginated-content
v-model:page-index="pageIndex"
:entities="transactions"
Expand Down
13 changes: 5 additions & 8 deletions src/components/OraclesPanel.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<template>
<app-panel class="oracles-panel">
<paginated-content
v-if="oracles"
:entities="oracles"
:limit="limit"
@prev-clicked="loadPrevOracles"
@next-clicked="loadNextOracles">
<oracles-table
v-if="oracles"
class="oracles-panel__oracles-table"
:oracles="oracles"/>
<oracles-table-condensed
v-if="oracles"
class="oracles-panel__oracles-table-condensed"
:oracles="oracles"/>
</paginated-content>
Expand All @@ -31,14 +28,14 @@ const oraclesStore = useOraclesStore()
const { fetchOracles } = oraclesStore
const { oracles } = storeToRefs(oraclesStore)

const limit = computed(() => isDesktop() ? 10 : 3)
const limit = computed(() => process.client && isDesktop() ? 10 : 3)

async function loadPrevOracles() {
await fetchOracles({ queryParameters: oracles.value.prev })
function loadPrevOracles() {
fetchOracles({ queryParameters: oracles.value.prev })
}

async function loadNextOracles() {
await fetchOracles({ queryParameters: oracles.value.next })
function loadNextOracles() {
fetchOracles({ queryParameters: oracles.value.next })
}

if (process.client) {
Expand Down
123 changes: 81 additions & 42 deletions src/components/PaginatedContent.vue
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
<template>
<div
v-if="entities"
ref="paginatedContent"
class="paginated-content">
<header class="paginated-content__header">
<div class="paginated-content__counter">
<span v-if="hasCounter">
<template v-if="totalCount > 0">
Displaying
<span class="paginated-content__highlighted">
{{ formatNullable(firstVisibleIndex) }}-{{ formatNullable(lastVisibleIndex) }}
of
{{ formatNullable(totalCount) }}
</span>
records
</template>
<template v-else>
Displaying
<span class="paginated-content__highlighted">0</span>
records
</template>
</span>
</div>
<slot name="header"/>
</header>
<slot v-if="!!entities?.data.length"/>
<blank-state
v-else
class="paginated-content__blank-state"/>

<app-pagination
v-if="hasPagination"
:is-prev-disabled="isPrevDisabled"
:is-next-disabled="isNextDisabled"
:prev-label="prevLabel"
:next-label="nextLabel"
@prev-clicked="handlePrevClicked"
@next-clicked="handleNextClicked"/>
<div
v-if="entities"
class="paginated-content__container">
<header class="paginated-content__header">
<div class="paginated-content__counter">
<span v-if="hasCounter">
<template v-if="totalCount > 0">
Displaying
<span class="paginated-content__highlighted">
{{ formatNullable(firstVisibleIndex) }}-{{ formatNullable(lastVisibleIndex) }}
of
{{ formatNullable(totalCount) }}
</span>
records
</template>
<template v-else>
Displaying
<span class="paginated-content__highlighted">0</span>
records
</template>
</span>
</div>
<slot name="header"/>
</header>
<slot v-if="!!entities?.data.length"/>
<blank-state
v-else
class="paginated-content__blank-state"/>

<app-pagination
v-if="hasPagination"
:is-prev-disabled="isPrevDisabled"
:is-next-disabled="isNextDisabled"
:prev-label="prevLabel"
:next-label="nextLabel"
@prev-clicked="handlePrevClicked"
@next-clicked="handleNextClicked"/>
</div>
<div v-else>
<spinner-loader class="paginated-content__spinner-loader"/>
</div>
</div>
</template>

Expand Down Expand Up @@ -72,15 +78,13 @@ const props = defineProps({
},
},
})

const emit = defineEmits([
'prev-clicked',
'next-clicked',
'update:pageIndex',
])

const pageIndex = props.pageIndex ? useVModel(props, 'pageIndex', emit) : ref(1)

const firstVisibleIndex = computed(
() => (pageIndex.value - 1) * props.limit + 1,
)
Expand Down Expand Up @@ -109,26 +113,53 @@ const nextLabel = computed(() => {
})

const handlePrevClicked = () => {
setFixedContainerHeight()
pageIndex.value--
emit('prev-clicked')
scrollToPaginatedContent()
}

const handleNextClicked = () => {
setFixedContainerHeight()
pageIndex.value++
emit('next-clicked')
scrollToPaginatedContent()
}

const paginatedContent = ref()
watch(
Copy link
Contributor

@lukeromanowicz lukeromanowicz Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make a dedicated composable e.g. useTableLoadingIndicator for that because this will be reused in most of the pages containing tables

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now when I fixed the resetting it's not an issue anymore.
The pagination for tables is only handled by PaginatedContent component, right?
If I missed your point, please give me some examples of which other table would you reuse it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misinterpreted the code. Please ignore it

() => props.entities,
() => {
if (props.entities) {
// reset container height after new data is loaded
resetContainerHeight()
}
},
)

function setFixedContainerHeight() {
paginatedContent.value.style.height = `${paginatedContent.value.clientHeight}px`
}

function scrollToPaginatedContent() {
paginatedContent.value.scrollIntoView()
function resetContainerHeight() {
paginatedContent.value.style.height = ''
}

const paginatedContent = ref()

onMounted(() => {
window.addEventListener('resize', resetContainerHeight())
})

onBeforeUnmount(() => {
window.removeEventListener('resize', resetContainerHeight())
})

</script>

<style scoped>
.paginated-content {
display: flex;
justify-content: center;
align-items: center;

&__header {
display: flex;
align-items: center;
Expand All @@ -145,6 +176,10 @@ function scrollToPaginatedContent() {
}
}

&__container {
width: 100%;
}

&__counter {
margin-bottom: var(--space-3);
font-family: var(--font-monospaced);
Expand All @@ -162,5 +197,9 @@ function scrollToPaginatedContent() {
&__blank-state {
margin-top: var(--space-3);
}

&__spinner-loader {
margin: var(--space-3) 0;
}
}
</style>
24 changes: 24 additions & 0 deletions src/components/SpinnerLoader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<div class="spinner-loader">
<img
class="spinner-loader__image"
alt="loading"
src="@/assets/loader.svg"
height="47">
<div>Loading</div>
</div>
</template>

<style scoped>

.spinner-loader {
display: flex;
flex-direction: column;
align-items: center;
font-family: var(--font-monospaced);

&__image {
margin-bottom: var(--space-2);
}
}
</style>
Loading