Skip to content

Commit

Permalink
Load issue activity in the router to prevent flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolfs committed Nov 5, 2024
1 parent 777430a commit 34c6480
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
42 changes: 20 additions & 22 deletions src/views/repo/Issue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import type { RepoInfo } from "@bindings/repo/RepoInfo";
import partial from "lodash/partial";
import { onMount, tick } from "svelte";
import { tick } from "svelte";
import * as roles from "@app/lib/roles";
import {
Expand Down Expand Up @@ -39,11 +39,18 @@
repo: RepoInfo;
issue: Issue;
issues: Issue[];
activity: Operation[];
config: Config;
}
/* eslint-disable prefer-const */
let { repo, issue, issues: initialIssues, config }: Props = $props();
let {
repo,
issue,
issues: initialIssues,
activity,
config,
}: Props = $props();
/* eslint-enable prefer-const */
const issues = $state(initialIssues);
Expand All @@ -62,7 +69,6 @@
topLevelReplyOpen = false;
editingTitle = false;
updatedTitle = issue.title;
void loadActivity();
}
});
Expand All @@ -85,20 +91,6 @@
}, []),
);
let activity = $state<Operation[]>([]);
async function loadActivity() {
activity = await invoke("activity_by_id", {
rid: repo.rid,
typeName: "xyz.radicle.issue",
id: issue.id,
});
}
onMount(() => {
void loadActivity();
});
async function toggleReply() {
topLevelReplyOpen = !topLevelReplyOpen;
if (!topLevelReplyOpen) {
Expand All @@ -113,11 +105,17 @@
}
async function reload() {
issue = await invoke("issue_by_id", {
rid: repo.rid,
id: issue.id,
});
await loadActivity();
[issue, activity] = await Promise.all([
invoke<Issue>("issue_by_id", {
rid: repo.rid,
id: issue.id,
}),
invoke<Operation[]>("activity_by_id", {
rid: repo.rid,
typeName: "xyz.radicle.issue",
id: issue.id,
}),
]);
}
async function createComment(body: string, embeds: Embed[]) {
Expand Down
13 changes: 10 additions & 3 deletions src/views/repo/router.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Config } from "@bindings/config/Config";
import type { PaginatedQuery } from "@bindings/cob/PaginatedQuery";
import type { Issue } from "@bindings/cob/issue/Issue";
import type { Operation } from "@bindings/cob/issue/Operation";
import type { PaginatedQuery } from "@bindings/cob/PaginatedQuery";
import type { Patch } from "@bindings/cob/patch/Patch";
import type { RepoInfo } from "@bindings/repo/RepoInfo";
import type { Revision } from "@bindings/cob/patch/Revision";
Expand Down Expand Up @@ -28,6 +29,7 @@ export interface LoadedRepoIssueRoute {
config: Config;
issue: Issue;
issues: Issue[];
activity: Operation[];
};
}

Expand Down Expand Up @@ -174,7 +176,7 @@ export async function loadCreateIssue(
export async function loadIssue(
route: RepoIssueRoute,
): Promise<LoadedRepoIssueRoute> {
const [config, repo, issue, issues] = await Promise.all([
const [config, repo, issue, activity, issues] = await Promise.all([
invoke<Config>("config"),
invoke<RepoInfo>("repo_by_id", {
rid: route.rid,
Expand All @@ -183,6 +185,11 @@ export async function loadIssue(
rid: route.rid,
id: route.issue,
}),
invoke<Operation[]>("activity_by_id", {
rid: route.rid,
typeName: "xyz.radicle.issue",
id: route.issue,
}),
invoke<Issue[]>("list_issues", {
rid: route.rid,
status: "all",
Expand All @@ -191,7 +198,7 @@ export async function loadIssue(

return {
resource: "repo.issue",
params: { repo, config, issue, issues },
params: { repo, config, issue, activity, issues },
};
}

Expand Down

0 comments on commit 34c6480

Please sign in to comment.