Exosphere is a set of small, modular, self-hostable community tools built on the AT Protocol. app.exosphere.site
at main 42 lines 1.5 kB view raw
1import { moduleFetch } from "@exosphere/client/module-api"; 2import type { FeatureRequestComment, FeatureRequestCommentListItem } from "../../types.ts"; 3 4export type { FeatureRequestComment, FeatureRequestCommentListItem }; 5 6export function getComments(requestId: string, sort?: "date" | "votes", order?: "asc" | "desc") { 7 const params = new URLSearchParams(); 8 if (sort) params.set("sort", sort); 9 if (order) params.set("order", order); 10 const qs = params.toString(); 11 return moduleFetch<{ comments: FeatureRequestCommentListItem[] }>( 12 `/feature-requests/${encodeURIComponent(requestId)}/comments${qs ? `?${qs}` : ""}`, 13 ); 14} 15 16export function createComment(requestId: string, content: string) { 17 return moduleFetch<{ comment: FeatureRequestComment & { createdAt: string } }>( 18 `/feature-requests/${encodeURIComponent(requestId)}/comments`, 19 { 20 method: "POST", 21 headers: { "Content-Type": "application/json" }, 22 body: JSON.stringify({ content }), 23 }, 24 ); 25} 26 27export function updateComment(id: string, content: string) { 28 return moduleFetch<{ comment: FeatureRequestComment & { createdAt: string } }>( 29 `/feature-requests/comments/${encodeURIComponent(id)}`, 30 { 31 method: "PUT", 32 headers: { "Content-Type": "application/json" }, 33 body: JSON.stringify({ content }), 34 }, 35 ); 36} 37 38export function deleteComment(id: string) { 39 return moduleFetch<{ ok: true }>(`/feature-requests/comments/${encodeURIComponent(id)}`, { 40 method: "DELETE", 41 }); 42}