File size: 3,598 Bytes
6d44341 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | import React, {useState} from 'react';
import {View, Text, StyleSheet, FlatList, TouchableOpacity, Alert, Modal} from 'react-native';
import {Ionicons} from '@expo/vector-icons';
import {TodosModal} from "./Todos";
import {useDB} from "../context/DBcontex";
import moment from "moment";
export const Header = () => {
return (
<View style={{backgroundColor: '#1C2833', paddingTop: 25}}>
<View style={{flexDirection: 'row', alignItems: 'center', justifyContent: 'center',}}>
<Text style={styles.todo}>Todo</Text>
<Text style={styles.list}>List</Text>
</View>
<View style={{alignSelf: 'flex-end', marginRight: 5}}>
<Text style={{color: 'grey'}}>by Jesse</Text>
</View>
</View>
)
}
export const HomeScreen = () => {
const [showModal, setShowModal] = useState(false)
const [currentList, setCurrentList] = useState({})
const {lists, deleteList, loading} = useDB()
if (loading) {
return (
<View>
<Text>Loading</Text>
</View>
)
}
const toggleModal = (listData = null) => {
setCurrentList(listData)
setShowModal(prev => !prev)
}
const onDelete = async (list) => {
await deleteList(list)
}
const OneListCard = ({item}) => (
<TouchableOpacity onPress={() => {toggleModal(item)}}>
<View style={[styles.item, {backgroundColor: item.color}]}>
<View style={{flex: 1}}>
<Text style={{fontSize: 27, alignSelf: 'center', fontWeight: 'bold'}}>{item.title}</Text>
<View style={{
flexDirection: 'row',
justifyContent: 'center',
paddingHorizontal: 1,
marginTop: 10}}>
<Text style={{fontSize: 12}}>{moment(item.createdAt.toDate()).calendar()}</Text>
</View>
</View>
<TouchableOpacity style={{alignItems: 'center', justifyContent: 'center'}}
onPress={() => onDelete(item)}>
<Ionicons name="trash-outline" size={41} color="#fb634c"/>
</TouchableOpacity>
</View>
</TouchableOpacity>
);
return (
<View style={styles.container}>
<Modal
animationType="slide"
visible={showModal}
onRequestClose={() => {toggleModal()}}>
<TodosModal closeModal={() => toggleModal()} data={currentList}/>
</Modal>
<FlatList
style={styles.flatList}
data={lists}
renderItem={({item}) => <OneListCard item={item}/>}
keyExtractor={(item) => item.title}
showsVerticalScrollIndicator={false}
/>
</View>
)
}
const styles = StyleSheet.create({
item: {
flexDirection: 'row',
borderRadius: 10,
paddingVertical: 12,
paddingHorizontal: 5,
marginHorizontal: 50,
marginTop: 20,
},
flatList: {},
todo: {
fontSize: 30,
fontWeight: 'bold',
color: 'grey'
},
list: {
fontSize: 30,
color: '#53abbf'
},
header: {
borderWidth: 2,
flexDirection: 'row',
marginTop: 20,
alignItems: 'center',
justifyContent: 'center'
},
container: {
flex: 1,
backgroundColor: '#14141c'
}
})
|