Skip to content

Commit

Permalink
performance enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
lcflight committed Mar 27, 2024
1 parent b6948f1 commit f9c7c7e
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 94 deletions.
7 changes: 0 additions & 7 deletions .babelrc

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions not_mocks/__mocks__/firebase.js

This file was deleted.

13 changes: 0 additions & 13 deletions not_mocks/__mocks__/firebase/app.js

This file was deleted.

31 changes: 11 additions & 20 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"react-native-webview": "13.2.2",
"react-navigation": "^5.0.0",
"react-test-renderer": "^18.2.0",
"typescript": "^5.4.3"
"typescript": "^5.4.3",
"react-native-gesture-handler": "~2.12.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
1 change: 0 additions & 1 deletion src/components/newTaskPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export default function NewTaskPopup({
]}
onPress={() => {
if (taskData.title.trim() !== '' && taskData.cents !== 0) {
console.log('taskData', taskData);
mutation.mutate(taskData);
setModalVisible(!modalVisible);
resetTaskData();
Expand Down
68 changes: 39 additions & 29 deletions src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useQuery} from '@tanstack/react-query';
import moment from 'moment';
import React, {useState} from 'react';
import React, {useMemo, useState} from 'react';
import {
Image,
ImageSourcePropType,
Expand Down Expand Up @@ -70,38 +70,48 @@ export default function HomeScreen({navigation}: Props): JSX.Element {
: themeProvider.colorsLight.plusButtonPressed,
};

const sortedTasks = tasks?.sort((a, b) => {
const taskA = a;
const taskB = b;
const sortedTasks = useMemo(() => {
console.log('sorting tasks');
return tasks?.sort((a, b) => {
const taskA = a;
const taskB = b;

if ('due' in taskA && 'due' in taskB) {
const diffDaysA = checkDate(String(taskA.due));
const diffDaysB = checkDate(String(taskB.due));
if ('due' in taskA && 'due' in taskB) {
const diffDaysA = checkDate(String(taskA.due));
const diffDaysB = checkDate(String(taskB.due));

// If the deadline is past, return a large number to sort the task to the bottom
const timeLeftA = diffDaysA < 0 ? Number.MAX_SAFE_INTEGER : diffDaysA;
const timeLeftB = diffDaysB < 0 ? Number.MAX_SAFE_INTEGER : diffDaysB;
// If the deadline is past, return a large number to sort the task to the bottom
const timeLeftA = diffDaysA < 0 ? Number.MAX_SAFE_INTEGER : diffDaysA;
const timeLeftB = diffDaysB < 0 ? Number.MAX_SAFE_INTEGER : diffDaysB;

return timeLeftA - timeLeftB;
} else {
return 0;
}
});
return timeLeftA - timeLeftB;
} else {
return 0;
}
});
}, [tasks]);

const nextTasks = useMemo(() => {
console.log('filtering next tasks');
return sortedTasks?.filter(task => {
const dueDate = moment(task.due, 'M/D/YYYY, hh:mm A').toDate();
const isDueInLessThan24Hours =
dueDate && dueDate.getTime() > Date.now() - 24 * 60 * 60 * 1000;
return isDueInLessThan24Hours;
});
}, [sortedTasks]);

const archiveTasks = useMemo(() => {
console.log('filtering archive tasks');
return sortedTasks?.filter(task => {
const dueDate = moment(task.due, 'M/D/YYYY, hh:mm A').toDate();
const isDueInMoreThan24Hours =
dueDate && dueDate.getTime() <= Date.now() - 24 * 60 * 60 * 1000;
return isDueInMoreThan24Hours;
});
}, [sortedTasks]);

const processedTasks =
selectedOption === 'Next'
? sortedTasks?.filter(task => {
const dueDate = moment(task.due, 'M/D/YYYY, hh:mm A').toDate();
const isDueInLessThan24Hours =
dueDate && dueDate.getTime() > Date.now() - 24 * 60 * 60 * 1000;
return isDueInLessThan24Hours;
})
: sortedTasks?.filter(task => {
const dueDate = moment(task.due, 'M/D/YYYY, hh:mm A').toDate();
const isDueInMoreThan24Hours =
dueDate && dueDate.getTime() <= Date.now() - 24 * 60 * 60 * 1000;
return isDueInMoreThan24Hours;
});
const processedTasks = selectedOption === 'Next' ? nextTasks : archiveTasks;

const textColorStyle = {
color: isDarkMode ? 'white' : 'black',
Expand Down
5 changes: 0 additions & 5 deletions src/services/taskratchet/addTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ type Input = {

// Requires that user be authenticated.
export async function addTask(input: Input): Promise<Response> {
console.log('input', input);

const response = await fetch1('me/tasks', true, 'POST', {
...input,
due: formatDate(input.due),
Expand All @@ -22,8 +20,6 @@ export async function addTask(input: Input): Promise<Response> {
// }

if (response) {
console.log('Task added successfully');
console.log('response', response);
return response;
}
}
Expand All @@ -48,6 +44,5 @@ function formatDate(date: Date): string {
// Make sure minutes have leading zeros if required
const mm = minutes < 10 ? `0${minutes}` : minutes.toString();
const result = `${month}/${day}/${year}, ${hour}:${mm} ${period}`;
console.log('date', result);
return result;
}
1 change: 0 additions & 1 deletion src/styles/taskPopupStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const styles = StyleSheet.create({
position: 'absolute',
right: 0,
fontSize: 30,
fontFamily: 'Trebuchet MS',
},
title: {
flexShrink: 1,
Expand Down

0 comments on commit f9c7c7e

Please sign in to comment.