fix: feed card follow ui

This commit is contained in:
gosangam
2026-06-18 00:21:06 +05:30
parent 071eb4d58a
commit 84cb273941
4 changed files with 59 additions and 19 deletions
+12 -4
View File
@@ -18,22 +18,30 @@ import { useAuthGate } from "@/components/auth/auth-gate";
export function FeedFollowButton({
handle,
followsYou,
requested = false,
}: {
handle: string;
/** The author already follows the viewer → label becomes "Follow back". */
followsYou: boolean;
/** Server-truth: the viewer already has a pending follow request to this
* author (e.g. sent in a prior session or on the profile page). */
requested?: boolean;
}) {
const { requireAuth } = useAuthGate();
const [requested, setRequested] = useState(false);
const [justRequested, setJustRequested] = useState(false);
const [busy, setBusy] = useState(false);
// Show "Requested" when the server already knows about a pending request or
// the viewer just sent one in this session.
const showRequested = requested || justRequested;
async function follow() {
if (busy || requested) return;
if (busy || showRequested) return;
if (!(await requireAuth())) return;
setBusy(true);
try {
await relationships.follow(handle);
setRequested(true);
setJustRequested(true);
} catch (err) {
toast.error(
err instanceof SocialError ? err.message : "Could not follow",
@@ -44,7 +52,7 @@ export function FeedFollowButton({
}
}
if (requested) {
if (showRequested) {
return (
<span className="shrink-0 inline-flex items-center gap-1 rounded-full border border-border px-3 h-8 text-xs font-medium text-muted-foreground">
<Clock className="size-3.5" />