a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add fold/unfold all shortcuts

+49
+49
components/Blocks/index.tsx
··· 15 15 16 16 import { BlockOptions } from "./BlockOptions"; 17 17 import { Block } from "./Block"; 18 + import { useEffect } from "react"; 19 + import { addShortcut } from "src/shortcuts"; 18 20 19 21 export function Blocks(props: { entityID: string }) { 20 22 let rep = useReplicache(); 21 23 let entity_set = useEntitySetContext(); 22 24 let blocks = useBlocks(props.entityID); 23 25 let foldedBlocks = useUIState((s) => s.foldedBlocks); 26 + useEffect(() => { 27 + return addShortcut([ 28 + { 29 + altKey: true, 30 + metaKey: true, 31 + key: "ArrowUp", 32 + shift: true, 33 + handler: () => { 34 + let allParents = blocks.reduce((acc, block) => { 35 + if (!block.listData) return acc; 36 + block.listData.path.forEach((p) => 37 + !acc.includes(p.entity) ? acc.push(p.entity) : null, 38 + ); 39 + return acc; 40 + }, [] as string[]); 41 + useUIState.setState((s) => { 42 + let foldedBlocks = [...s.foldedBlocks]; 43 + allParents.forEach((p) => { 44 + if (!foldedBlocks.includes(p)) foldedBlocks.push(p); 45 + }); 46 + return { foldedBlocks }; 47 + }); 48 + }, 49 + }, 50 + { 51 + altKey: true, 52 + metaKey: true, 53 + key: "ArrowDown", 54 + shift: true, 55 + handler: () => { 56 + let allParents = blocks.reduce((acc, block) => { 57 + if (!block.listData) return acc; 58 + block.listData.path.forEach((p) => 59 + !acc.includes(p.entity) ? acc.push(p.entity) : null, 60 + ); 61 + return acc; 62 + }, [] as string[]); 63 + useUIState.setState((s) => { 64 + let foldedBlocks = [...s.foldedBlocks].filter( 65 + (f) => !allParents.includes(f), 66 + ); 67 + return { foldedBlocks }; 68 + }); 69 + }, 70 + }, 71 + ]); 72 + }, [blocks]); 24 73 25 74 let lastRootBlock = blocks.findLast( 26 75 (f) => !f.listData || f.listData.depth === 1