Skip to content

Commit

Permalink
Merge pull request #73 from oss-slu/InlineMediaIssue
Browse files Browse the repository at this point in the history
Made a comment on what appears to be where changes are needed at first glance
  • Loading branch information
yashb196 authored Sep 29, 2023
2 parents 0fece48 + c39b360 commit d466d97
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
30 changes: 30 additions & 0 deletions __tests__/InsertImageNoteScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -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(<AddNoteScreen />);

// 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);
});
});
Binary file added __tests__/TestResources/TestImage.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions lib/components/photoScroller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ const PhotoScroller = forwardRef(
newMedia,
setNewMedia,
active,
insertImageToEditor,
}: {
newMedia: Media[];
setNewMedia: React.Dispatch<React.SetStateAction<Media[]>>;
active: Boolean;
insertImageToEditor: Function;
},
ref
) => {
Expand Down Expand Up @@ -83,6 +85,7 @@ const PhotoScroller = forwardRef(
uri: uploadedUrl,
});
setNewMedia([...newMedia, newMediaItem]);
insertImageToEditor(uploadedUrl);
} else if (
uri.endsWith(".jpg") ||
uri.endsWith("png") ||
Expand All @@ -96,6 +99,9 @@ const PhotoScroller = forwardRef(
uri: uploadedUrl,
});
setNewMedia([...newMedia, newMediaItem]);
if (insertImageToEditor) {
insertImageToEditor(uploadedUrl, 'Captured Image');
}
} else if (
uri.endsWith(".MOV") ||
uri.endsWith(".mov") ||
Expand Down
7 changes: 6 additions & 1 deletion lib/screens/AddNoteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ const AddNoteScreen: React.FC<AddNoteScreenProps> = ({ navigation, route }) => {
}
};

const addImageToEditor = (imageUri: string) => {
richTextRef.current?.insertImage(imageUri);
};

const saveNote = async () => {
if (titleText === "") {
navigation.goBack();
Expand Down Expand Up @@ -195,7 +199,7 @@ const AddNoteScreen: React.FC<AddNoteScreenProps> = ({ navigation, route }) => {
</TouchableOpacity>
</View>
<View style={{ backgroundColor: "white" }}>
<PhotoScroller active={viewMedia} newMedia={newMedia} setNewMedia={setNewMedia} />
<PhotoScroller active={viewMedia} newMedia={newMedia} setNewMedia={setNewMedia} insertImageToEditor={addImageToEditor} />
{viewAudio && (
<AudioContainer newAudio={newAudio} setNewAudio={setNewAudio} />
)}
Expand Down Expand Up @@ -311,6 +315,7 @@ const AddNoteScreen: React.FC<AddNoteScreenProps> = ({ navigation, route }) => {
</ScrollView>
</View>
</View>

);
};

Expand Down
9 changes: 9 additions & 0 deletions lib/screens/EditNoteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -34,6 +35,7 @@ const user = User.getInstance();
const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
route,
navigation,
insertImageToEditor,
}) => {
const { note, onSave } = route.params;
const [title, setTitle] = useState(note.title);
Expand Down Expand Up @@ -116,6 +118,11 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
}
};

const addImageToEditor = (imageUri: string) => {
richTextRef.current?.insertImage(imageUri);
};


const handleSaveNote = async () => {
try {
const editedNote: Note = {
Expand Down Expand Up @@ -239,6 +246,7 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
active={viewMedia}
newMedia={media}
setNewMedia={setMedia}
insertImageToEditor={addImageToEditor}
/>
{viewAudio && (
<AudioContainer newAudio={newAudio} setNewAudio={setNewAudio} />
Expand Down Expand Up @@ -372,6 +380,7 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
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);
}}
Expand Down
1 change: 1 addition & 0 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type EditNoteScreenProps = {
navigation: {
goBack: () => void;
};
insertImageToEditor: (capturedImage: string) => void;
};

export type RootTabParamList = {
Expand Down

0 comments on commit d466d97

Please sign in to comment.