Files
thoughts/thoughts-frontend/components/federation/remote-following.tsx
Gabriel Kaszewski 2e3b81de17
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Has been cancelled
test / unit (pull_request) Has been cancelled
test / integration (pull_request) Has been cancelled
fix: full fediverse handle display + follower count includes remote
2026-05-15 04:35:04 +02:00

71 lines
2.3 KiB
TypeScript

"use client";
import { useEffect, useState } from "react";
import { getRemoteFollowing, unfollowRemoteActor, type RemoteActor } from "@/lib/api";
import { useAuth } from "@/hooks/use-auth";
import { UserAvatar } from "@/components/user-avatar";
import { Button } from "@/components/ui/button";
import { toast } from "sonner";
import Link from "next/link";
import { fullFediverseHandle } from "@/lib/utils";
export function RemoteFollowing() {
const { token } = useAuth();
const [following, setFollowing] = useState<RemoteActor[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
if (!token) return;
getRemoteFollowing(token)
.then(setFollowing)
.catch(() => toast.error("Failed to load following"))
.finally(() => setLoading(false));
}, [token]);
const unfollow = async (handle: string) => {
if (!token) return;
setFollowing((prev) => prev.filter((f) => f.handle !== handle));
await unfollowRemoteActor(handle, token).catch(() => {
toast.error("Failed to unfollow");
});
};
if (loading) return <p className="text-sm text-muted-foreground">Loading</p>;
if (following.length === 0)
return <p className="text-sm text-muted-foreground">Not following anyone remotely yet.</p>;
return (
<ul className="space-y-3">
{following.map((actor) => (
<li key={actor.url} className="flex items-center justify-between gap-3">
<Link
href={`/users/@${actor.handle}`}
className="flex items-center gap-2 min-w-0 hover:opacity-80"
>
<UserAvatar
src={actor.avatarUrl}
alt={actor.displayName}
className="h-8 w-8 shrink-0"
/>
<div className="min-w-0">
<p className="text-sm font-medium truncate">
{actor.displayName || actor.handle}
</p>
<p className="text-xs text-muted-foreground truncate font-mono">
@{fullFediverseHandle(actor.handle, actor.url)}
</p>
</div>
</Link>
<Button
size="sm"
variant="outline"
onClick={() => unfollow(actor.handle)}
>
Unfollow
</Button>
</li>
))}
</ul>
);
}