fix: hidden post
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
* lives outside this layout so it isn't framed by the header + tabs).
|
||||
*/
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import {
|
||||
AtSign,
|
||||
@@ -27,6 +27,7 @@ import { useAuthGate } from "@/components/auth/auth-gate";
|
||||
import { profile } from "@/lib/social";
|
||||
import { ProfileHeader } from "@/components/profile/profile-header";
|
||||
import { ProfileTabs, type ProfileTab } from "@/components/profile/profile-tabs";
|
||||
import { HiddenCountProvider } from "@/components/profile/hidden-count-context";
|
||||
|
||||
export default function MeLayout({ children }: { children: React.ReactNode }) {
|
||||
const { user, loading } = useAuth();
|
||||
@@ -78,6 +79,15 @@ export default function MeLayout({ children }: { children: React.ReactNode }) {
|
||||
};
|
||||
}, [handle]);
|
||||
|
||||
// Let a hide/unhide action anywhere in the subtree (the PostCardMenu) nudge
|
||||
// the hidden count so the "Hidden" tab toggles instantly. Clamped at 0.
|
||||
const adjustHiddenCount = useCallback((delta: number) => {
|
||||
setCounts((c) =>
|
||||
c ? { ...c, hidden: Math.max(0, c.hidden + delta) } : c,
|
||||
);
|
||||
}, []);
|
||||
const hiddenCtx = useMemo(() => ({ adjustHiddenCount }), [adjustHiddenCount]);
|
||||
|
||||
if (loading || !user) {
|
||||
return (
|
||||
<main className="flex-1 flex items-center justify-center px-4 py-12">
|
||||
@@ -136,7 +146,9 @@ export default function MeLayout({ children }: { children: React.ReactNode }) {
|
||||
followingCount={counts?.following}
|
||||
/>
|
||||
<ProfileTabs tabs={tabs} />
|
||||
<div className="py-6">{children}</div>
|
||||
<HiddenCountProvider value={hiddenCtx}>
|
||||
<div className="py-6">{children}</div>
|
||||
</HiddenCountProvider>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user