import React, { useEffect, useState } from 'react';
import { View, Text, Button, FlatList, Alert, TextInput, Modal, StyleSheet } from 'react-native';
import * as SQLite from 'expo-sqlite';
const db = SQLite.openDatabase('notes.db');
export default function NotesList() {
const [notes, setNotes] = useState([]);
const [modalVisible, setModalVisible] = useState(false);
const [newNote, setNewNote] = useState('');
useEffect(() => {
// TODO: Create notes table if not exists
// TODO: Load notes from database
}, []);
const addNote = () => {
// TODO: Insert newNote into database
// TODO: Refresh notes list
// TODO: Close modal and clear input
};
return (
<View style={{ flex: 1, padding: 20 }}>
<Button title='+ Add Note' onPress={() => setModalVisible(true)} />
<FlatList
data={notes}
keyExtractor={(item) => item.id.toString()}
renderItem={({ item }) => <Text style={{ padding: 10 }}>- {item.text}</Text>}
/>
<Modal visible={modalVisible} animationType='slide' transparent={true}>
<View style={styles.modalView}>
<TextInput
placeholder='Enter note'
value={newNote}
onChangeText={setNewNote}
style={styles.input}
/>
<Button title='Save' onPress={addNote} />
<Button title='Cancel' onPress={() => setModalVisible(false)} />
</View>
</Modal>
</View>
);
}
const styles = StyleSheet.create({
modalView: {
margin: 20,
backgroundColor: 'white',
borderRadius: 8,
padding: 20,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
flex: 1,
justifyContent: 'center'
},
input: {
borderWidth: 1,
borderColor: '#ccc',
padding: 10,
marginBottom: 10,
borderRadius: 4
}
});