import { Link } from "@tanstack/react-router";
import { Avatar, EmptyState, RelativeTime } from "./ui/Primitives";
import type { JsonValue } from "~/lib/types";
type FeedItem = {
id: string;
actor: { name: string };
repo: { owner: string; name: string } | null;
kind: string;
data: { [key: string]: JsonValue };
createdAt: number;
};
function text(value: JsonValue | undefined): string {
return typeof value === "string" || typeof value === "number" ? String(value) : "";
}
function describe(item: FeedItem): string {
const { data } = item;
switch (item.kind) {
case "push":
return `pushed ${text(data.total)} commit(s) to ${text(data.ref)}`;
case "ref_created":
return `created ${text(data.refType)} ${text(data.ref)}`;
case "ref_deleted":
return `deleted ${text(data.refType)} ${text(data.ref)}`;
case "repo_created":
return "created repository";
case "repo_imported":
return `imported from ${text(data.source)}`;
case "repo_forked":
return `forked ${text(data.source)}`;
case "issue_opened":
return `opened issue #${text(data.number)} ${text(data.title)}`;
case "pull_opened":
return `opened pull request #${text(data.number)} ${text(data.title)}`;
case "pull_merged":
return `merged pull request #${text(data.number)} ${text(data.title)}`;
case "comment":
return `commented on #${text(data.number)} ${text(data.title)}`;