a tool for shared writing and social publishing
0
fork

Configure Feed

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

clicking anywhere are bottom of the page focuses the last visible text block, instead of focusing the last text root block

celine 2bfdc3c7 49ba5a0e

+39 -12
+39 -12
components/Blocks/index.tsx
··· 11 11 import { CardBlock } from "./CardBlock"; 12 12 import { ExternalLinkBlock } from "./ExternalLinkBlock"; 13 13 import { BlockOptions } from "./BlockOptions"; 14 - import { getBlocksWithType, useBlocks } from "src/hooks/queries/useBlocks"; 14 + import { useBlocks } from "src/hooks/queries/useBlocks"; 15 15 import { setEditorState, useEditorStates } from "src/state/useEditorState"; 16 16 import { useEntitySetContext } from "components/EntitySetProvider"; 17 - import { scanIndex } from "src/replicache/utils"; 18 17 import { v7 } from "uuid"; 19 18 import { useBlockMouseHandlers } from "./useBlockMouseHandlers"; 20 19 import { indent, outdent } from "src/utils/list-operations"; ··· 36 35 let blocks = useBlocks(props.entityID); 37 36 let foldedBlocks = useUIState((s) => s.foldedBlocks); 38 37 39 - let lastBlock = blocks.findLast((f) => !f.listData || f.listData.depth === 1); 38 + let lastRootBlock = blocks.findLast( 39 + (f) => !f.listData || f.listData.depth === 1, 40 + ); 41 + 42 + let lastVisibleBlock = blocks.findLast( 43 + (f) => 44 + !f.listData || 45 + !f.listData.path.find( 46 + (path) => foldedBlocks.includes(path.entity) && f.value !== path.entity, 47 + ), 48 + ); 49 + 40 50 return ( 41 51 <div 42 - className={`blocks w-full flex flex-col outline-none h-fit min-h-full ${entity_set.permissions.write ? "pb-32" : "pb-4"}`} 52 + className={`blocks w-full flex flex-col outline-none h-fit min-h-full ${!entity_set.permissions.write && "pb-6"}`} 43 53 onClick={async (e) => { 44 54 if (useUIState.getState().selectedBlock.length > 1) return; 45 55 if (e.target === e.currentTarget) { 46 56 if ( 47 - !lastBlock || 48 - (lastBlock.type !== "text" && lastBlock.type !== "heading") 57 + !lastVisibleBlock || 58 + (lastVisibleBlock.type !== "text" && 59 + lastVisibleBlock.type !== "heading") 49 60 ) { 50 61 let newEntityID = v7(); 51 62 await rep.rep?.mutate.addBlock({ ··· 53 64 factID: v7(), 54 65 permission_set: entity_set.set, 55 66 type: "text", 56 - position: generateKeyBetween(lastBlock?.position || null, null), 67 + position: generateKeyBetween( 68 + lastRootBlock?.position || null, 69 + null, 70 + ), 57 71 newEntityID, 58 72 }); 59 73 ··· 63 77 ?.focus(); 64 78 }, 10); 65 79 } else { 66 - focusBlock(lastBlock, { type: "end" }); 80 + lastVisibleBlock && focusBlock(lastVisibleBlock, { type: "end" }); 67 81 } 68 82 } 69 83 }} ··· 100 114 /> 101 115 ); 102 116 })} 103 - <NewBlockButton lastBlock={lastBlock || null} entityID={props.entityID} /> 117 + <NewBlockButton 118 + lastBlock={lastRootBlock || null} 119 + entityID={props.entityID} 120 + /> 104 121 {entity_set.permissions.write ? ( 105 122 <div 106 123 className="shrink-0 h-[50vh]" 107 124 onClick={() => { 108 125 let newEntityID = v7(); 109 126 110 - if (lastBlock && textBlocks[lastBlock.type]) { 111 - focusBlock({ ...lastBlock, type: "text" }, { type: "end" }); 127 + if ( 128 + lastRootBlock && 129 + lastVisibleBlock && 130 + textBlocks[lastVisibleBlock.type] 131 + ) { 132 + focusBlock( 133 + { ...lastVisibleBlock, type: "text" }, 134 + { type: "end" }, 135 + ); 112 136 } else { 113 137 rep?.rep?.mutate.addBlock({ 114 138 permission_set: entity_set.set, 115 139 factID: v7(), 116 140 parent: props.entityID, 117 141 type: "text", 118 - position: generateKeyBetween(lastBlock?.position || null, null), 142 + position: generateKeyBetween( 143 + lastRootBlock?.position || null, 144 + null, 145 + ), 119 146 newEntityID, 120 147 }); 121 148