Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/-focus-mode-(#110
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Undeadlol1 committed Nov 20, 2020
2 parents 912fa64 + d2bc2be commit f132b43
Show file tree
Hide file tree
Showing 7 changed files with 5,633 additions and 2,206 deletions.
7,738 changes: 5,566 additions & 2,172 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"@material-ui/lab": "^4.0.0-alpha.35",
"@reach/window-size": "^0.11.2",
"@reduxjs/toolkit": "^1.0.4",
"@storybook/addon-actions": "^6.0.28",
"@storybook/addon-actions": "^6.1.1",
"@storybook/addon-console": "^1.2.2",
"@storybook/addon-knobs": "^6.0.28",
"@storybook/addon-links": "^6.0.28",
"@storybook/addons": "^6.0.28",
"@storybook/react": "^6.0.28",
"@storybook/addon-knobs": "^6.1.1",
"@storybook/addon-links": "^6.1.1",
"@storybook/addons": "^6.1.1",
"@storybook/react": "^6.1.1",
"@types/babel__core": "^7.1.12",
"@types/classnames": "^2.2.11",
"@types/debug": "^4.1.5",
Expand All @@ -23,7 +23,7 @@
"@types/faker": "^5.1.4",
"@types/jest": "^26.0.15",
"@types/lodash": "^4.14.165",
"@types/node": "^14.14.7",
"@types/node": "^14.14.9",
"@types/prettier": "2.1.5",
"@types/prop-types": "^15.7.3",
"@types/ramda": "^0.27.32",
Expand All @@ -41,17 +41,17 @@
"classnames": "^2.2.6",
"clsx": "^1.0.4",
"date-fns": "^2.16.1",
"debug": "^4.2.0",
"firebase": "^8.0.2",
"debug": "^4.3.1",
"firebase": "^8.1.1",
"firebase-tools": "^8.16.2",
"firebaseui": "^4.7.1",
"formik": "^2.2.5",
"i18next": "^19.8.3",
"i18next": "^19.8.4",
"i18next-browser-languagedetector": "^6.0.1",
"lodash": "^4.17.15",
"lorem-ipsum": "^2.0.3",
"material-ui-chip-input": "^1.1.0",
"nanoid": "^3.1.16",
"nanoid": "^3.1.17",
"pretty-error": "^2.1.2",
"prop-types": "^15.7.2",
"query-string": "^6.13.7",
Expand Down Expand Up @@ -80,13 +80,13 @@
"redux-firestore": "^0.14.0",
"reselect": "^4.0.0",
"typescript": "4.0.5",
"web-vitals": "^0.2.4",
"web-vitals": "^1.0.1",
"workbox-core": "^5.1.4",
"workbox-expiration": "^5.1.4",
"workbox-precaching": "^5.1.4",
"workbox-routing": "^5.1.4",
"workbox-strategies": "^5.1.4",
"yup": "^0.29.3"
"yup": "^0.30.0"
},
"scripts": {
"start:nofirebase": "react-scripts start",
Expand Down Expand Up @@ -128,14 +128,14 @@
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@storybook/addon-essentials": "^6.0.28",
"@storybook/node-logger": "^6.0.28",
"@storybook/addon-essentials": "^6.1.1",
"@storybook/node-logger": "^6.1.1",
"@storybook/preset-create-react-app": "^3.1.5",
"@testing-library/jest-dom": "^5.11.6",
"@types/enzyme": "^3.10.8",
"@types/enzyme-adapter-react-16": "^1.0.5",
"@typescript-eslint/eslint-plugin": "^4.8.0",
"@typescript-eslint/parser": "^4.8.0",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.1",
"babel-plugin-import": "^1.13.1",
Expand All @@ -157,7 +157,7 @@
"faker": "^5.1.0",
"jest-enzyme": "^7.1.2",
"plop": "^2.7.4",
"prettier": "2.1.2",
"prettier": "2.2.0",
"react-app-rewired": "^2.1.6",
"source-map-explorer": "^2.1.0"
}
Expand Down
26 changes: 10 additions & 16 deletions src/components/tasks/SubtasksList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import DeleteIcon from '@material-ui/icons/Delete';
import DragHandleIcon from '@material-ui/icons/DragHandle';
import { makeStyles } from '@material-ui/styles';
import arrayMove from 'array-move';
import firebase from 'firebase/app';
import isEmpty from 'lodash/isEmpty';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -22,16 +21,16 @@ import {
SortableElement,
SortableHandle,
} from 'react-sortable-hoc';
import { getFirestore } from 'redux-firestore';
import { Subtask } from '../../entities/Subtask';
import { addPointsWithSideEffects } from '../../repositories/addPointsWithSideEffects';
import { deleteSubtask } from '../../repositories/deleteSubtask';
import { updateSubtasks } from '../../repositories/updateSubtasks';
import {
handleErrors,
useTypedTranslate,
} from '../../services/index';
import Snackbar from '../../services/Snackbar';
import { deleteSubtask } from '../../repositories/deleteSubtask';
import { addPointsWithSideEffects } from "../../repositories/addPointsWithSideEffects";
import { authSelector } from '../../store/selectors';
import { Subtask } from '../../entities/Subtask';

const useStyles = makeStyles((theme: Theme) => {
const color = theme.palette.text.primary;
Expand Down Expand Up @@ -115,33 +114,28 @@ const SortableListContainer = SortableContainer(
},
);

export default function SubtasksList({ documents, ...props }: Props) {
export default function SubtasksList({ documents = [] }: Props) {
const classes = useStyles();
// @ts-ignore
const firestore = getFirestore(firebase);
const [subtasksStub, setSubtasksStub] = useState<
Subtask[] | undefined
>();

if (!documents || isEmpty(documents)) return null;
if (isEmpty(documents)) return null;

const updateSubtasks = ({ oldIndex, newIndex }: any) => {
function rearangeSubtasks({ oldIndex, newIndex }: any) {
const taskId = documents[0].parentId;
const updatedSubtasks = arrayMove(documents, oldIndex, newIndex);
setSubtasksStub(updatedSubtasks);
firestore
.doc(`tasks/${taskId}`)
.update({ subtasks: updatedSubtasks })
.catch(handleErrors);
};
updateSubtasks({ taskId, subtasks: updatedSubtasks });
}

return (
<Paper elevation={6} className={classes.paper}>
<SortableListContainer
useDragHandle
lockAxis="y"
items={subtasksStub || documents}
onSortEnd={updateSubtasks}
onSortEnd={rearangeSubtasks}
/>
</Paper>
);
Expand Down
5 changes: 5 additions & 0 deletions src/pages/TaskPage/TaskPageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { deleteTask as deleteTaskRepo } from '../../repositories/deleteTask';

const componentName = 'TaskPageContainer';
const log = debug(componentName);
// TODO: remove this line.
debug.enable('TaskPageContainer');

export interface updateTaskParams {
values: any;
Expand Down Expand Up @@ -84,6 +86,9 @@ const Container = memo(() => {
}
const task = find(tasks, ['id', taskId]) || fetchedTask;

log('task: ', task);
log('isStale?', TaskService.isStale(task));

// Fetch task if needed.
useEffect(() => {
if (
Expand Down
15 changes: 15 additions & 0 deletions src/repositories/updateSubtasks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Subtask } from '../entities/Subtask';
import { updateTask } from './updateTask';

export async function updateSubtasks({
taskId,
subtasks = [],
}: {
taskId: string;
subtasks: Subtask[];
}) {
return updateTask({
subtasks,
id: taskId,
});
}
12 changes: 11 additions & 1 deletion src/services/TaskService.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@ describe('TaskService.isStale returns"', () => {
expect(TaskService.isStale(task)).toEqual(true);
});

it("task wasn't worked on after update.", () => {
it("true if task wasn't worked on after update.", () => {
const task: Task = {
...taskDefaults,
dueAt: fiveDaysAgo,
};
expect(TaskService.isStale(task)).toEqual(true);
});

it('false if task is old but was updated.', () => {
const task: Task = {
...taskDefaults,
updatedAt: today,
dueAt: fiveDaysAgo,
createdAt: fiveDaysAgo,
};
expect(TaskService.isStale(task)).toEqual(false);
});
});
9 changes: 9 additions & 0 deletions src/services/TaskService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,24 @@ export default class TaskService {
differenceInDays(today, task.createdAt || today) > 3;
const isTaskReadyButNotWorkedOn =
differenceInDays(today, task.dueAt) > 3;
const hasTaskBeenUpdatedRecently =
task.updatedAt === undefined
? false
: differenceInDays(today, task.updatedAt) < 5;

log('isStale is called. %O', task);
log('isTaskOld: ', isTaskCreatedLongAgo);
log('hasTaskBeenUpdatedRecently: ', hasTaskBeenUpdatedRecently);

function notifyThatTaskIsTale(reason: string) {
log(reason);
log('Task is stale.');
}

if (hasTaskBeenUpdatedRecently) {
notifyThatTaskIsTale('Task has been updated recently.');
return false;
}
if (task?.createdAt === undefined) {
notifyThatTaskIsTale('task.createdAt is undefined.');
return true;
Expand Down

0 comments on commit f132b43

Please sign in to comment.