Skip to content

Commit

Permalink
Merge pull request #10 from TaskRatchet/New-Task-Button
Browse files Browse the repository at this point in the history
New task functionality
  • Loading branch information
narthur authored Feb 2, 2024
2 parents 7b7568b + b1f7957 commit 8b684e8
Show file tree
Hide file tree
Showing 14 changed files with 565 additions and 57 deletions.
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ PODS:
- React-jsinspector (0.72.7)
- React-logger (0.72.7):
- glog
- react-native-date-picker (4.3.5):
- React-Core
- react-native-safe-area-context (4.8.1):
- React-Core
- react-native-secure-key-store (2.0.10):
Expand Down Expand Up @@ -548,6 +550,7 @@ DEPENDENCIES:
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- react-native-date-picker (from `../node_modules/react-native-date-picker`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- react-native-secure-key-store (from `../node_modules/react-native-secure-key-store`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
Expand Down Expand Up @@ -633,6 +636,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
React-logger:
:path: "../node_modules/react-native/ReactCommon/logger"
react-native-date-picker:
:path: "../node_modules/react-native-date-picker"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
react-native-secure-key-store:
Expand Down Expand Up @@ -714,6 +719,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: c49502e5d02112247ee4526bc3ccfc891ae3eb9b
React-jsinspector: 8baadae51f01d867c3921213a25ab78ab4fbcd91
React-logger: 8edc785c47c8686c7962199a307015e2ce9a0e4f
react-native-date-picker: 90d1d60802a20085125657940b944f2bb4e5c113
react-native-safe-area-context: cd1169d797a2ef722a00bfc5af10748d5b6c94f9
react-native-secure-key-store: 910e6df6bc33cb790aba6ee24bc7818df1fe5898
React-NativeModulesApple: b6868ee904013a7923128892ee4a032498a1024a
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"punycode": "^2.3.1",
"react": "^18.2.0",
"react-native": "0.72.7",
"react-native-date-picker": "^4.3.5",
"react-native-gesture-handler": "^2.14.1",
"react-native-safe-area-context": "^4.7.4",
"react-native-screens": "^3.27.0",
Expand Down
67 changes: 67 additions & 0 deletions src/components/datePickerPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {useQuery} from '@tanstack/react-query';
import React from 'react';
import {Modal, Pressable, Text, View} from 'react-native';
import DatePicker from 'react-native-date-picker';

import themeProvider from '../providers/themeProvider';
import {getMe} from '../services/taskratchet/getMe';
import {styles} from '../styles/datePickerPopupStyle';
import useIsDarkMode from '../utils/checkDarkMode';
import type {DatePickerPopupProps} from './types';

export default function DatePickerPopup({
dateModalVisible,
setDateModalVisible,
date,
onDateChange,
}: DatePickerPopupProps): JSX.Element {
const {data: user} = useQuery({queryKey: ['user'], queryFn: getMe});

const isDarkMode = useIsDarkMode();

const backgroundStyle = {
backgroundColor: isDarkMode
? themeProvider.colorsDark.secondaryLight
: themeProvider.colorsLight.secondary,
};

const textColorStyle = {
color: isDarkMode ? 'white' : 'black',
};

return (
<View>
<Modal visible={dateModalVisible} transparent={true} animationType="none">
<View style={styles.centeredView}>
<View style={[styles.modalView, backgroundStyle]}>
<View style={styles.datePickerGroup}>
<Text style={[styles.textStyle, textColorStyle]}>
Select Date:
</Text>
<DatePicker
style={styles.datePicker}
date={date}
onDateChange={onDateChange}
/>
<Text style={[textColorStyle]}>{user?.timezone}</Text>
</View>
<Pressable
style={({pressed}) => [
{
backgroundColor: pressed
? 'rgba(33, 150, 243, 0.5)'
: '#2196F3',
},
styles.button,
]}
onPress={() => {
setDateModalVisible(!dateModalVisible);
}}>
<Text style={styles.textStyle}>Set</Text>
</Pressable>
</View>
</View>
</Modal>
</View>
);
}
172 changes: 172 additions & 0 deletions src/components/newTaskPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import {useMutation, useQueryClient} from '@tanstack/react-query';
import React, {useState} from 'react';
import {Modal, Pressable, Text, TextInput, View} from 'react-native';

import themeProvider from '../providers/themeProvider';
import {addTask} from '../services/taskratchet/addTask';
import {styles} from '../styles/newTaskPopupStyle';
import useIsDarkMode from '../utils/checkDarkMode';
import DatePickerPopup from './datePickerPopup';
import type {infoPopupProps} from './types';

export default function NewTaskPopup({
modalVisible,
setModalVisible,
}: infoPopupProps): JSX.Element {
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: () =>
addTask({
task: taskData.title,
due: taskData.date,
cents: taskData.cents,
}),
onError: error => {
console.error('Error adding task:', error);
},
onSettled: () => {
return queryClient.invalidateQueries({queryKey: ['tasks']});
},
});
const [chosenDate, setChosenDate] = useState(() => {
const d = new Date();
d.setDate(d.getDate() + 7);
d.setHours(23, 59, 0, 0);
return d;
});

const isDarkMode = useIsDarkMode();

const backgroundStyle = {
backgroundColor: isDarkMode
? themeProvider.colorsDark.secondaryLight
: themeProvider.colorsLight.secondary,
};

const inputBackgroundStyle = {
backgroundColor: isDarkMode ? '#303845' : '#EFEFF0',
};

const textColorStyle = {
color: isDarkMode ? 'white' : 'black',
};

const [title, setTitle] = useState('');
const [dollars, setDollars] = useState(5);
const [failMessage, setFailMessage] = useState('');
const [datePickerModalVisible, setDatePickerModalVisible] = useState(false);

const taskData = {
title: title,
date: chosenDate,
cents: dollars * 100,
};

function handleSetDatePress() {
setDatePickerModalVisible(!datePickerModalVisible);
}

function resetTaskData() {
setFailMessage('');
setTitle('');
setDollars(5);
setChosenDate(() => {
const d = new Date();
d.setDate(d.getDate() + 7);
d.setHours(23, 59, 0, 0);
return d;
});
}

return (
<View>
<Modal visible={modalVisible} transparent={true} animationType="none">
<View style={styles.centeredView}>
<View style={[styles.modalView, backgroundStyle]}>
<View style={styles.titlePair}>
<Text style={[styles.titleTextStyle, textColorStyle]}>Task</Text>
<TextInput
style={[styles.input, inputBackgroundStyle, textColorStyle]}
keyboardType="default"
placeholder="Enter Title"
onChangeText={text => setTitle(text)}
/>
</View>

<View style={styles.centsPair}>
<Text style={[styles.textStyle, textColorStyle]}>Stakes</Text>
<TextInput
style={[styles.input, inputBackgroundStyle, textColorStyle]}
keyboardType="numeric"
placeholder="Enter Value"
onChangeText={text => setDollars(parseFloat(text))}
/>
</View>

<View style={styles.datePair}>
<Text style={[styles.textStyle, textColorStyle]}>Date</Text>
<Pressable
style={[styles.inputEmulatorBox, inputBackgroundStyle]}
onPress={() => {
handleSetDatePress();
}}>
<Text style={[styles.textStyleInputEmulator, textColorStyle]}>
{chosenDate.toLocaleString([], {
dateStyle: 'short',
timeStyle: 'short',
})}
</Text>
</Pressable>
</View>

<Text style={styles.failMessageTextStyle}>{failMessage}</Text>

<Pressable
style={({pressed}) => [
{
backgroundColor: pressed
? 'rgba(33, 150, 243, 0.5)'
: '#2196F3',
},
styles.createButton,
]}
onPress={() => {
if (taskData.title !== '' && taskData.cents !== 0) {
mutation.mutate();
setModalVisible(!modalVisible);
resetTaskData();
} else {
console.error('Invalid task data');
setFailMessage('Title and Value must be set');
}
}}>
<Text style={styles.buttonText}>Create</Text>
</Pressable>
<Pressable
style={({pressed}) => [
{
backgroundColor: pressed
? 'rgba(33, 150, 243, 0.5)'
: '#2196F3',
},
styles.button,
]}
onPress={() => {
setModalVisible(!modalVisible);
resetTaskData();
}}>
<Text style={styles.buttonText}>Hide</Text>
</Pressable>
</View>
</View>
<DatePickerPopup
testID="datePickerPopup"
dateModalVisible={datePickerModalVisible}
setDateModalVisible={setDatePickerModalVisible}
date={chosenDate}
onDateChange={setChosenDate}
/>
</Modal>
</View>
);
}
8 changes: 8 additions & 0 deletions src/components/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ export type infoPopupProps = {
setModalVisible: Dispatch<SetStateAction<boolean>>;
};

export type DatePickerPopupProps = {
testID?: string;
dateModalVisible: boolean;
setDateModalVisible: Dispatch<SetStateAction<boolean>>;
date: Date;
onDateChange: Dispatch<SetStateAction<Date>>;
};

export type LoginScreenProps = StackScreenProps<
RootStackParamList,
'LoginScreen'
Expand Down
4 changes: 4 additions & 0 deletions src/providers/themeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ const themeProvider = {
background: '#EBF3FA',
primary: '#C5C3C9',
secondary: '#fff',
plusButton: '#7A9CC6',
plusButtonPressed: '#6A8CB6',
},
colorsDark: {
background: '#1A2533',
primary: 'rgba(124, 138, 159, 0.4)',
secondary: '#0C0E11',
secondaryLight: '#1A2533',
plusButton: '#2734A4',
plusButtonPressed: '#1F2E8B',
},
};

Expand Down
Loading

0 comments on commit 8b684e8

Please sign in to comment.