Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made a comment on what appears to be where changes are needed at first glance #73

Merged
merged 4 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -28,10 +28,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 @@ -81,6 +83,7 @@ const PhotoScroller = forwardRef(
uri: uploadedUrl,
});
setNewMedia([...newMedia, newMediaItem]);
insertImageToEditor(uploadedUrl);
} else if (
uri.endsWith(".jpg") ||
uri.endsWith("png") ||
Expand All @@ -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") ||
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 @@ -194,7 +198,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 @@ -310,6 +314,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
Loading