({ blockId } : Props)
| 25 | } |
| 26 | |
| 27 | export function PageBlock({ blockId } : Props) { |
| 28 | const { |
| 29 | getTextInputProps, |
| 30 | getValue, |
| 31 | getSelection |
| 32 | } = useTextInput(blockId); |
| 33 | const { |
| 34 | blocks, |
| 35 | insertBlock, |
| 36 | updateBlock, |
| 37 | updateBlockV2, |
| 38 | blocksOrder, |
| 39 | } = useBlocksContext(); |
| 40 | const { |
| 41 | inputRefs |
| 42 | } = useTextBlocksContext(); |
| 43 | const { properties } = useBlock(blockId); |
| 44 | |
| 45 | // This condition should be renamed to "isFirstBlock" or sth like that. |
| 46 | const isRootBlock = blocks["root"].content[0] === blockId; |
| 47 | const [showEmojiSelector, setShowEmojiSelector] = useState(false); |
| 48 | const [pageIcon, setPageIcon] = useState<string | null>(blocks[blockId]?.format?.page_icon || null); |
| 49 | const [pageCover, setPageCover] = useState<string | null>(blocks[blockId]?.format?.page_cover || null); |
| 50 | const placeholder = "New page"; |
| 51 | |
| 52 | const pickCover = async () => { |
| 53 | let result = await ImagePicker.launchImageLibraryAsync({ |
| 54 | mediaTypes: ['images'], |
| 55 | allowsEditing: false, |
| 56 | quality: 1, |
| 57 | }); |
| 58 | |
| 59 | if (!result.canceled) { |
| 60 | setPageCover(result.assets[0].uri); |
| 61 | |
| 62 | const updatedBlock = updateBlockData(blocks[blockId], { |
| 63 | format: { |
| 64 | page_cover: result.assets[0].uri |
| 65 | /* page_cover_position */ |
| 66 | } |
| 67 | }); |
| 68 | |
| 69 | updateBlock(updatedBlock); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | const pickIcon = async () => { |
| 74 | let result = await ImagePicker.launchImageLibraryAsync({ |
| 75 | mediaTypes: ['images'], |
| 76 | allowsEditing: true, |
| 77 | quality: 1, |
| 78 | aspect: [4, 3] |
| 79 | }); |
| 80 | |
| 81 | if (!result.canceled) { |
| 82 | setPageIcon(result.assets[0].uri); |
| 83 | /* setAspectRatio(result.assets[0].width / result.assets[0].height); */ |
| 84 | setShowEmojiSelector(false); |
nothing calls this directly
no test coverage detected