From acbca6468122a666aaaabfc7c935578e39285777 Mon Sep 17 00:00:00 2001 From: Thomas Irvine Date: Sun, 17 Sep 2023 23:16:04 -0500 Subject: [PATCH 1/3] comment on possible location --- lib/screens/EditNoteScreen.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/screens/EditNoteScreen.tsx b/lib/screens/EditNoteScreen.tsx index c538c41..e045493 100644 --- a/lib/screens/EditNoteScreen.tsx +++ b/lib/screens/EditNoteScreen.tsx @@ -372,6 +372,7 @@ const EditNoteScreen: React.FC = ({ placeholder="Write your note here" onChange={(text) => setText(text)} initialContentHTML={text} + //at first glance I believe changes need to be made here. onCursorPosition={(position) => { handleScroll(position); }} From 257eb107376bd57b9157437c87f09ca5b93ac0e3 Mon Sep 17 00:00:00 2001 From: Thomas Irvine Date: Mon, 25 Sep 2023 11:39:50 -0500 Subject: [PATCH 2/3] inline image, no test yet --- lib/components/photoScroller.tsx | 6 ++++++ lib/screens/EditNoteScreen.tsx | 8 ++++++++ types.ts | 1 + 3 files changed, 15 insertions(+) diff --git a/lib/components/photoScroller.tsx b/lib/components/photoScroller.tsx index 61d7db4..fc51f51 100644 --- a/lib/components/photoScroller.tsx +++ b/lib/components/photoScroller.tsx @@ -28,10 +28,12 @@ const PhotoScroller = forwardRef( newMedia, setNewMedia, active, + insertImageToEditor, }: { newMedia: Media[]; setNewMedia: React.Dispatch>; active: Boolean; + insertImageToEditor: Function; }, ref ) => { @@ -81,6 +83,7 @@ const PhotoScroller = forwardRef( uri: uploadedUrl, }); setNewMedia([...newMedia, newMediaItem]); + insertImageToEditor(uploadedUrl); } else if ( uri.endsWith(".jpg") || uri.endsWith("png") || @@ -94,6 +97,9 @@ const PhotoScroller = forwardRef( uri: uploadedUrl, }); setNewMedia([...newMedia, newMediaItem]); + if (insertImageToEditor) { + insertImageToEditor(uploadedUrl, 'Captured Image'); + } } else if ( uri.endsWith(".MOV") || uri.endsWith(".mov") || diff --git a/lib/screens/EditNoteScreen.tsx b/lib/screens/EditNoteScreen.tsx index e045493..1de43ca 100644 --- a/lib/screens/EditNoteScreen.tsx +++ b/lib/screens/EditNoteScreen.tsx @@ -7,6 +7,7 @@ import { useWindowDimensions, Text, } from "react-native"; +import * as ImagePicker from 'expo-image-picker'; import { TouchableOpacity } from "react-native-gesture-handler"; import { Ionicons } from "@expo/vector-icons"; import { Note } from "../../types"; @@ -34,6 +35,7 @@ const user = User.getInstance(); const EditNoteScreen: React.FC = ({ route, navigation, + insertImageToEditor, }) => { const { note, onSave } = route.params; const [title, setTitle] = useState(note.title); @@ -116,6 +118,11 @@ const EditNoteScreen: React.FC = ({ } }; + const addImageToEditor = (imageUri: string) => { + richTextRef.current?.insertImage(imageUri); + }; + + const handleSaveNote = async () => { try { const editedNote: Note = { @@ -239,6 +246,7 @@ const EditNoteScreen: React.FC = ({ active={viewMedia} newMedia={media} setNewMedia={setMedia} + insertImageToEditor={addImageToEditor} /> {viewAudio && ( diff --git a/types.ts b/types.ts index c2759a6..cb3564f 100644 --- a/types.ts +++ b/types.ts @@ -55,6 +55,7 @@ export type EditNoteScreenProps = { navigation: { goBack: () => void; }; + insertImageToEditor: (capturedImage: string) => void; }; export type RootTabParamList = { From 38128496183744e30468449a30cf67770536e7ae Mon Sep 17 00:00:00 2001 From: Thomas Irvine Date: Wed, 27 Sep 2023 15:30:37 -0500 Subject: [PATCH 3/3] fin? --- __tests__/InsertImageNoteScreen.test.tsx | 30 +++++++++++++++++++++++ __tests__/TestResources/TestImage.jpg | Bin 0 -> 666 bytes lib/screens/AddNoteScreen.tsx | 7 +++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 __tests__/InsertImageNoteScreen.test.tsx create mode 100644 __tests__/TestResources/TestImage.jpg diff --git a/__tests__/InsertImageNoteScreen.test.tsx b/__tests__/InsertImageNoteScreen.test.tsx new file mode 100644 index 0000000..3238116 --- /dev/null +++ b/__tests__/InsertImageNoteScreen.test.tsx @@ -0,0 +1,30 @@ +import Enzyme from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; + +Enzyme.configure({ adapter: new Adapter() }); + +import React from 'react'; +import { shallow } from "enzyme"; +import AddNoteScreen from '../lib/screens/AddNoteScreen'; + +describe("AddNoteScreen", () => { + it("adds image to editor", () => { + const wrapper = shallow(); + + // Mock richTextRef + const richTextRef = { current: { insertImage: jest.fn() } }; + + //hard code copy paste of function + const addImageToEditor = (imageUri: string) => { + richTextRef.current?.insertImage(imageUri); + }; + // Mock image URI + const imageUri = '__tests__/TestResources/TestImage.jpg'; + + // Call addImageToEditor function + addImageToEditor(imageUri); + + // Verify that the function was called with the correct argument + expect(richTextRef.current.insertImage).toHaveBeenCalledWith(imageUri); + }); +}); diff --git a/__tests__/TestResources/TestImage.jpg b/__tests__/TestResources/TestImage.jpg new file mode 100644 index 0000000000000000000000000000000000000000..947d00b75113de47f78e932472d07ff87fb89726 GIT binary patch literal 666 zcmeAS@N?(olHy`uVBq!ia0vp^H6YBv3?%0qQ0W0u$pJnguK)l4mz9+U@?N}nap1s# zw{PE?n3(+e^G8xrOk7-4SXkim=g+aRv5t<8moHzQGiMG52U}TL*^V7MPMkQAl$11e z>eQPzZ|3FYty;C}(W6J&+FFW=ir(Jd*4EYy4GkO|j6p$xZ+CiLV_;zXj= z-rN0~J_~Pp|8zpz{@*;TkL$$w{0!voCK$v|Gb@-Dw?NQtx_-H|9#+ zXE%4QsI7cr5ZmCWvVDK0a&7H3{B+B&67dBK$VN0+dl zP4+owd?q~job&gz@(Htwn?fWVI({E{3hdXA}e0G zwf(MrzGBgzUdx`aIAccNtZO;#zpnJ1F;<_{{dd#MWz+Ug-hVOeIlFcy$FrGtt+tyN#7{2Xv#Fz5{4Q6mxRK(j==~d3)=#^yKTChPa_r3sLdmDk#s}}S zoH}(ws)n%nvLEYalr7GGxxl}wb5V@rx?L4{yg5lP6)U%frfqMkdAUk-SJT;p>yoyo z+E#kC+e)(=n;l&e?-*zH{nx1}*Ppo9i&bg-+4hU+XHoLS`QE%Q!^%4^@J_5ee0p8f zjiBhuTc!m4+O@Gy^l8fc)jUg=KaKm#{Il2S*SS-R^Z&Wc-DO$y = ({ navigation, route }) => { } }; + const addImageToEditor = (imageUri: string) => { + richTextRef.current?.insertImage(imageUri); + }; + const saveNote = async () => { if (titleText === "") { navigation.goBack(); @@ -194,7 +198,7 @@ const AddNoteScreen: React.FC = ({ navigation, route }) => { - + {viewAudio && ( )} @@ -310,6 +314,7 @@ const AddNoteScreen: React.FC = ({ navigation, route }) => { + ); };