Skip to content

Commit

Permalink
Implemented MainPage template and AddPage template Ref #18
Browse files Browse the repository at this point in the history
  • Loading branch information
rhit-villencr committed Oct 20, 2024
1 parent 7cb17ba commit 63632a6
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 386 deletions.
46 changes: 3 additions & 43 deletions app/addFinanceEvents.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import React, { useState } from 'react';
import { View, Text, TouchableOpacity, TextInput } from 'react-native';
import { styles } from './styles';
import { Ionicons } from "@expo/vector-icons";
import { Dropdown } from 'react-native-element-dropdown';
import React from 'react';
import axios from 'axios';
import DateTimePicker from '@react-native-community/datetimepicker';
import { IPAddr } from './constants';
import { useNavigation } from '@react-navigation/native';
import GenericAddPageForm from './addEventPage';
Expand All @@ -22,7 +17,6 @@ export default function AddFinanceEvents() {
type AddFinanceTrackerNavigationProp = StackNavigationProp<RootStackParamList, 'addFinanceEvents'>;
const navigation = useNavigation<AddFinanceTrackerNavigationProp>();

const [value, setValue] = useState<string | null>(null);
const fields = [
{ name: 'title', label: 'Title', type: 'text' },
{ name: 'event_date', label: 'Date', type: 'date' },
Expand All @@ -31,7 +25,6 @@ export default function AddFinanceEvents() {
{ name: 'money', label: 'Money', type: 'number' }
];


const initialData = {
user_id: 1,
title: '',
Expand All @@ -42,49 +35,16 @@ export default function AddFinanceEvents() {
money: 0.0
}

const [eventData, setEventData] = useState({
user_id: 1,
title: '',
event_date: new Date(),
event_time: new Date(),
repeating: false,
repeat_timeline: '',
money: 0.0
});


const handleChange = (name: string, value: any) => {
setEventData({ ...eventData, [name]: value });
};

const handleSave = async () => {
const formattedData = {
...eventData,
event_date: eventData.event_date.toISOString().split('T')[0],
event_time: eventData.event_time.toTimeString().split(' ')[0],
};

const handleSave = async (saveData: any) => {
try {
const response = await axios.post(IPAddr + '/add_finance_events', formattedData);
const response = await axios.post(IPAddr + '/add_finance_events', saveData);
console.log('Event saved successfully:', response.data);
} catch (error) {
console.error('Error saving event:', error);
}
navigation.navigate('finance')
};

const handleDateChange = (event: any, selectedDate: any) => {
if (selectedDate) {
handleChange('event_date', selectedDate);
}
};

const handleTimeChange = (event: any, selectedTime: any) => {
if (selectedTime) {
handleChange('event_time', selectedTime);
}
};

const handleCancel = (() => {
navigation.navigate('finance')
})
Expand Down
50 changes: 13 additions & 37 deletions app/addHealthEvents.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import React, { useState } from 'react';
import { View, TextInput, Text, TouchableOpacity } from 'react-native';
import { styles } from './styles';
import { Ionicons } from "@expo/vector-icons";
import { Dropdown } from 'react-native-element-dropdown';
import React from 'react';
import { IPAddr } from './constants';
import axios from 'axios';
import DateTimePicker from '@react-native-community/datetimepicker';
import { StackNavigationProp } from '@react-navigation/stack';
import { useNavigation } from '@react-navigation/native';
import GenericAddPageForm from './addEventPage';
Expand All @@ -22,7 +17,6 @@ export default function AddHealthEvents() {
type AddHealthEventNavProp = StackNavigationProp<RootStackParamList, 'addCalendarEvents'>;
const navigation = useNavigation<AddHealthEventNavProp>();

const [value, setValue] = useState<string | null>(null);
const initialData = {
user_id: 1,
title: '',
Expand All @@ -31,47 +25,29 @@ export default function AddHealthEvents() {
repeating: false,
repeat_timeline: ''
}
const [eventData, setEventData] = useState({
user_id: 1,
title: '',
event_date: new Date(),
event_time: new Date(),
repeating: false,
repeat_timeline: ''
});

const handleChange = (name: string, value: any) => {
setEventData({ ...eventData, [name]: value });
};
const fields = [
{ name: 'title', label: 'Title', type: 'text' },
{ name: 'event_date', label: 'Date', type: 'date' },
{ name: 'event_time', label: 'Time', type: 'time' },
{ name: 'repeat_timeline', label: 'Repeating', type: 'dropdown', options: data },
{ name: 'description', label: 'Description', type: 'textarea' },
];

const handleSave = async () => {
const formattedData = {
...eventData,
event_date: eventData.event_date.toISOString().split('T')[0],
event_time: eventData.event_time.toTimeString().split(' ')[0],
};
const handleCancel = () => {
navigation.navigate('healthTracker')
}

const handleSave = async (saveData: any) => {
try {
const response = await axios.post(IPAddr + '/add_health_events', formattedData);
const response = await axios.post(IPAddr + '/add_health_events', saveData);
console.log('Event saved successfully:', response.data);
} catch (error) {
console.error('Error saving event:', error);
}
navigation.navigate('healthTracker')
};

const handleDateChange = (event: any, selectedDate: any) => {
if (selectedDate) {
handleChange('event_date', selectedDate);
}
};

const handleTimeChange = (event: any, selectedTime: any) => {
if (selectedTime) {
handleChange('event_time', selectedTime);
}
};

return (
<GenericAddPageForm
title="New Health Event"
Expand Down
51 changes: 12 additions & 39 deletions app/addMeals.tsx
Original file line number Diff line number Diff line change
@@ -1,69 +1,43 @@
import React, { useState } from 'react';
import { View, TextInput, Text, TouchableOpacity } from 'react-native';
import { styles } from './styles';
import { Ionicons } from "@expo/vector-icons";
import React from 'react'
import axios from 'axios';
import { IPAddr } from './constants';
import DateTimePicker from '@react-native-community/datetimepicker';
import { RootStackParamList } from '../components/Types';
import { useNavigation } from '@react-navigation/native';
import GenericAddPageForm from './addEventPage';
import { StackNavigationProp } from '@react-navigation/stack';


export default function AddMeals() {
type CalendarTrackerNavigationProp = StackNavigationProp<RootStackParamList, 'addMeals'>;
const navigation = useNavigation<CalendarTrackerNavigationProp>();
type AddMealTrackerNavigationProp = StackNavigationProp<RootStackParamList, 'addMeals'>;
const navigation = useNavigation<AddMealTrackerNavigationProp>();

const [eventData, setEventData] = useState({
const initialData = {
user_id: 1,
title: '',
event_date: new Date(),
event_time: new Date(),
});

const handleChange = (name: string, value: any) => {
setEventData({ ...eventData, [name]: value });
};

const handleSave = async () => {
const formattedData = {
...eventData,
event_date: eventData.event_date.toISOString().split('T')[0],
event_time: eventData.event_time.toTimeString().split(' ')[0],
};
const fields = [
{ name: 'title', label: 'Title', type: 'text' },
{ name: 'event_date', label: 'Date', type: 'date' },
{ name: 'event_time', label: 'Time', type: 'time' },
];

const handleSave = async (saveData: any) => {
try {
const response = await axios.post(IPAddr + '/add_meal_events', formattedData);
const response = await axios.post(IPAddr + '/add_meal_events', saveData);
console.log('Event saved successfully:', response.data);
} catch (error) {
console.error('Error saving event:', error);
}
navigation.navigate('mealTracker')
};

const handleDateChange = (event: any, selectedDate: any) => {
if (selectedDate) {
handleChange('event_date', selectedDate);
}
};

const handleCancel = (() => {
navigation.navigate('mealTracker')
})

const initialData = {
user_id: 1,
title: '',
event_date: new Date(),
event_time: new Date(),
};

const fields = [
{ name: 'title', label: 'Title', type: 'text' },
{ name: 'event_date', label: 'Date', type: 'date' },
{ name: 'event_time', label: 'Time', type: 'time' },
];
})

return (
<GenericAddPageForm
Expand All @@ -76,4 +50,3 @@ export default function AddMeals() {
);
};


94 changes: 14 additions & 80 deletions app/finance.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import React, { useState, useEffect } from 'react';
import { View, Text, FlatList, TouchableOpacity } from 'react-native';
import BouncyCheckbox from "react-native-bouncy-checkbox";
import { Calendar } from 'react-native-calendars';
import { styles } from './styles';
import { IPAddr } from './constants';
import { Ionicons } from "@expo/vector-icons";
import { RootStackParamList, Task } from '../components/Types';
import { useNavigation } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';
import { Task } from '../components/Types';
import axios from 'axios';


import GenericMainPageForm from './mainPageTemplate';

export default function FinanceTracker() {
const [selectedDate, setSelectedDate] = useState('');
const [tasks, setTasks] = useState<Task[]>([]);

type FinanceTrackerNavigationProp = StackNavigationProp<RootStackParamList, 'calendarEvents'>;
const navigation = useNavigation<FinanceTrackerNavigationProp>();

useEffect(() => {
axios.get(IPAddr + '/get_finance_events/1')
const fetchEvents = async () => {
axios.get(IPAddr + '/get_finance_events/1')
.then(response => {
const events = response.data.map((event: any) => ({
id: event.id.toString(),
Expand All @@ -31,71 +19,17 @@ export default function FinanceTracker() {
setTasks(events);
})
.catch(error => console.error('Error fetching events:', error));
}, []);

const handleDayPress = (day: { dateString: React.SetStateAction<string>; }) => {
setSelectedDate(day.dateString);
};
}

const renderTask = ({ item }: { item: Task }) => (
<View style={styles.taskItem}>
<Text style={styles.bullet}>
<View style={styles.taskicon}>
<Ionicons name={item.icon} size={30} color={'#000'} />
</View>
</Text>
<Text style={styles.taskText}>{item.title}</Text>
<View>
<BouncyCheckbox
fillColor="#65558F"
iconStyle={{ borderRadius: 0 }}
innerIconStyle={{ borderRadius: 0, borderWidth: 2 }}
onPress={(isChecked: boolean) => { item.done = isChecked; }} />
</View>
</View>
);
useEffect(() => {
fetchEvents();
}, []);

return (
<View style={styles.container}>
<View>
<Text style={styles.headerText}>Finance Events</Text>
<Text style={styles.sectionHeader}>Upcoming Events</Text>
</View>

<FlatList style={styles.flatList}
data={tasks}
renderItem={renderTask}
keyExtractor={(item) => item.id}
/>
<View style={{ height: 50 }}>
<Text style={styles.sectionHeader}>Title</Text>
</View>

<Calendar
onDayPress={handleDayPress}
markedDates={{
[selectedDate]: {
selected: true,
marked: true,
selectedColor: '#9b59b6',
},
}}
theme={{
selectedDayBackgroundColor: '#65558F',
todayTextColor: '#00adf5',
arrowColor: '#9b59b6',
}}
/>

{/* Button to navigate to addCalendarEvents */}
<TouchableOpacity style={styles.fixedButton}
onPress={() => navigation.navigate('addFinanceEvents')}
hitSlop={{ top: 20, bottom: 20, left: 20, right: 20 }}>
<View style={styles.icon}>
<Ionicons name="add-outline" size={40} color={'#eee'} />
<Text style={styles.newText}>New</Text>
</View>
</TouchableOpacity>
</View>
);
<GenericMainPageForm
title='Finance Tracker'
header='Upcoming Events'
nextPage='addFinanceEvents'
tasks={tasks}
/>);
}
Loading

0 comments on commit 63632a6

Please sign in to comment.