Query all local repos by getting the local repo count

Instead of falling back to the default of 10 repos, set by
radicle-httpd.
We query the local httpd instance for the amount of repos hosted.
This commit is contained in:
Sebastian Martinez
2024-03-13 16:33:30 +01:00
parent 493d33a80a
commit 67eef6caa7
5 changed files with 30 additions and 10 deletions
+3 -1
View File
@@ -1,10 +1,11 @@
import type { BaseUrl } from "./lib/fetcher.js";
import type {
Blob,
DiffResponse,
Project,
ProjectListQuery,
Remote,
Tree,
DiffResponse,
} from "./lib/project.js";
import type {
SuccessResponse,
@@ -70,6 +71,7 @@ export type {
PatchUpdateAction,
Policy,
Project,
ProjectListQuery,
Range,
Reaction,
Remote,
+6 -1
View File
@@ -141,6 +141,11 @@ const diffResponseSchema = object({
files: record(string(), diffBlobSchema),
});
export type ProjectListQuery = {
page?: number;
perPage?: number;
show?: "pinned" | "all";
};
export class Client {
#fetcher: Fetcher;
@@ -181,7 +186,7 @@ export class Client {
}
public async getAll(
query?: { page?: number; perPage?: number; show?: "pinned" | "all" },
query?: ProjectListQuery,
options?: RequestOptions,
): Promise<Project[]> {
return this.#fetcher.fetchOk(
+4 -2
View File
@@ -1,3 +1,5 @@
import type { ProjectListQuery } from "@httpd-client";
import { loadProjectActivity, type WeeklyActivity } from "@app/lib/commit";
import {
HttpdClient,
@@ -15,10 +17,10 @@ export interface ProjectInfo {
export async function fetchProjectInfos(
baseUrl: BaseUrl,
show: "all" | "pinned",
query?: ProjectListQuery,
): Promise<ProjectInfo[]> {
const api = new HttpdClient(baseUrl);
const projects = await api.project.getAll({ show });
const projects = await api.project.getAll(query);
const info = await Promise.all(
projects.map(async project => {
const [activity, lastCommit] = await Promise.all([
+16 -5
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import type { ComponentProps } from "svelte";
import type { ProjectListQuery } from "@httpd-client";
import storedWritable from "@efstajas/svelte-stored-writable";
import { derived } from "svelte/store";
@@ -50,8 +51,19 @@
| undefined;
async function loadLocalProjects() {
const query: ProjectListQuery = { show: "all" };
await api
.getStats()
.then(({ repos: { total } }) => (query.perPage = total))
.catch(e => {
console.error(
"Not able to query to total repo count for your local node.",
e,
);
});
localProjects = undefined;
localProjects = await fetchProjectInfos(api.baseUrl, "all").catch(
localProjects = await fetchProjectInfos(api.baseUrl, query).catch(
error => error,
);
}
@@ -60,10 +72,9 @@
preferredSeedProjects = undefined;
if (!$selectedSeed) return;
preferredSeedProjects = await fetchProjectInfos(
$selectedSeed,
"pinned",
).catch(error => error);
preferredSeedProjects = await fetchProjectInfos($selectedSeed, {
show: "pinned",
}).catch(error => error);
}
function isSeeding(projectId: string) {
+1 -1
View File
@@ -148,7 +148,7 @@
</div>
<div style:margin-top="1rem">
{#await fetchProjectInfos(baseUrl, isLocal(baseUrl.hostname) ? "all" : "pinned")}
{#await fetchProjectInfos( baseUrl, { show: isLocal(baseUrl.hostname) ? "all" : "pinned" }, )}
<Loading small center />
{:then projectInfos}
<div class="project-grid">