import { StyleSheet, Text, View, Pressable, Alert } from 'react-native'
import SwipeableFlatList from 'react-native-swipeable-list'
import { useState, useEffect } from 'react'
import Note from './Note'
import Menu from './Menu'
const List = ({ session, setSession, showError, setEdit }) => {
const [list, setList] = useState()
const [loading, setLoading] = useState(true)
const fetchNotes = async () => {
setLoading(true)
try {
const response = await fetch('https://apps.pruss.it/api/notes', { 'Cookie': session.cookies } )
const data = await response.json()
setList(data)
} catch(e) {
showError('Error while fetching notes')
}
setLoading(false)
}
useEffect(() => {
setLoading(true)
fetchNotes()
}, [])
const deleteNote = async (note) => {
setLoading(true)
try {
await fetch(`https://apps.pruss.it/api/notes/${note._id}`, {
method: 'DELETE', headers: { 'Cookie': session.cookies },
})
fetchNotes()
} catch(e) {
showError('Error while removing note')
} finally {
setLoading(false)
}
}
const deleteItem = note => {
Alert.alert(
'Are you sure?',
`Note "${note.title}" will be permanently removed`,
[
{
text: 'Remove',
onPress: () => deleteNote(note),
style: 'destructive',
},
{
text: 'Cancel',
onPress: () => {},
style: 'cancel',
},
],
);
};
const removeBtn = (note) => {
return (