fix: hidden post
This commit is contained in:
@@ -11,12 +11,14 @@
|
||||
*/
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAuth } from "@/components/auth/auth-provider";
|
||||
import { PostScrollCard } from "@/components/social/post/post-scroll-card";
|
||||
import { posts, SocialError, type Post } from "@/lib/social";
|
||||
|
||||
export default function MyHiddenPostsPage() {
|
||||
const { user } = useAuth();
|
||||
const router = useRouter();
|
||||
const [feed, setFeed] = useState<Post[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -25,7 +27,13 @@ export default function MyHiddenPostsPage() {
|
||||
if (!user) return;
|
||||
posts
|
||||
.hidden()
|
||||
.then((rows) => setFeed(rows ?? []))
|
||||
.then((rows) => {
|
||||
const list = rows ?? [];
|
||||
setFeed(list);
|
||||
// Nothing hidden → the "Hidden" tab isn't in the strip, so this page
|
||||
// is a tab-less dead-end. Send the user to their Posts tab instead.
|
||||
if (list.length === 0) router.replace("/u/me");
|
||||
})
|
||||
.catch((err) =>
|
||||
setError(
|
||||
err instanceof SocialError
|
||||
@@ -34,15 +42,21 @@ export default function MyHiddenPostsPage() {
|
||||
),
|
||||
)
|
||||
.finally(() => setLoading(false));
|
||||
}, [user]);
|
||||
}, [user, router]);
|
||||
|
||||
function onPostUpdated(updated: Post) {
|
||||
setFeed((rows) => rows.map((p) => (p.id === updated.id ? updated : p)));
|
||||
}
|
||||
|
||||
// Unhiding a post means it's no longer hidden → remove it from this list.
|
||||
// Unhiding a post means it's no longer hidden → drop it from this list.
|
||||
// When that empties the list, the "Hidden" tab disappears (the layout's
|
||||
// count hits 0), so move the user to their Posts tab rather than leaving
|
||||
// them on an empty page with no active tab.
|
||||
function onHiddenChange(id: string, hidden: boolean) {
|
||||
if (!hidden) setFeed((rows) => rows.filter((p) => p.id !== id));
|
||||
if (hidden) return;
|
||||
const remaining = feed.filter((p) => p.id !== id);
|
||||
setFeed(remaining);
|
||||
if (remaining.length === 0) router.replace("/u/me");
|
||||
}
|
||||
|
||||
if (!user) return null;
|
||||
|
||||
Reference in New Issue
Block a user