a tool for shared writing and social publishing
at main 63 lines 1.8 kB view raw
1import { useCallback } from "react"; 2import { useFootnoteContext } from "./FootnoteContext"; 3import { FootnoteEditor } from "./FootnoteEditor"; 4import { useReplicache } from "src/replicache"; 5import { useEntitySetContext } from "components/EntitySetProvider"; 6import { deleteFootnoteFromBlock } from "./deleteFootnoteFromBlock"; 7import { FootnoteSideColumnLayout } from "./FootnoteSideColumnLayout"; 8 9type EditorFootnoteItem = { 10 id: string; 11 index: number; 12 footnoteEntityID: string; 13 blockID: string; 14}; 15 16export function FootnoteSideColumn(props: { 17 pageEntityID: string; 18 visible: boolean; 19 fullPageScroll?: boolean; 20}) { 21 let { footnotes } = useFootnoteContext(); 22 let { permissions } = useEntitySetContext(); 23 let rep = useReplicache(); 24 25 let items: EditorFootnoteItem[] = footnotes.map((fn) => ({ 26 id: fn.footnoteEntityID, 27 index: fn.index, 28 footnoteEntityID: fn.footnoteEntityID, 29 blockID: fn.blockID, 30 })); 31 32 let getAnchorSelector = useCallback( 33 (item: EditorFootnoteItem) => 34 `.footnote-ref[data-footnote-id="${item.id}"]`, 35 [], 36 ); 37 38 let renderItem = useCallback( 39 (item: EditorFootnoteItem & { top: number }) => ( 40 <FootnoteEditor 41 footnoteEntityID={item.footnoteEntityID} 42 index={item.index} 43 editable={permissions.write} 44 onDelete={ 45 permissions.write 46 ? () => deleteFootnoteFromBlock(item.footnoteEntityID, item.blockID, rep.rep) 47 : undefined 48 } 49 /> 50 ), 51 [permissions.write, rep.rep], 52 ); 53 54 return ( 55 <FootnoteSideColumnLayout 56 items={items} 57 visible={props.visible} 58 fullPageScroll={props.fullPageScroll} 59 getAnchorSelector={getAnchorSelector} 60 renderItem={renderItem} 61 /> 62 ); 63}