Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nachocodoner committed Jul 22, 2024
1 parent 99e45d5 commit ef724b5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/tasks-common/tasks-common.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ const App = () => {
const firstTask = tasks[0];
const lastTask = tasks[tasks.length - 1];

const onAction = useCallback(() => {
if (!reactive) fetchTasks();
}, [reactive]);

const onAddClick = useCallback(async () => {
const parts = lastTask?.description?.split(' ') || [];
const nextTaskNum = (parseFloat(parts[parts.length - 1] || '0') || 0) + 1;
const descriptionsParts = lastTask?.description?.split(' ') || [];
const lastDescriptionNum = (parseFloat(descriptionsParts[descriptionsParts.length - 1] || '0') || 0);
const nextTaskNum = lastDescriptionNum + 1;
await Meteor.callAsync('insertTask', { description: `New Task ${nextTaskNum}` });
if (!reactive) fetchTasks();
}, [reactive, lastTask?._id]);
onAction();
}, [onAction, lastTask?._id]);
const onRemoveClick = useCallback(async () => {
await Meteor.callAsync('removeTask', { taskId: firstTask?._id });
if (!reactive) fetchTasks();
}, [reactive, firstTask?._id]);
onAction();
}, [onAction, firstTask?._id]);
const onRemoveAllClick = useCallback(async () => {
await Meteor.callAsync('removeAllTasks');
if (!reactive) fetchTasks();
}, [reactive]);
onAction();
}, [onAction]);

const fetchTasks = useCallback(async () => {
if (reactive) return;
Expand Down

0 comments on commit ef724b5

Please sign in to comment.