Something went wrong. Try again.
a tool for shared writing and social publishing
Something went wrong. Try again.
TSX
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152"use client";import { createContext, useContext } from "react";import type { PostPageData } from "app/lish/[did]/[publication]/[rkey]/getPostPageData";
// Derive types from PostPageDatatype NonNullPostPageData = NonNullable<PostPageData>;export type PublicationContext = NonNullPostPageData["publication"];export type CommentOnDocument = NonNullPostPageData["comments"][number];export type DocumentMention = NonNullPostPageData["mentions"][number];export type QuotesAndMentions = NonNullPostPageData["quotesAndMentions"];
export type DocumentContextValue = Pick< NonNullPostPageData, | "uri" | "normalizedDocument" | "normalizedPublication" | "theme" | "prevNext" | "quotesAndMentions" | "publication" | "comments" | "mentions" | "leafletId" | "recommendsCount">;
const DocumentContext = createContext<DocumentContextValue | null>(null);
export function useDocument() { const ctx = useContext(DocumentContext); if (!ctx) throw new Error("useDocument must be used within DocumentProvider"); return ctx;}
export function useDocumentOptional() { return useContext(DocumentContext);}
export function DocumentProvider({ children, value,}: { children: React.ReactNode; value: DocumentContextValue;}) { return ( <DocumentContext.Provider value={value}> {children} </DocumentContext.Provider> );}