mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +08:00
Cancel in-flight activity fetches on navigation
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
import type { BaseUrl, NodeStats } from "@http-client";
|
||||
import type { RepoInfo } from "@app/components/RepoCard";
|
||||
|
||||
import { onDestroy } from "svelte";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
import {
|
||||
fetchRepoInfos,
|
||||
@@ -23,6 +25,16 @@
|
||||
let sorting = false;
|
||||
let displayedRepos: RepoInfo[] = [];
|
||||
|
||||
let activityAbort: AbortController | undefined;
|
||||
|
||||
function newActivitySession(): AbortSignal {
|
||||
activityAbort?.abort();
|
||||
activityAbort = new AbortController();
|
||||
return activityAbort.signal;
|
||||
}
|
||||
|
||||
onDestroy(() => activityAbort?.abort());
|
||||
|
||||
// Reset state when baseUrl changes
|
||||
$: if (baseUrl) {
|
||||
listState = "pinned";
|
||||
@@ -51,7 +63,12 @@
|
||||
perPage: number,
|
||||
page: number,
|
||||
) {
|
||||
const repos = await fetchRepoInfos(baseUrl, { show, perPage, page });
|
||||
const repos = await fetchRepoInfos(
|
||||
baseUrl,
|
||||
{ show, perPage, page },
|
||||
undefined,
|
||||
newActivitySession(),
|
||||
);
|
||||
|
||||
if (
|
||||
hasPinnedRepos &&
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import type { BaseUrl, NodeIdentity, NodeStats } from "@http-client";
|
||||
|
||||
import { onDestroy } from "svelte";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
import * as utils from "@app/lib/utils";
|
||||
import { fetchRepoInfos } from "@app/components/RepoCard";
|
||||
@@ -16,6 +18,16 @@
|
||||
export let stats: NodeStats;
|
||||
export let user: NodeIdentity;
|
||||
export let did: { prefix: string; pubkey: string };
|
||||
|
||||
let activityAbort: AbortController | undefined;
|
||||
|
||||
function newActivitySession(): AbortSignal {
|
||||
activityAbort?.abort();
|
||||
activityAbort = new AbortController();
|
||||
return activityAbort.signal;
|
||||
}
|
||||
|
||||
onDestroy(() => activityAbort?.abort());
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -43,7 +55,7 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
{#await fetchRepoInfos(baseUrl, { show: "all", perPage: stats.repos.total }, utils.formatDid(did))}
|
||||
{#await fetchRepoInfos(baseUrl, { show: "all", perPage: stats.repos.total }, utils.formatDid(did), newActivitySession())}
|
||||
<div class="container">
|
||||
<Loading small center />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user