mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-16 03:40:37 +08:00
Refactor commit history view
Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { fade } from "svelte/transition";
|
||||
|
||||
import Button from "@app/components/Button.svelte";
|
||||
import Loading from "@app/components/Loading.svelte";
|
||||
|
||||
type Item = $$Generic;
|
||||
|
||||
export let complete = false;
|
||||
export let items: Item[];
|
||||
export let query: () => Promise<Item[]>;
|
||||
|
||||
// Used to handle the display of the trigger to load more items, according to the current loading state.
|
||||
let loading = false;
|
||||
|
||||
const transitionParams = { duration: 200 };
|
||||
|
||||
const fetchMore = async () => {
|
||||
loading = true;
|
||||
const response = await query();
|
||||
|
||||
if (response.length > 0) {
|
||||
items = [...items, ...response];
|
||||
} else {
|
||||
complete = true;
|
||||
}
|
||||
|
||||
loading = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.more {
|
||||
margin-top: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
<slot name="list" {items} />
|
||||
{#if !complete}
|
||||
<slot name="more" {fetchMore} {loading}>
|
||||
{#if loading}
|
||||
<div class="more" transition:fade|local={transitionParams}>
|
||||
<Loading small />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="more" transition:fade|local={transitionParams}>
|
||||
<Button
|
||||
variant="foreground"
|
||||
waiting={loading}
|
||||
disabled={loading}
|
||||
on:click={fetchMore}>
|
||||
More
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</slot>
|
||||
{/if}
|
||||
Reference in New Issue
Block a user