-
Notifications
You must be signed in to change notification settings - Fork 3
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
Account activity loading enhancement #334
Draft
deansallinen
wants to merge
8
commits into
dev
Choose a base branch
from
account-activity-loading
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
104962c
dev: update interval in env
deansallinen 4e8d358
wip
deansallinen 7ff3258
fix: element reactivity
deansallinen 50476cd
enhancement: prefetch paginated account activity
deansallinen a51af5c
style: update table header
deansallinen a72cbe7
fix: cache logic
deansallinen a3ba7c5
fix: swr length
deansallinen e64cca2
revert: swl logic
deansallinen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 35 additions & 131 deletions
166
src/routes/[network]/(explorer)/account/[name]/activity/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,142 +1,46 @@ | ||
<script lang="ts"> | ||
import Stack from '$lib/components/layout/stack.svelte'; | ||
import { onMount } from 'svelte'; | ||
import { ActivityLoader } from './state.svelte.js'; | ||
import type { ActivityActionWrapper } from '$lib/types.js'; | ||
import Code from '$lib/components/code.svelte'; | ||
import Transaction from '$lib/components/elements/transaction.svelte'; | ||
import Button from '$lib/components/button/button.svelte'; | ||
import Contract from '$lib/components/elements/contract.svelte'; | ||
import * as m from '$lib/paraglide/messages'; | ||
|
||
const { data } = $props(); | ||
|
||
const networkName = String(data.network); | ||
|
||
onMount(() => { | ||
const loader = ActivityLoader.getInst(networkName); | ||
loader.setAccount(String(data.name)); | ||
loader.load(); | ||
}); | ||
|
||
const activityLoader: ActivityLoader = $derived.by(() => { | ||
return ActivityLoader.getInst(networkName); | ||
}); | ||
|
||
const isLoading = $derived.by(() => { | ||
const scence = activityLoader.scene; | ||
return scence.isLoading && !scence.list.length; | ||
}); | ||
|
||
const hasMore = $derived(activityLoader.scene.hasMore); | ||
const loadingText = $derived.by(() => { | ||
const scence = activityLoader.scene; | ||
if (!scence.hasMore) return 'No more'; | ||
if (scence.isLoading) return 'Loading'; | ||
return 'Load more'; | ||
}); | ||
|
||
const activityActions: ActivityActionWrapper[] = $derived.by(() => { | ||
const scence = activityLoader.scene; | ||
return [...scence.list]; | ||
}); | ||
|
||
function clickLoadMore() { | ||
activityLoader.laodMore(); | ||
} | ||
</script> | ||
|
||
<Stack class="pb-8"> | ||
{#if isLoading} | ||
<div class="flex items-center justify-center gap-4 py-20"> | ||
<div class="bounce bounce-1 h-3 w-3 rounded-full bg-white"></div> | ||
<div class="bounce bounce-2 h-3 w-3 rounded-full bg-white"></div> | ||
<div class="bounce bounce-3 h-3 w-3 rounded-full bg-white"></div> | ||
<svelte:head> | ||
<link | ||
rel="prefetch" | ||
href={`/${data.network}/api/account/${data.account}/activity/${-data.json.activity.last}`} | ||
/> | ||
</svelte:head> | ||
|
||
{#if data.json.activity.actions.length} | ||
<div class="grid gap-6 md:grid-cols-[auto_auto_auto_1fr]"> | ||
<div | ||
class="col-span-full grid grid-cols-subgrid gap-2 border-b border-mineShaft-900 pb-4 *:text-mineShaft-50 md:gap-4" | ||
> | ||
<p>ID</p> | ||
<p>Time</p> | ||
<p>Action</p> | ||
<p>Info</p> | ||
</div> | ||
{/if} | ||
{#if activityActions.length} | ||
<div> | ||
<div class="hidden border-b border-mineShaft-900 lg:flex lg:flex-row"> | ||
<div class="grow-0 basis-[12%] px-2 py-3">ID</div> | ||
<div class="grow-0 basis-[20%] px-2 py-3">Time</div> | ||
<div class="grow-0 basis-[23%] px-2 py-3">Action</div> | ||
<div class="grow-0 basis-[45%] px-2 py-3">Info</div> | ||
</div> | ||
|
||
{#each activityActions as activityAction} | ||
<div | ||
class="text-muted box-border flex flex-col break-words border-b border-mineShaft-900 py-4 lg:flex-row" | ||
> | ||
<div class="flex flex-1 gap-2 px-2 py-1 lg:max-w-[12%] lg:grow-0 lg:basis-[11%] lg:py-3"> | ||
<div class="block lg:hidden"> | ||
<span class="text-white">ID:</span> | ||
</div> | ||
<Transaction id={activityAction.id} /> | ||
</div> | ||
<div | ||
class="flex flex-1 gap-2 px-2 py-1 lg:max-w-[20%] lg:grow-0 lg:basis-[20%] lg:gap-0 lg:py-3" | ||
> | ||
<div class="block lg:hidden"> | ||
<span class="text-white">Time:</span> | ||
</div> | ||
<div> | ||
<span>{activityAction.date}  {activityAction.timeInDay}</span> | ||
</div> | ||
</div> | ||
<div | ||
class="flex flex-1 break-all px-2 py-1 lg:max-w-[23%] lg:grow-0 lg:basis-[23%] lg:py-3" | ||
> | ||
<div> | ||
<span class="inline-block rounded px-3 py-0.5 {activityAction.actionStyle} text-white" | ||
>{activityAction.actionName}</span | ||
> | ||
</div> | ||
</div> | ||
<div | ||
class="flex flex-1 flex-col px-2 py-1 lg:max-w-[45%] lg:grow-0 lg:basis-[45%] lg:py-3" | ||
> | ||
<Code>{JSON.stringify(activityAction.actionData, null, 2)}</Code> | ||
</div> | ||
{#each data.json.activity.actions as action} | ||
<div | ||
class="col-span-full grid grid-cols-subgrid gap-2 border-b border-mineShaft-900 pb-6 last:border-none md:gap-4" | ||
> | ||
<Transaction id={action.id} /> | ||
<p>{action.timestamp}</p> | ||
<div class="flex gap-2"> | ||
<Contract name={action.contract} /> | ||
<p>{action.action}</p> | ||
</div> | ||
{/each} | ||
</div> | ||
|
||
{#if hasMore} | ||
<Button onclick={clickLoadMore} variant="primary" class=""> | ||
{loadingText} | ||
</Button> | ||
{/if} | ||
{/if} | ||
</Stack> | ||
|
||
<style> | ||
@keyframes bounce { | ||
0%, | ||
20%, | ||
50%, | ||
80%, | ||
100% { | ||
transform: translateY(0); | ||
} | ||
40% { | ||
transform: translateY(-10px); | ||
} | ||
60% { | ||
transform: translateY(-5px); | ||
} | ||
} | ||
|
||
.bounce { | ||
animation: bounce 1.4s infinite ease-in-out; | ||
} | ||
|
||
.bounce-1 { | ||
animation-delay: 0s; | ||
} | ||
|
||
.bounce-2 { | ||
animation-delay: 0.2s; | ||
} | ||
<Code>{JSON.stringify(action.data, null, 2)}</Code> | ||
</div> | ||
{/each} | ||
</div> | ||
{/if} | ||
|
||
.bounce-3 { | ||
animation-delay: 0.4s; | ||
} | ||
</style> | ||
{#if data.json.activity.last} | ||
<Button href="?start={data.json.activity.last}">{m.common_next()}</Button> | ||
{/if} |
12 changes: 11 additions & 1 deletion
12
src/routes/[network]/(explorer)/account/[name]/activity/+page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 0 additions & 124 deletions
124
src/routes/[network]/(explorer)/account/[name]/activity/state.svelte.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't do this, because older activity shifts in time and the results aren't in the same sequence because its in descending order.
If the initial page shows records 99 through 90 (walking back in time), and page 2 shows 89 to 80 - then if a new entry is added to the front, record 90 would end up on page 2. If page 2 is cached, that record won't show.