import React, { useState, useRef, useEffect } from "react"; import { Animated, Easing,…
- User
import React, { useState, useRef, useEffect } from "react"; import { Animated, Easing, View, Text, TouchableOpacity, Image, Alert } from "react-native"; import { styles } from "./addNoteStyle"; import { useDispatch, useSelector } from "react-redux"; import {setTitle,setNote,setImageUrl,setAudioUrl,resetAddNoteState} from "../../store/addNoteSlice"; import { selectAddNote } from '../../store/addNoteSlice'; import { collection, addDoc, setDoc, doc, serverTimestamp } from "firebase/firestore"; import { firebaseDb } from "../../../firebaseConfig"; import { getStorage, ref, uploadString, getDownloadURL } from "firebase/storage"; import { Entypo, Feather, AntDesign } from "@expo/vector-icons"; import { RichEditor, RichToolbar, actions } from "react-native-pell-rich-editor"; import * as ImagePicker from 'expo-image-picker'; import { Audio } from "expo-av"; import { useFocusEffect } from "@react-navigation/native";
const AddNote = ({ navigation, route }) => { const titleEditorRef = useRef(null); const noteEditorRef = useRef(null);
const { title, note, imageUrl, audioUrl } = useSelector(selectAddNote); const dispatch = useDispatch(); const [recording, setRecording] = useState(); const [isRecording, setIsRecording] = useState(false); const [isPlaying, setIsPlaying] = useState(false); const [isEditing, setIsEditing] = useState(false); const [recordedAudios, setRecordedAudios] = useState([]); const [currentlyPlayingIndex, setCurrentlyPlayingIndex] = useState(null); const [soundObject, setSoundObject] = useState(null);
const [opacityValue] = useState(new Animated.Value(1));
const startRecordingAnimation = () => { Animated.loop( Animated.timing( opacityValue, { toValue: 0, duration: 800, easing: Easing.linear, useNativeDriver: true } ) ).start(); };
const stopRecordingAnimation = () => { Animated.timing( opacityValue, { toValue: 1, duration: 800, easing: Easing.linear, useNativeDriver: true } ).start(); };
useEffect(() => { if (isRecording) { startRecordingAnimation(); } else { stopRecordingAnimation(); } }, [isRecording]);
useEffect(() => { if (route.params && route.params.noteData) { const { title, note, image, audio } = route.params.noteData; dispatch(setTitle(title || "")); dispatch(setNote(note || "")); dispatch(setImageUrl(image || "")); dispatch(setAudioUrl(audio || "")); setIsEditing(true); } else { dispatch(resetAddNoteState()); } }, [route.params]);
useEffect(() => { return () => { dispatch(resetAddNoteState()); }; }, []);
// useFocusEffect( // React.useCallback(() => { // const clearEditorContent = () => { // titleEditorRef.current?.setContentHTML(''); // noteEditorRef.current?.setContentHTML(''); // };
// clearEditorContent();
// return () => {
// }; // }, []) // );
const handleTitleChange = (text) => { dispatch(setTitle(text)); };
const handleNoteChange = (text) => { dispatch(setNote(text)); };
- Assistant