Fix repo cards failing to load when head commit with non-utf8 are loaded

This commit is contained in:
Sebastian Martinez
2024-09-11 12:22:22 +02:00
parent 2bbcc2f9d1
commit 337dbf4312
4 changed files with 30 additions and 25 deletions
+15 -8
View File
@@ -1,5 +1,8 @@
<script lang="ts">
import type { RepoInfo } from "./RepoCard";
import type { BaseUrl } from "@http-client";
import { HttpdClient } from "@http-client";
import {
absoluteTimestamp,
@@ -15,6 +18,9 @@
export let compact = false;
export let repoInfo: RepoInfo;
export let baseUrl: BaseUrl;
const api = new HttpdClient(baseUrl);
$: repo = repoInfo.repo;
$: project = repoInfo.repo.payloads["xyz.radicle.project"];
@@ -174,14 +180,15 @@
<Icon name="issue" />
{project.meta.issues.open} ·
<Icon name="patch" />
<span
style:overflow="hidden"
style:text-overflow="ellipsis"
title={absoluteTimestamp(repoInfo.lastCommit.commit.committer.time)}>
{project.meta.patches.open} · Updated {formatTimestamp(
repoInfo.lastCommit.commit.committer.time,
)}
</span>
{project.meta.patches.open}
{#await api.repo.getCommitBySha(repo.rid, project.meta.head) then { commit }}
<span
style:overflow="hidden"
style:text-overflow="ellipsis"
title={absoluteTimestamp(commit.committer.time)}>
· Updated {formatTimestamp(commit.committer.time)}
</span>
{/await}
<span
title={repo.rid}
style:color="var(--color-foreground-emphasized)"
+13 -15
View File
@@ -1,13 +1,12 @@
import type { Repo, RepoListQuery } from "@http-client";
import type { BaseUrl, Repo, RepoListQuery } from "@http-client";
import { loadRepoActivity, type WeeklyActivity } from "@app/lib/commit";
import { HttpdClient, type BaseUrl, type Commit } from "@http-client";
import { HttpdClient } from "@http-client";
export interface RepoInfo {
repo: Repo;
baseUrl: BaseUrl;
activity: WeeklyActivity[];
lastCommit: Commit;
}
export async function fetchRepoInfos(
@@ -27,21 +26,20 @@ export async function fetchRepoInfos(
repos
.filter(r => Boolean(r.payloads["xyz.radicle.project"]))
.map(async repo => {
const [activity, lastCommit] = await Promise.all([
loadRepoActivity(repo.rid, baseUrl),
api.repo.getCommitBySha(
repo.rid,
repo["payloads"]["xyz.radicle.project"].meta.head,
),
]);
return { repo, activity, lastCommit, baseUrl };
const activity = await loadRepoActivity(repo.rid, baseUrl);
return { repo, activity, baseUrl };
}),
);
return info.sort((a, b) => {
const aLastCommit = a.lastCommit.commit.committer.time;
const bLastCommit = b.lastCommit.commit.committer.time;
return bLastCommit - aLastCommit;
if (a.activity.length === 0 && b.activity.length === 0) {
return 0;
} else if (a.activity.length === 0 && b.activity.length > 0) {
return 1;
} else if (b.activity.length === 0 && a.activity.length > 0) {
return -1;
} else {
return b.activity[0].time - a.activity[0].time;
}
});
}
+1 -1
View File
@@ -415,7 +415,7 @@
{#if repoInfos.length > 0}
<div class="repo-grid">
{#each repoInfos as repoInfo}
<RepoCard {repoInfo} />
<RepoCard {baseUrl} {repoInfo} />
{/each}
</div>
<div class="subtitle">
+1 -1
View File
@@ -360,7 +360,7 @@
{#if repos.length > 0}
<div class="repo-grid">
{#each repos as repoInfo}
<RepoCard {repoInfo}>
<RepoCard {repoInfo} {baseUrl}>
<svelte:fragment slot="delegate">
<Badge
title={`${node.alias || utils.formatNodeId(did.pubkey)} is a delegate of this repository`}