Skip to content

Commit 268e5be

Browse files
committed
feat: load more events
1 parent f65e381 commit 268e5be

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

components/modules/tx/TxOverview.vue

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,30 @@ const bookmarkText = computed(() => {
5757
5858
const activeTab = ref("messages")
5959
60-
const showAll = ref(false)
61-
const handleShowAll = () => {
62-
showAll.value = !showAll.value
63-
64-
amp.log("toggleShowAll")
65-
}
66-
6760
const messages = ref([])
6861
62+
const offset = ref(0)
6963
const events = ref([])
70-
const filteredEvents = computed(() => (showAll.value ? events.value : events.value.slice(0, 10)))
7164
72-
const { data: rawEvents } = await fetchTxEvents(props.tx.hash)
73-
events.value = rawEvents.value.sort((a, b) => a.position - b.position)
74-
cacheStore.current.events = events.value
65+
const handleLoadMore = async () => {
66+
if (events.length === props.tx.events_count) return
67+
68+
offset.value += 10
69+
70+
const rawEvents = await fetchTxEvents({ hash: props.tx.hash, offset: offset.value })
71+
events.value = [...events.value, ...rawEvents].sort((a, b) => a.position - b.position)
72+
cacheStore.current.events = events.value
73+
}
7574
7675
onMounted(async () => {
7776
isBookmarked.value = !!bookmarksStore.bookmarks.txs.find((t) => t.id === props.tx.hash)
7877
7978
const data = await fetchTxMessages(props.tx.hash)
8079
messages.value = data
80+
81+
const rawEvents = await fetchTxEvents({ hash: props.tx.hash })
82+
events.value = rawEvents.sort((a, b) => a.position - b.position)
83+
cacheStore.current.events = events.value
8184
})
8285
8386
const handleBookmark = () => {
@@ -324,13 +327,7 @@ const handleViewRawEvent = (event) => {
324327
</Flex>
325328

326329
<Flex v-if="activeTab === 'events'" direction="column" :class="[$style.inner, $style.events]">
327-
<Flex
328-
v-for="(event, idx) in filteredEvents"
329-
@click="handleViewRawEvent(event)"
330-
align="center"
331-
gap="12"
332-
:class="$style.event"
333-
>
330+
<Flex v-for="(event, idx) in events" @click="handleViewRawEvent(event)" align="center" gap="12" :class="$style.event">
334331
<Flex
335332
direction="column"
336333
align="center"
@@ -607,14 +604,14 @@ const handleViewRawEvent = (event) => {
607604
</Text>
608605
</Flex>
609606
</Flex>
607+
608+
<Button @click="handleLoadMore" type="secondary" size="mini" :disabled="tx.events_count == events.length">
609+
Load More
610+
</Button>
610611
</Flex>
611612
<Flex v-if="activeTab === 'messages'" :class="$style.inner">
612613
<MessagesTable :messages="messages" />
613614
</Flex>
614-
615-
<Button v-if="events.length > 10" @click="handleShowAll" type="secondary" size="mini">
616-
{{ !showAll ? "View More" : "Hide" }}
617-
</Button>
618615
</Flex>
619616
</Flex>
620617
</Flex>

services/api/tx.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ export const fetchTxMessages = async (hash) => {
5252
}
5353
}
5454

55-
export const fetchTxEvents = async (hash) => {
55+
export const fetchTxEvents = async ({ hash, offset }) => {
5656
try {
5757
const url = new URL(`${useServerURL()}/tx/${hash}/events`)
5858

59-
const data = await useFetch(url.href)
59+
if (offset) url.searchParams.append("offset", offset)
60+
61+
const data = await $fetch(url.href)
6062
return data
6163
} catch (error) {
6264
console.error(error)

0 commit comments

Comments
 (0)