30 lines
970 B
TypeScript
30 lines
970 B
TypeScript
"use client";
|
|
|
|
/**
|
|
* HiddenCountContext — lets a hide/unhide action deep in the tree (the
|
|
* PostCardMenu) nudge the owner's hidden-post count held by the /u/me layout,
|
|
* so the "Hidden" tab appears/disappears instantly without a refetch.
|
|
*
|
|
* The /u/me layout provides it around its subtree. Anywhere else (home feed,
|
|
* other users' profiles) there's no provider, so `adjustHiddenCount` defaults
|
|
* to a no-op — hiding from those surfaces simply doesn't touch a tab that
|
|
* isn't there.
|
|
*/
|
|
|
|
import { createContext, useContext } from "react";
|
|
|
|
type HiddenCountValue = {
|
|
/** Adjust the owner's hidden-post count by `delta` (the layout clamps at 0). */
|
|
adjustHiddenCount: (delta: number) => void;
|
|
};
|
|
|
|
const HiddenCountContext = createContext<HiddenCountValue>({
|
|
adjustHiddenCount: () => {},
|
|
});
|
|
|
|
export const HiddenCountProvider = HiddenCountContext.Provider;
|
|
|
|
export function useHiddenCount(): HiddenCountValue {
|
|
return useContext(HiddenCountContext);
|
|
}
|