Skip to content

Commit defb9f3

Browse files
committed
Fixes
1 parent 8147b1b commit defb9f3

File tree

4 files changed

+32
-37
lines changed

4 files changed

+32
-37
lines changed

src/modules/tasks/TaskStore.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,22 @@ export default class TaskStore {
292292
this.versionHash = uuid();
293293
}
294294
}
295+
296+
export function createTask(title: string) {
297+
const { tasksStore, projectStore } = rootStore;
298+
tasksStore.add(
299+
new TaskModel({
300+
key: uuid(),
301+
title,
302+
projectId: projectStore.activeProject,
303+
active: false,
304+
time: [],
305+
checked: false,
306+
children: [],
307+
datesInProgress: [],
308+
details: [],
309+
parent: undefined, // Add into root
310+
expanded: true,
311+
})
312+
);
313+
}

src/screens/projects/components/CreateTask/Suggestions/Suggestion.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { observer } from 'mobx-react';
44
import { createUseStyles } from 'react-jss';
55

66
import { createTaskStore } from '../store/CreateTaskStore';
7+
import { createTask } from '../../../../../modules/tasks/TaskStore';
78

89
type Props = {
910
text: string;
@@ -12,10 +13,10 @@ type Props = {
1213
const SuggestionComp: FC<Props> = ({ text }: Props) => {
1314
const $ = useStyle();
1415

15-
const handleApplySuggestion = useCallback(
16-
() => createTaskStore.applySuggestion(text),
17-
[text]
18-
);
16+
const handleApplySuggestion = useCallback(() => {
17+
createTask(text);
18+
createTaskStore.afterApplySuggestion();
19+
}, [text]);
1920

2021
return (
2122
<Button

src/screens/projects/components/CreateTask/TaskInput.tsx

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import React, { ChangeEvent, KeyboardEvent, useEffect, useRef } from 'react';
1+
import React, { ChangeEvent, KeyboardEvent } from 'react';
22
import { Input } from 'antd';
33
import { observer } from 'mobx-react';
4-
import { v4 as uuid } from 'uuid';
54

6-
import rootStore from '../../../../modules/RootStore';
7-
import TaskModel from '../../../../modules/tasks/models/TaskModel';
85
import { createTaskStore } from './store/CreateTaskStore';
6+
import { createTask } from '../../../../modules/tasks/TaskStore';
97

108
interface Props {
119
className?: string;
@@ -14,22 +12,7 @@ interface Props {
1412
const handleCreateTask = (event: KeyboardEvent) => {
1513
// Hotkey: Enter
1614
if (event.key === 'Enter') {
17-
const { tasksStore, projectStore } = rootStore;
18-
tasksStore.add(
19-
new TaskModel({
20-
key: uuid(),
21-
title: createTaskStore.input,
22-
projectId: projectStore.activeProject,
23-
active: false,
24-
time: [],
25-
checked: false,
26-
children: [],
27-
datesInProgress: [],
28-
details: [],
29-
parent: undefined, // Add into root
30-
expanded: true,
31-
})
32-
);
15+
createTask(createTaskStore.input);
3316
createTaskStore.clear();
3417
}
3518
};
@@ -40,15 +23,8 @@ const handleChange = (e: ChangeEvent<HTMLInputElement>) =>
4023
const handleFocus = () => createTaskStore.setFocus(true);
4124

4225
export default observer(function TaskInput({ className }: Props) {
43-
const inputRef = useRef<Input>(null);
44-
45-
useEffect(() => {
46-
inputRef.current?.focus();
47-
}, [createTaskStore.focusTrigger]);
48-
4926
return (
5027
<Input
51-
ref={inputRef}
5228
className={className}
5329
placeholder="Create task..."
5430
onKeyPress={handleCreateTask}

src/screens/projects/components/CreateTask/store/CreateTaskStore.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { computed, makeAutoObservable } from 'mobx';
33
class CreateTaskStore {
44
input: string = '';
55
inputFocus: boolean = false;
6-
focusTrigger: boolean = false; // TODO better solution?
6+
7+
isInputEmpty = computed(() => this.input.length === 0);
78

89
constructor() {
910
makeAutoObservable(this);
@@ -13,17 +14,15 @@ class CreateTaskStore {
1314
return (this.input = value);
1415
}
1516

16-
applySuggestion(value: string) {
17-
this.setInput(value);
18-
this.focusTrigger = !this.focusTrigger;
17+
afterApplySuggestion() {
18+
this.clear();
19+
createTaskStore.setFocus(false);
1920
}
2021

2122
clear() {
2223
return (this.input = '');
2324
}
2425

25-
isInputEmpty = computed(() => this.input.length === 0);
26-
2726
setFocus(isFocus: boolean) {
2827
this.inputFocus = isFocus;
2928
}

0 commit comments

Comments
 (0)