Skip to content

Commit

Permalink
Removed Some Code Duplication in repeating data Ref #18
Browse files Browse the repository at this point in the history
  • Loading branch information
rhit-villencr committed Oct 20, 2024
1 parent 63632a6 commit d59b501
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 27 deletions.
11 changes: 2 additions & 9 deletions app/addCalendarEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@ import { Ionicons } from "@expo/vector-icons";
import { Dropdown } from 'react-native-element-dropdown';
import axios from 'axios';
import DateTimePicker from '@react-native-community/datetimepicker';
import { IPAddr } from './constants';
import { IPAddr, repeatingData } from './constants';
import { useNavigation } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';
import { RootStackParamList } from '@/components/Types';

const data = [
{ label: 'Daily', value: '1' },
{ label: 'Weekly', value: '2' },
{ label: 'Monthly', value: '3' },
{ label: 'Yearly', value: '4' },
];

export default function AddCalendarEvents() {
type AddCalendarTrackerNavigationProp = StackNavigationProp<RootStackParamList, 'addCalendarEvents'>;
const navigation = useNavigation<AddCalendarTrackerNavigationProp>();
Expand Down Expand Up @@ -115,7 +108,7 @@ export default function AddCalendarEvents() {
<View style={styles.container}>
<Dropdown
style={{ width: 200, borderWidth: 1, padding: 8 }}
data={data}
data={repeatingData}
maxHeight={300}
labelField="label"
valueField="value"
Expand Down
11 changes: 2 additions & 9 deletions app/addFinanceEvents.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import React from 'react';
import axios from 'axios';
import { IPAddr } from './constants';
import { IPAddr, repeatingData } from './constants';
import { useNavigation } from '@react-navigation/native';
import GenericAddPageForm from './addEventPage';
import { StackNavigationProp } from '@react-navigation/stack';
import { RootStackParamList } from '@/components/Types';

const data = [
{ label: 'Daily', value: '1' },
{ label: 'Weekly', value: '2' },
{ label: 'Monthly', value: '3' },
{ label: 'Yearly', value: '4' },
];

export default function AddFinanceEvents() {
type AddFinanceTrackerNavigationProp = StackNavigationProp<RootStackParamList, 'addFinanceEvents'>;
const navigation = useNavigation<AddFinanceTrackerNavigationProp>();
Expand All @@ -21,7 +14,7 @@ export default function AddFinanceEvents() {
{ name: 'title', label: 'Title', type: 'text' },
{ name: 'event_date', label: 'Date', type: 'date' },
{ name: 'event_time', label: 'Time', type: 'time' },
{ name: 'repeating', label: 'Repeating', type: 'dropdown', options: data },
{ name: 'repeating', label: 'Repeating', type: 'dropdown', options: repeatingData },
{ name: 'money', label: 'Money', type: 'number' }
];

Expand Down
11 changes: 3 additions & 8 deletions app/addHealthEvents.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import React from 'react';
import { IPAddr } from './constants';
import { IPAddr, repeatingData } from './constants';
import axios from 'axios';
import { StackNavigationProp } from '@react-navigation/stack';
import { useNavigation } from '@react-navigation/native';
import GenericAddPageForm from './addEventPage';
import { RootStackParamList } from '@/components/Types';

const data = [
{ label: 'Daily', value: '1' },
{ label: 'Weekly', value: '2' },
{ label: 'Monthly', value: '3' },
{ label: 'Yearly', value: '4' },
];


export default function AddHealthEvents() {
type AddHealthEventNavProp = StackNavigationProp<RootStackParamList, 'addCalendarEvents'>;
Expand All @@ -30,7 +25,7 @@ export default function AddHealthEvents() {
{ 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: 'repeat_timeline', label: 'Repeating', type: 'dropdown', options: repeatingData },
{ name: 'description', label: 'Description', type: 'textarea' },
];

Expand Down
9 changes: 8 additions & 1 deletion app/constants.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
export const IPAddr = "http://34.204.83.156:8080"
export const IPAddr = "http://34.204.83.156:8080"

export const repeatingData = [
{ label: 'Daily', value: '1' },
{ label: 'Weekly', value: '2' },
{ label: 'Monthly', value: '3' },
{ label: 'Yearly', value: '4' },
];

0 comments on commit d59b501

Please sign in to comment.