Skip to content

Commit 48990a0

Browse files
committed
Sort addresses by balance
1 parent 8d468f0 commit 48990a0

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

pages/addresses.vue

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,19 @@ await getAddressesCount()
7575
const page = ref(route.query.page ? parseInt(route.query.page) : 1)
7676
const pages = computed(() => Math.ceil(count.value / 20))
7777
78+
const sort = reactive({
79+
by: "spendable",
80+
dir: "desc",
81+
})
82+
7883
const getAddresses = async () => {
7984
isRefetching.value = true
8085
8186
const { data } = await fetchAddresses({
8287
limit: 20,
8388
offset: (page.value - 1) * 20,
84-
sort: "desc",
89+
sort: sort.dir,
90+
sort_by: sort.by,
8591
})
8692
addresses.value = data.value
8793
@@ -104,6 +110,23 @@ watch(
104110
},
105111
)
106112
113+
const handleSort = (by) => {
114+
switch (sort.dir) {
115+
case "desc":
116+
if (sort.by == by) sort.dir = "asc"
117+
break
118+
119+
case "asc":
120+
sort.dir = "desc"
121+
122+
break
123+
}
124+
125+
sort.by = by
126+
127+
getAddresses()
128+
}
129+
107130
const handlePrev = () => {
108131
if (page.value === 1) return
109132
@@ -167,7 +190,18 @@ const handleLast = async () => {
167190
<thead>
168191
<tr>
169192
<th><Text size="12" weight="600" color="tertiary" noWrap>Hash</Text></th>
170-
<th><Text size="12" weight="600" color="tertiary" noWrap>Balance</Text></th>
193+
<th @click="handleSort('spendable')" :class="$style.sortable">
194+
<Flex align="center" gap="6">
195+
<Text size="12" weight="600" color="tertiary" noWrap>Balance</Text>
196+
<Icon
197+
v-if="sort.by === 'spendable'"
198+
name="chevron"
199+
size="12"
200+
color="secondary"
201+
:style="{ transform: `rotate(${sort.dir === 'asc' ? '180' : '0'}deg)` }"
202+
/>
203+
</Flex>
204+
</th>
171205
<th><Text size="12" weight="600" color="tertiary" noWrap>First Height</Text></th>
172206
<th><Text size="12" weight="600" color="tertiary" noWrap>Last Height</Text></th>
173207
</tr>

services/api/address.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/** Services */
22
import { useServerURL } from "@/services/config"
33

4-
export const fetchAddresses = async ({ limit, offset, sort }) => {
4+
export const fetchAddresses = async ({ limit, offset, sort, sort_by }) => {
55
try {
66
const url = new URL(`${useServerURL()}/address`)
77

88
if (limit) url.searchParams.append("limit", limit)
99
if (offset) url.searchParams.append("offset", offset)
1010
if (sort) url.searchParams.append("sort", sort)
11+
if (sort_by) url.searchParams.append("sort_by", sort_by)
1112

1213
const data = await useFetch(url.href)
1314
return data

0 commit comments

Comments
 (0)