Browse Source

clean calendar view

José C.S. Curet 1 year ago
parent
commit
a4836af648
1 changed files with 17 additions and 175 deletions
  1. 17
    175
      screens/calendar.js

+ 17
- 175
screens/calendar.js View File

@@ -6,183 +6,38 @@ import { Agenda, calendarTheme } from 'react-native-calendars';
6 6
 import { Ionicons } from '@expo/vector-icons';
7 7
 import { ProgressBar, MD3Colors } from 'react-native-paper';
8 8
 
9
-// react hooks, useState and useEffect
10
-
11 9
 const userslist = 'https://ada.uprrp.edu/~pablo.puig1/TPMG/userslist.php'
12 10
 const eventlist = 'https://ada.uprrp.edu/~pablo.puig1/TPMG/eventslist.php'
13 11
 
14 12
 export default function Calendario({ navigation }) {
15 13
 
16
-  // state = {
17
-  //   array: []
18
-  // }
19 14
   const [eventos, setEventos] = useState({});
20 15
 
21 16
   useEffect(() => {
22 17
     fetch(eventlist)
23 18
       .then(response => response.json())
24 19
       .then(dat => setEventos(dat))
25
-        // this.setState({ array: response })
26
-        // state.array = response
27
-        // console.log(response)
28
-      // );
29
-      // console.log(state.array)
30
-      // state.array = array
31 20
       .catch(error => console.error(error))
32 21
   }, []);
33 22
 
34
-  {/*
35
-      TODO: Convert array of dictionary into a dictionary of dictionary where the keys are the `startDate
36
-
37
-  */}
38
-
39
-  var events = {}
40
-  // console.log('array: ', this.state.array)
41
-
42
-  // {this.state.array.map(value => {
43
-  //   console.log('value: ', value)
44
-  //   events[value.startDate] = [{  // this have a problem because we can have multiple events in the same date, so it is not a best key
45
-  //     'id' : value.id,
46
-  //     'activityDescription' : value.activityDescription,
47
-  //     'subscribed' : value.subscribed,
48
-  //     'icon' : value.icon,
49
-  //     'totalSubscribed' : value.totalSubscribed,
50
-  //     'maxSubscribed' : value.maxSubscribed
51
-  //   }]
52
-  // });}
53
-
54
-  // console.log('events: ', events);
55
-
56
-
57
-  // getMoviesFromApi();
58
-
59
-  // const [dates, setDates] = useState([
60
-  //   {
61
-  //     date: '2022-12-06',
62
-  //     items: [1, 2, 3]
63
-  //   },
64
-  //   {
65
-  //     date: '2022-12-07',
66
-  //     items: [1, 2, 3]
67
-  //   }
68
-  // ]);
69
-
70
-  // const [items, setItems] = useState([
71
-  //   {id: '1', date: '2022-12-06',  name: 'matricula', sub: false, count: 10, max: 10}
72
-  // ])
73
-
74
-  // TODO 1: make sure more than one activity on the same date appears on screen
75
-  // TO SOLVE: Two items of the same date, just the last item appear
76
-  // TODO 2: make can we add images as part of the item? (this is more advanced, which could be implemented in the future)
77
-
78
-  const [items, setItems] = useState({
79
-    '2022-12-21': [{
80
-      id: '1',
81
-      activityDescription: 'aaaa',
82
-      subscribed: false,
83
-      icon: 'person-add-outline',
84
-      totalSubscribed: 10,
85
-      maxSubscribed: 10 }],
86
-    '2022-12-22':[{
87
-      id: '2',
88
-      activityDescription: 'Actividad de cocina para la comunidad de Santa Rita, Río Piedras 🍲',
89
-      subscribed: false,
90
-      icon: 'person-add-outline',
91
-      totalSubscribed: 3, 
92
-      maxSubscribed: 7 }],
93
-    '2022-12-23': [{
94
-      id: '3',
95
-      activityDescription: 'Taller de aprendizaje de construcción de techos 🏠',
96
-      subscribed: false,
97
-      icon: 'person-add-outline',
98
-      totalSubscribed: 7,
99
-      maxSubscribed: 7 }],
100
-    '2022-12-24': [],
101
-  });
102
-
103
-  const [data, setData] = useState({data});
104
-
105
-  const [selectedIcon, setSelectedIcon] = useState('person-add-outline');
106
-
107 23
   const formattedEvents = Object.keys(eventos).reduce((result, key) => {
108 24
     const item = eventos[key];
109 25
     const date = item.startDate;
110
-    // result[date] = item;
111
-    if (result[date]){
112
-      result[date].push(item);
113
-    }else{
114
-      result[date] = [item];
115
-    }
26
+    if (result[date]){ result[date].push(item);}
27
+    else{result[date] = [item];}
116 28
     return result;
117 29
   }, {});
118 30
 
119
-  // const [current, setCurrent] = useState({formattedEvents});
120
-
121
-  console.log(formattedEvents)
122
-  console.log(items)
123
-
124
- const onButtonClick = useCallback((itemClicked) => {
125
-   // [1]. change selected icon sub status from false to true or vice versa
126
-   // [2]. change icon from 'person-add-outline' to 'person-sharp' or vice versa
127
-
128
-   {
129
-     Object.keys(items).map(key => {
130
-       items[key].map(item => {
131
-         // alert(item.id)
132
-         if (item.id === itemClicked.id) {
133
-            // alert(item.icon)
134
-           // alert(item.sub)
135
-             return{
136
-              ...item,
137
-              subscribed: true, //item.sub === false ? true : false,
138
-              icon: 'person-sharp' //item.icon === 'person-add-outline' ? 'person-sharp' : 'person-add-outline'
139
-           }
140
-
141
-           // setSelectedIcon(selectedIcon === 'person-add-outline' ? 'person-sharp' : 'person-add-outline')
142
-         }
143
-         else{
144
-           return item
145
-         }
146
-        //  {items[key].id}
147
-       })
148
-
149
-     })
150
-   }
151
-
152
- }, [setItems]);
153
-  
154
-
155
-
156
-//     const onButtonClick = useCallback((itemClicked) => {
157
-        
158
-//         Object.keys(items).map(key => {
159
-//             items[key].map(item => {
160
-
161
-//                 const id = itemClicked
162
-//                 alert(id)
163
-
164
-//                 if (item.id === itemClicked.id) {
165
-// //                    alert(item.id)
166
-// //                    if (typeof items[key] === 'object'){
167
-//                         setItems({
168
-//                             ...items,
169
-//                         sub: !item.sub, //item.sub === false ? true : false,
170
-//                         icon: 'person-sharp' // item.icon === 'person-add-outline' ? 'person-sharp' : 'person-add-outline'
171
-//                         });
172
-// //                    }
173
-//                 }
174
-//             })
175
-//         })
176
-//     }, [setItems]);
177
-
178
-
179 31
   function renderItem(item) {
180 32
     console.log('item.activityDescription: ', item.activityDescription)
181 33
     return (
182 34
       <View>
183 35
           <View style={[styles.item, { height: item.height }]}>
184
-            <Text> {item.activityDescription}</Text>
185
-            {/* <Text> {data.title}</Text> */}
36
+            <View>
37
+              <Text style = {[styles.activity_name]}> {item.activityName}</Text>
38
+              <Text style = {[styles.time]}> 10:00AM-2:00PM</Text>
39
+              <Text style = {[styles.activity_description]}> {item.activityDescription}</Text>
40
+            </View>
186 41
             {/* <TouchableOpacity onPress={() => onButtonClick(item)}> */}
187 42
             <TouchableOpacity onPress={() => alert("Te has subcrito a la actividad!")}>
188 43
                 <Ionicons name={item.icon} />
@@ -197,34 +52,11 @@ export default function Calendario({ navigation }) {
197 52
   return (
198 53
     <Agenda
199 54
       items={formattedEvents}
200
-      // items={items}
201
-      // item={current}
202
-      // items={state.array}
203
-      // data={data}
204 55
       renderItem={renderItem}
205
-      // renderItem={(eventos, eventos.startDate)}
206 56
     />
207 57
   );
208
-
209
-
210
-  // return (
211
-  //   <Agenda
212
-  //         items={current}
213
-  //         renderItem={(item, firstItemInDay) => {
214
-  //           return (
215
-  //             <View>
216
-  //               <Text>{item.activityName}</Text>
217
-  //               <Text>{item.startDate}</Text>
218
-  //             </View>
219
-  //           );
220
-  //         }}
221
-  //       />
222
-  // );
223
-
224
-
225 58
 }
226 59
 
227
-
228 60
 const styles = StyleSheet.create({
229 61
   container: {
230 62
     padding: 24
@@ -238,6 +70,16 @@ const styles = StyleSheet.create({
238 70
     marginRight: 10,
239 71
     marginTop: 32
240 72
   },
73
+  activity_name :{
74
+    // fontFamily : 'sans-serif',
75
+    fontSize : 25,
76
+  },
77
+  time : {
78
+    // fontWeight: 'bold'
79
+  },
80
+  activity_description : {
81
+    fontSize : 16,
82
+  },
241 83
   progress: {
242 84
     height: 5,
243 85
     width: 355.2 // this is harcoded and need to be calculated based on the previous View width