Merge pull request #108 from bob2402/purchases-list-very-long

problem: the list of purchases is sometimes very long
This commit is contained in:
gsovereignty
2024-08-19 19:27:40 +08:00
committed by GitHub

View File

@@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
import { Button } from '@/components/ui/button';
import * as Table from '@/components/ui/table'; import * as Table from '@/components/ui/table';
import { Product, Rocket, ValidateZapPublisher, ZapPurchase } from '@/event_helpers/rockets'; import { Product, Rocket, ValidateZapPublisher, ZapPurchase } from '@/event_helpers/rockets';
import { unixToRelativeTime } from '@/helpers'; import { unixToRelativeTime } from '@/helpers';
@@ -81,6 +82,8 @@
}); });
}); });
let truncate = writable(true);
let validatedZapsNotInRocket = derived( let validatedZapsNotInRocket = derived(
[zapsNotInRocket, validPubkeys], [zapsNotInRocket, validPubkeys],
([$zapsNotInRocket, $validPubkeys]) => { ([$zapsNotInRocket, $validPubkeys]) => {
@@ -94,6 +97,17 @@
} }
); );
let validatedZapsNotInRocketTruncated = derived(
[validatedZapsNotInRocket, truncate],
([$validatedZapsNotInRocket, $truncate]) => {
let validatedZapsNotInRocketArray = Array.from($validatedZapsNotInRocket);
if (validatedZapsNotInRocketArray.length > 6 && $truncate) {
validatedZapsNotInRocketArray.length = 6;
}
return validatedZapsNotInRocketArray;
}
);
validatedZapsNotInRocket.subscribe((zaps) => { validatedZapsNotInRocket.subscribe((zaps) => {
for (let [_, z] of zaps) { for (let [_, z] of zaps) {
unratifiedZaps.set(z.ZapReceipt.id, z); unratifiedZaps.set(z.ZapReceipt.id, z);
@@ -119,7 +133,7 @@
</Table.Row> </Table.Row>
</Table.Header> </Table.Header>
<Table.Body> <Table.Body>
{#each $validatedZapsNotInRocket as [id, purchase], _ (id)} {#each $validatedZapsNotInRocketTruncated as [id, purchase], _ (id)}
<Table.Row <Table.Row
on:click={() => { on:click={() => {
console.log(purchase.ZapReceipt.rawEvent()); console.log(purchase.ZapReceipt.rawEvent());
@@ -146,5 +160,14 @@
> >
</Table.Row> </Table.Row>
{/each} {/each}
{#if $validatedZapsNotInRocket.size > $validatedZapsNotInRocketTruncated.length}
<Button
class="mt-2 rounded-full"
on:click={() => {
truncate.set(false);
}}
>View {$validatedZapsNotInRocket.size - $validatedZapsNotInRocketTruncated.length} more</Button
>
{/if}
</Table.Body> </Table.Body>
</Table.Root> </Table.Root>