Skip to content

Commit ca47fc7

Browse files
committed
fix(list): adds loaded indicator and fix load more
1 parent 230d1dc commit ca47fc7

File tree

4 files changed

+103
-39
lines changed

4 files changed

+103
-39
lines changed

src/components/common/list/ListEmpty.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ const emit = defineEmits<{
4848

4949
<style scoped lang="scss">
5050
.empty {
51-
margin-top: 0.5rem;
51+
display: flex;
52+
justify-content: center;
53+
margin-bottom: 1rem;
5254
color: var(--n-text-color);
5355
transition: color 0.3s var(--n-bezier);
5456

src/components/common/list/ListLoadMore.vue

+60-23
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
<script setup lang="ts">
22
import { NButton } from 'naive-ui';
33
4+
import { computed, toRefs } from 'vue';
5+
46
import { useI18n } from '~/utils/i18n.utils';
57
68
const i18n = useI18n('list', 'more');
79
8-
defineProps({
10+
const props = defineProps({
11+
search: {
12+
type: String,
13+
required: false,
14+
},
15+
items: {
16+
type: Number,
17+
required: false,
18+
default: 0,
19+
},
20+
itemCount: {
21+
type: Number,
22+
required: false,
23+
default: 0,
24+
},
925
page: {
1026
type: Number,
1127
required: false,
@@ -29,37 +45,58 @@ const emit = defineEmits<{
2945
pagination: { page: number; pageCount: number; pageSize: number },
3046
): void;
3147
}>();
48+
49+
const { page, pageCount } = toRefs(props);
50+
51+
const showButton = computed(() => page.value < pageCount.value);
3252
</script>
3353

3454
<template>
35-
<template v-if="page && pageCount">
36-
<div class="row">
37-
{{ i18n('pages_line_1') }} <span class="page"> {{ page }} </span>
38-
{{ i18n('pages_line_2') }} <span class="page"> {{ pageCount }} </span>
39-
{{ i18n('pages_line_3') }}
40-
</div>
41-
<div class="row">
42-
{{ i18n('current_page_size') }} <span class="page"> {{ pageSize }} </span>.
43-
</div>
44-
<template v-if="page < pageCount">
45-
<NButton
46-
class="button"
47-
tertiary
48-
round
49-
type="primary"
50-
@click="emit('onLoadMore', { page, pageCount, pageSize })"
51-
>
52-
Load more Pages
53-
</NButton>
54-
</template>
55-
</template>
55+
<div v-if="items && itemCount" class="row items" :class="{ offset: !showButton }">
56+
<span class="page"> {{ items }} </span> {{ i18n('out_of') }}
57+
<span class="page"> {{ itemCount }} </span>
58+
{{ i18n('pages') }}
59+
</div>
60+
<div class="row">
61+
<span class="page"> {{ page }} </span> {{ i18n('out_of') }}
62+
<span class="page"> {{ pageCount }} </span>
63+
{{ i18n('items') }}
64+
</div>
65+
<div class="row">
66+
{{ i18n('page_size') }} <span class="page"> {{ pageSize }} </span>
67+
</div>
68+
<Transition name="fade">
69+
<NButton
70+
v-if="showButton"
71+
class="button"
72+
tertiary
73+
round
74+
type="primary"
75+
@click="emit('onLoadMore', { page, pageCount, pageSize })"
76+
>
77+
{{ i18n('load_more') }}
78+
</NButton>
79+
</Transition>
5680
</template>
5781

5882
<style scoped lang="scss">
83+
@use '~/styles/transition' as transition;
84+
@include transition.fade;
85+
5986
.row {
6087
margin-top: 0.5rem;
6188
color: var(--n-text-color);
62-
transition: color 0.3s var(--n-bezier);
89+
transition:
90+
color 0.3s var(--n-bezier),
91+
margin 0.3s var(--n-bezier);
92+
93+
&:first-child {
94+
margin-top: 1.5rem;
95+
96+
&.offset {
97+
margin-top: 2rem;
98+
}
99+
}
63100
64101
.page {
65102
color: var(--color-primary-disabled);

src/components/common/list/ListScroll.vue

+23-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ const listPaddingBottom = computed(() => listOptions?.value?.paddingBottom ?? 8)
232232
<slot v-if="item.type === ListScrollItemType.LoadMore" name="load-more">
233233
<NFlex
234234
class="load-more"
235-
justify="center"
235+
justify="flex-start"
236236
align="center"
237237
vertical
238238
size="small"
@@ -242,11 +242,32 @@ const listPaddingBottom = computed(() => listOptions?.value?.paddingBottom ?? 8)
242242
<ListLoadMore
243243
:page="pagination?.page"
244244
:page-count="pagination?.pageCount"
245+
:items="items.length > 1 ? items.length - 1 : 0"
246+
:item-count="pagination?.itemCount"
245247
:page-size="pageSize"
246248
@on-load-more="onLoadMore"
247249
/>
248250
</NFlex>
249251
</slot>
252+
<slot v-else-if="item.type === ListScrollItemType.AllLoaded" name="empty">
253+
<NFlex
254+
class="all-loaded"
255+
justify="flex-start"
256+
align="center"
257+
vertical
258+
size="small"
259+
:theme-overrides="{ gapSmall: '0' }"
260+
:style="`height: ${listOptions?.itemSize ?? defaultSize}px;`"
261+
>
262+
<ListLoadMore
263+
:page="pagination?.page"
264+
:page-count="pagination?.pageCount"
265+
:items="items.length > 1 ? items.length - 1 : 0"
266+
:item-count="pagination?.itemCount"
267+
:page-size="pageSize"
268+
/>
269+
</NFlex>
270+
</slot>
250271
<ListItem
251272
v-else
252273
:key="item.id"
@@ -294,8 +315,8 @@ const listPaddingBottom = computed(() => listOptions?.value?.paddingBottom ?? 8)
294315
height: var(--full-height);
295316
margin-top: calc(0% - #{layout.$safe-navbar-height});
296317
318+
.all-loaded,
297319
.load-more {
298-
margin-top: 1rem;
299320
opacity: 0;
300321
animation: fade-in 0.5s forwards;
301322
animation-delay: 0.25s;

src/i18n/en/list/list.json

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
{
22
"list__empty__no_data": {
3-
"message": "No data found.",
3+
"message": "No data found",
44
"description": "Empty message when there is no data to display in the list."
55
},
6-
"list__more__pages_line_1": {
7-
"message": "Searched",
8-
"description": "First line of the list empty pagination message."
9-
},
10-
"list__more__pages_line_2": {
6+
"list__more__out_of": {
117
"message": "out of",
12-
"description": "Second line of the list empty pagination message."
8+
"description": "Second line of the list load more pagination message."
9+
},
10+
"list__more__pages": {
11+
"message": "pages",
12+
"description": "Third line of the list load more pagination message."
13+
},
14+
"list__more__items": {
15+
"message": "items",
16+
"description": "Third line of the list load more pagination message."
1317
},
14-
"list__more__pages_line_3": {
15-
"message": "pages.",
16-
"description": "Third line of the list empty pagination message."
18+
"list__more__page_size": {
19+
"message": "page size",
20+
"description": "page size label."
1721
},
18-
"list__more__current_page_size": {
19-
"message": "Current page size is",
20-
"description": "Current page size label."
22+
"list__more__load_more": {
23+
"message": "Load more Pages",
24+
"description": "Load more Pages."
2125
},
2226
"list__item__placeholder_empty": {
2327
"message": "Nothing on this day.",

0 commit comments

Comments
 (0)