/ src / api / repos / index.ts
index.ts
 1  import { API_URL, type DID, type RID } from "../constants"
 2  
 3  export interface Repository {
 4      delegates: Array<{
 5          alias: string
 6          id: DID
 7      }>
 8      payloads: {
 9          "xyz.radicle.project": {
10              data: {
11                  defaultBranch: string
12                  description: string
13                  name: string
14              }
15              meta: {
16                  head: string
17                  issues: {
18                      open: number
19                      closed: number
20                  }
21                  patches: {
22                      archived: number
23                      draft: number
24                      merged: number
25                      open: number
26                  }
27              }
28          }
29      }
30      rid: RID
31      seeding: number
32      threshold: number
33      visibility: {
34          type: "public"
35      }
36  }
37  
38  export const getRepositories = async (show: "all" | "pinned" = "all", page = 0, perPage = 24): Promise<Array<Repository>> => {
39      const params = new URLSearchParams();
40  
41      params.set("show", show);
42      params.set("page", String(page));
43      params.set("perPage", String(perPage));
44  
45      return fetch(`${API_URL}/repos?${params.toString()}`)
46          .then(res => res.json())
47  }
48  
49  export const getRepository = async (rid: RID): Promise<Repository> =>
50      fetch(`${API_URL}/repos/${rid}`)
51          .then(res => res.json())