|
1 | 1 | import React from 'react';
|
2 |
| -import {StyleSheet, Text, TextBase, View} from 'react-native'; |
| 2 | +import { |
| 3 | + FlatList, |
| 4 | + StyleSheet, |
| 5 | + Text, |
| 6 | + TextInput, |
| 7 | + TouchableOpacity, |
| 8 | + View, |
| 9 | +} from 'react-native'; |
3 | 10 | import {SafeAreaView} from 'react-native-safe-area-context';
|
4 |
| -import {Header} from '../../common/components/'; |
5 |
| -import config from '../../config'; |
6 | 11 | import {optimizeHeavyScreen} from 'react-navigation-heavy-screen';
|
7 | 12 | import {useQuery} from 'react-query';
|
8 | 13 | import {HomeApi} from '../../common/apis';
|
9 |
| - |
| 14 | +import {ColorDefault} from '../../common/themes/colors'; |
| 15 | +import {MaterialCommunityIcons, MaterialIcons} from '@expo/vector-icons'; |
| 16 | +import {scale, verticalScale} from '../../common/helpers'; |
10 | 17 | const HomeScreen = () => {
|
11 | 18 | const fetchDataList = () => HomeApi.fetchData(1, 10);
|
12 | 19 | const {isLoading, isError, data, error} = useQuery(
|
13 | 20 | 'homeLists',
|
14 | 21 | fetchDataList,
|
15 | 22 | );
|
16 | 23 |
|
| 24 | + const ListItem = ({todo}: any) => { |
| 25 | + return ( |
| 26 | + <View style={styles.listItem}> |
| 27 | + <View style={{flex: 1}}> |
| 28 | + <Text |
| 29 | + style={{ |
| 30 | + fontWeight: 'bold', |
| 31 | + fontSize: 15, |
| 32 | + color: ColorDefault.primary, |
| 33 | + // textDecorationLine: todo?.completed ? 'line-through' : 'none', |
| 34 | + }}> |
| 35 | + {todo?.title} |
| 36 | + </Text> |
| 37 | + </View> |
| 38 | + {/* {!todo?.completed && ( */} |
| 39 | + <TouchableOpacity |
| 40 | + // onPress={() => markTodoComplete(todo.id)} |
| 41 | + > |
| 42 | + <View style={[styles.actionIcon, {backgroundColor: 'green'}]}> |
| 43 | + <MaterialIcons name="done" size={20} color="white" /> |
| 44 | + </View> |
| 45 | + </TouchableOpacity> |
| 46 | + {/* )} */} |
| 47 | + <TouchableOpacity |
| 48 | + // onPress={() => deleteTodo(todo.id)} |
| 49 | + > |
| 50 | + <View style={styles.actionIcon}> |
| 51 | + <MaterialCommunityIcons name="delete" size={25} color="red" /> |
| 52 | + </View> |
| 53 | + </TouchableOpacity> |
| 54 | + </View> |
| 55 | + ); |
| 56 | + }; |
| 57 | + if (isLoading) return <Text>'Loading...'</Text>; |
| 58 | + |
| 59 | + if (error) return <Text>'An error has occurred: ' </Text>; |
| 60 | + |
17 | 61 | return (
|
18 |
| - <SafeAreaView style={{flex: 1}}> |
19 |
| - <Header title="Header" backEnabled={true} /> |
20 |
| - <View style={styles.container}> |
21 |
| - <Text>{config.BASE_URL}</Text> |
| 62 | + <SafeAreaView |
| 63 | + style={{ |
| 64 | + flex: 1, |
| 65 | + backgroundColor: 'white', |
| 66 | + }}> |
| 67 | + <View style={styles.header}> |
| 68 | + <Text |
| 69 | + style={{ |
| 70 | + fontWeight: 'bold', |
| 71 | + fontSize: 20, |
| 72 | + color: ColorDefault.primary, |
| 73 | + }}> |
| 74 | + TODO APP |
| 75 | + </Text> |
| 76 | + <MaterialCommunityIcons |
| 77 | + onPress={() => console.log('delete')} |
| 78 | + name="delete" |
| 79 | + size={25} |
| 80 | + color="red" |
| 81 | + /> |
| 82 | + </View> |
| 83 | + <View> |
| 84 | + <FlatList |
| 85 | + data={data.data.entries} |
| 86 | + renderItem={({item}) => <ListItem todo={item} />} |
| 87 | + /> |
| 88 | + </View> |
| 89 | + |
| 90 | + <View style={styles.footer}> |
| 91 | + <View style={styles.inputContainer}> |
| 92 | + <TextInput |
| 93 | + // value={textInput} |
| 94 | + placeholder="Add Todo" |
| 95 | + // onChangeText={text => setTextInput(text)} |
| 96 | + /> |
| 97 | + </View> |
| 98 | + <TouchableOpacity> |
| 99 | + <View style={styles.iconContainer}> |
| 100 | + <MaterialIcons name="add" size={30} color="white" /> |
| 101 | + </View> |
| 102 | + </TouchableOpacity> |
22 | 103 | </View>
|
23 | 104 | </SafeAreaView>
|
24 | 105 | );
|
25 | 106 | };
|
26 | 107 | const styles = StyleSheet.create({
|
27 |
| - container: { |
| 108 | + footer: { |
| 109 | + position: 'absolute', |
| 110 | + bottom: verticalScale(40), |
| 111 | + width: '100%', |
| 112 | + flexDirection: 'row', |
| 113 | + alignItems: 'center', |
| 114 | + paddingHorizontal: 20, |
| 115 | + backgroundColor: ColorDefault.navigationBar, |
| 116 | + }, |
| 117 | + inputContainer: { |
| 118 | + height: verticalScale(50), |
| 119 | + paddingHorizontal: 20, |
| 120 | + elevation: 40, |
| 121 | + backgroundColor: ColorDefault.navigationBar, |
28 | 122 | flex: 1,
|
29 |
| - backgroundColor: '#81ecec', |
| 123 | + marginVertical: 20, |
| 124 | + marginRight: 20, |
| 125 | + borderRadius: 30, |
| 126 | + }, |
| 127 | + iconContainer: { |
| 128 | + height: 50, |
| 129 | + width: 50, |
| 130 | + backgroundColor: ColorDefault.primary, |
| 131 | + elevation: 40, |
| 132 | + borderRadius: 25, |
| 133 | + justifyContent: 'center', |
30 | 134 | alignItems: 'center',
|
| 135 | + }, |
| 136 | + |
| 137 | + listItem: { |
| 138 | + padding: 20, |
| 139 | + backgroundColor: ColorDefault.navigationBar, |
| 140 | + flexDirection: 'row', |
| 141 | + elevation: 12, |
| 142 | + borderRadius: 7, |
| 143 | + marginVertical: 10, |
| 144 | + }, |
| 145 | + actionIcon: { |
| 146 | + height: verticalScale(25), |
| 147 | + width: scale(25), |
| 148 | + backgroundColor: ColorDefault.navigationBar, |
31 | 149 | justifyContent: 'center',
|
| 150 | + alignItems: 'center', |
| 151 | + // backgroundColor: 'red', |
| 152 | + marginLeft: 5, |
| 153 | + borderRadius: 3, |
| 154 | + }, |
| 155 | + header: { |
| 156 | + padding: 20, |
| 157 | + flexDirection: 'row', |
| 158 | + alignItems: 'center', |
| 159 | + justifyContent: 'space-between', |
32 | 160 | },
|
33 | 161 | });
|
| 162 | + |
34 | 163 | export default optimizeHeavyScreen(HomeScreen);
|
0 commit comments