MCPcopy Create free account
hub / github.com/PatoSala/react-native-blocks / PageBlock

Function PageBlock

packages/blocks/src/PageBlock.tsx:27–403  ·  view source on GitHub ↗
({ blockId } : Props)

Source from the content-addressed store, hash-verified

25}
26
27export 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);

Callers

nothing calls this directly

Calls 7

useTextInputFunction · 0.90
useBlocksContextFunction · 0.90
useTextBlocksContextFunction · 0.90
useBlockFunction · 0.90
containsEmojiFunction · 0.85
getTextInputPropsFunction · 0.85
pickIconFunction · 0.85

Tested by

no test coverage detected