Skip to content

Commit 2334025

Browse files
committedJan 6, 2025
feat(command): add !focus command
1 parent 30076c2 commit 2334025

14 files changed

+158
-5
lines changed
 

‎README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Open the `_styles.js` file and modify the following settings to customized the T
189189
- headerDisplay: Default = **"flex"**
190190
- headerBorderRadius: Default = **"6px"**
191191
- headerMarginBottom: Default = **"6px"**
192-
- headerBackgroundColor: Default = **"rgba(45, 45, 45, 0.7)"**
192+
- headerBackgroundColor: Default = **"rgba(0, 0, 0, 0.7)"**
193193
- headerFontSize: Default = **"20px"**
194194
- headerFontColor: Default = **"#FFFFFF"**
195195
- headerFontWeight: Default = **"normal"**
@@ -198,7 +198,7 @@ Open the `_styles.js` file and modify the following settings to customized the T
198198

199199
- cardGapBetween: Default = **"6px"**
200200
- cardBorderRadius: Default = **"6px"**
201-
- cardBackgroundColor: Default = **"rgba(45, 45, 45, 0.7)"**
201+
- cardBackgroundColor: Default = **"rgba(0, 0, 0, 0.7)"**
202202

203203
#### Username Styles
204204

@@ -214,6 +214,9 @@ Open the `_styles.js` file and modify the following settings to customized the T
214214
- taskDoneFontColor: Default = **"#aaaaaa"**
215215
- taskDoneFontStyle: Default = **"#italic"**
216216
- taskDoneTextDecoration: Default = **"line-through"**
217+
- taskFocusFontColor: Default = **"#111111"**
218+
- taskFocusBackgroundColor: Default = **"rgba(255, 255, 255, 0.7)"**
219+
- taskFocusBorderRadius: Default = **"8px"**
217220

218221
## Commands
219222

‎_configUser.js

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const _userConfig = {
88
editTask: ["!edit", "!editar", "!modifier", "!編集", "!редагувати"],
99
finishTask: ["!done", "!hecho", "!terminé", "!完了", "!готово"],
1010
deleteTask: ["!delete", "!eliminar", "!supprimer", "!削除", "!видалити"],
11+
focusTask: ["!focus", "!focalizar", "!concentrer", "!集中", "!зосередитись"],
1112
check: ["!check", "!comprobar", "!vérifier", "!チェック", "!перевірити"],
1213
help: ["!help", "!ayuda", "!aide", "!ヘルプ", "!допомога"],
1314
additional: ["!credit", "!crédito", "!crédit", "!クレジット", "!кредит"],
@@ -19,6 +20,7 @@ const _userConfig = {
1920
finishTask: 'Good job on completing task(s) {message}!',
2021
deleteTask: 'Task(s) {message} has been deleted!',
2122
deleteAll: "All of your tasks have been deleted!",
23+
focusTask: 'Prioritizing your focus on task {message}!',
2224
check: 'Your current task(s) are: {message}',
2325
help: "Try these commands - !task !edit !done !delete !check",
2426
additional:
@@ -34,6 +36,7 @@ const _userConfig = {
3436
finishTask: '¡Buen trabajo completando la(s) tarea(s) {message}!',
3537
deleteTask: 'La(s) tarea(s) {message} ha sido eliminada(s)!',
3638
deleteAll: "Todas tus tareas han sido eliminadas!",
39+
focusTask: 'Priorizando tu enfoque en la tarea {message}!',
3740
check: 'Tus tareas actuales son: {message}',
3841
help: "Prueba a usar estos comandos - !añadir !editar !hecho !eliminar !comprobar",
3942
additional:
@@ -49,6 +52,7 @@ const _userConfig = {
4952
finishTask: 'Bon travail pour avoir terminé la tâche {message}!',
5053
deleteTask: 'La tâche {message} a été supprimée!',
5154
deleteAll: "Toutes vos tâches ont été supprimées!",
55+
focusTask: 'Priorisation de votre focus sur la tâche {message}!',
5256
check: 'Vos tâches actuelles sont: {message}',
5357
help: "Essayez d'utiliser ces commandes - !ajouter !modifier !terminé !supprimer !vérifier",
5458
additional:
@@ -65,6 +69,7 @@ const _userConfig = {
6569
finishTask: 'タスク {message} を完了しました!',
6670
deleteTask: 'タスク {message} が削除されました!',
6771
deleteAll: "すべてのタスクが削除されました!",
72+
focusTask: 'タスク {message} にフォーカスを当てています!',
6873
check: '現在のタスクは {message} です',
6974
help: "これらのコマンドを試してみてください - !追加 !編集 !完了 !削除 !チェック",
7075
additional:
@@ -80,6 +85,7 @@ const _userConfig = {
8085
finishTask: 'Вітаю з виконанням завдання {message}!',
8186
deleteTask: 'Завдання {message} видалено!',
8287
deleteAll: "Всі твої завдання видалено!",
88+
focusTask: 'Сфокусовано на завданні {message}!',
8389
check: 'Твої завдання наразі : {message}',
8490
help: "Спробуй такі команди -!додати !редагувати !готово !видалити !перевірити",
8591
additional:

‎_styles.js

+4
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ const _styles = {
4242
taskDoneFontColor: "#b0b0b0", // hex value
4343
taskDoneFontStyle: "italic", // "italic" or "normal"
4444
taskDoneTextDecoration: "line-through", // "line-through" or "none"
45+
46+
taskFocusFontColor: "#111111", // hex value
47+
taskFocusBackgroundColor: "rgba(255, 255, 255, 0.7)", // rgba value https://rgbcolorpicker.com/
48+
taskFocusBorderRadius: "8px", // hex value
4549
};

‎dist/taskBot.iife.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/app.js

+27
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export default class App {
6161
if (task.isComplete()) {
6262
listItem.classList.add("done");
6363
}
64+
if (task.isFocused()) {
65+
listItem.classList.add("focus");
66+
}
6467
list.appendChild(listItem);
6568
});
6669
fragment.appendChild(cardEl);
@@ -301,6 +304,14 @@ export default class App {
301304
responseDetail = taskNumber;
302305
template = _userConfig.responseTo[this.#languageCode].editTask;
303306
}
307+
else if (_userConfig.commands.focusTask.includes(command)) {
308+
// FOCUS TASK
309+
const taskIndex = parseTaskIndex(message);
310+
const task = this.userList.focusUserTask(username, taskIndex);
311+
this.focusTaskFromDOM(username, task.id);
312+
responseDetail = (taskIndex + 1).toString();
313+
template = _userConfig.responseTo[this.#languageCode].focusTask;
314+
}
304315
else if (_userConfig.commands.finishTask.includes(command)) {
305316
// COMPLETE/DONE TASK
306317
const indices = message.split(",").reduce((acc, i) => {
@@ -476,6 +487,22 @@ export default class App {
476487
this.renderTaskCount();
477488
}
478489

490+
/**
491+
* Mark task as focused in the DOM.
492+
* @param {string} username
493+
* @param {string} taskId
494+
* @returns {void}
495+
*/
496+
focusTaskFromDOM(username, taskId) {
497+
document.querySelectorAll(`[data-user="${username}"] .task`).forEach(task => {
498+
task.classList.remove("focus");
499+
});
500+
501+
document.querySelectorAll(`[data-task-id="${taskId}"]`).forEach(task => {
502+
task.classList.add("focus");
503+
});
504+
}
505+
479506
/**
480507
* Delete the task in the DOM
481508
* @param {string} taskId

‎src/classes/Task.js

+23
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* @property {string} description - The description of the task.
44
* @property {number} id - The id of the task.
55
* @property {boolean} completionStatus - Indicates whether the task is complete or not.
6+
* @property {boolean} focusStatus - Indicates whether the task is focused or not.
67
* @method validateDescription - Validate the description of the task.
78
* @method setDescription - Set the description of the task.
89
* @method isComplete - Get the completion status of the task.
910
* @method setCompletionStatus - Set the status of the task.
11+
* @method isFocused - Get the focus status of the task.
12+
* @method setFocusStatus - Set the focus status of the task.
1013
* @returns {Task}
1114
*/
1215
export default class Task {
@@ -18,6 +21,7 @@ export default class Task {
1821
this.description = this.validateDescription(description);
1922
this.id = this.#assignId();
2023
this.completionStatus = false;
24+
this.focusStatus = false;
2125
}
2226

2327
/**
@@ -80,4 +84,23 @@ export default class Task {
8084
}
8185
this.completionStatus = status;
8286
}
87+
88+
/**
89+
* Get the focus status of the task.
90+
* @returns {boolean} The focus status of the task.
91+
*/
92+
isFocused() {
93+
return this.focusStatus;
94+
}
95+
96+
/**
97+
* Set the focus status of the task.
98+
* @param {boolean} status - The new focus status of the task.
99+
*/
100+
setFocusStatus(status) {
101+
if (typeof status !== "boolean") {
102+
throw new Error("Focus status must be of type boolean");
103+
}
104+
this.focusStatus = status;
105+
}
83106
}

‎src/classes/User.js

+18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @method addTask - Add tasks to the user
99
* @method editTask - Edit the task at the specified index
1010
* @method completeTask - Mark the task at index as complete
11+
* @method setFocusedTask - Mark the task at index as focused
1112
* @method deleteTask - Delete the task at the specified index
1213
* @method removeCompletedTasks - Remove all completed tasks
1314
* @method getTask - Get the task at the specified index
@@ -82,6 +83,23 @@ export default class User {
8283
return null;
8384
}
8485

86+
/**
87+
* Mark the task at the specified index as focused
88+
* @param {number} index - The index of the task to focus
89+
* @returns {Task | null} The task that was focused
90+
*/
91+
setFocusedTask(index) {
92+
let task = this.getTask(index);
93+
if (task) {
94+
this.tasks.forEach((t) => {
95+
t.setFocusStatus(false);
96+
});
97+
task.setFocusStatus(true);
98+
return task;
99+
}
100+
return null;
101+
}
102+
85103
/**
86104
* Delete the task at the specified index
87105
* @param {number | number[]} indices - The indices of the tasks to delete

‎src/classes/UserList.js

+24
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Task from "./Task.js";
1212
* @method addUserTasks - Add a tasks to the specified user
1313
* @method editUserTask - Edit the task at the specified index
1414
* @method completeUserTasks - Mark specified tasks as complete
15+
* @method focusUserTasks - Mark specified tasks as focused
1516
* @method deleteUserTasks - Delete tasks at specified indices
1617
* @method checkUserTasks - Get remaining tasks
1718
* @method clearUserList - Clear user list
@@ -52,6 +53,9 @@ export default class UserList {
5253
newTask.setCompletionStatus(task.completionStatus);
5354
this.tasksCompleted++;
5455
}
56+
if (task.focusStatus) {
57+
newTask.setFocusStatus(task.focusStatus);
58+
}
5559
});
5660
userList.push(user);
5761
});
@@ -148,6 +152,26 @@ export default class UserList {
148152
return task;
149153
}
150154

155+
/**
156+
* Mark user task as focused
157+
* @param {string} username - The username of the user
158+
* @param {number} taskIndex - The index of the task to focus
159+
* @throws {Error} User not found
160+
* @returns {Task} The focused task
161+
*/
162+
focusUserTask(username, taskIndex) {
163+
const user = this.getUser(username);
164+
if (!user) {
165+
throw new Error(`User ${username} not found`);
166+
}
167+
const task = user.setFocusedTask(taskIndex);
168+
if (!task) {
169+
throw new Error(`Task ${taskIndex} not found`);
170+
}
171+
this.#commitToLocalStorage();
172+
return task;
173+
}
174+
151175
/**
152176
* Mark the user tasks as complete
153177
* @param {string} username - The username of the user

‎styles/app.css

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
font-weight: var(--task-font-weight, normal);
8787
}
8888

89+
.task.focus {
90+
background-color: var(--task-focus-background-color, #aaaaaa);
91+
color: var(--task-focus-font-color, #111111);
92+
border-radius: var(--task-focus-boarder-radius, 8px);
93+
}
8994
.done {
9095
color: var(--task-done-font-color, #aaaaaa);
9196
text-decoration-line: var(--task-done-text-decoration, none);

‎styles/variables.css

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,7 @@
3838
--task-done-font-color: #aaaaaa;
3939
--task-done-font-style: italic;
4040
--task-done-text-decoration: line-through;
41-
}
41+
--task-focus-font-color: #111111;
42+
--task-focus-background-color: rgba(255, 255, 255, 0.7);
43+
--task-focus-border-radius: 8px;
44+
}

‎tests/Task.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,25 @@ describe("Task", () => {
7979
);
8080
});
8181
});
82+
83+
describe("isFocused", () => {
84+
it("should return the focus status of the task", () => {
85+
expect(task.isFocused()).toBe(false);
86+
});
87+
});
88+
89+
describe("setFocusStatus", () => {
90+
it("should set the focus status of the task", () => {
91+
task.setFocusStatus(true);
92+
expect(task.isFocused()).toBe(true);
93+
task.setFocusStatus(false);
94+
expect(task.isFocused()).toBe(false);
95+
});
96+
97+
it("should return Error if status is not a boolean", () => {
98+
expect(() => task.setFocusStatus("true")).toThrow(
99+
"Focus status must be of type boolean"
100+
);
101+
});
102+
});
82103
});

‎tests/User.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ describe("User", () => {
7272
});
7373
});
7474

75+
describe("setFocusedTask", () => {
76+
test("should mark the task at the specified index as focused", () => {
77+
user.addTask(new Task("test task 1"));
78+
user.setFocusedTask(0);
79+
expect(user.getTasks()[0].isFocused()).toBe(true);
80+
});
81+
82+
test("should return null if the task index is out of bounds", () => {
83+
user.addTask(new Task("test task 1"));
84+
const task = user.setFocusedTask(3);
85+
expect(task).toBeNull();
86+
});
87+
});
88+
7589
describe("deleteTask", () => {
7690
test("should be able to delete a single task given a single index number", () => {
7791
user.addTask(new Task("test task 0"));

‎tests/globalSetup.js

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const _userConfig = {
2525
editTask: ["!edit", "!editar", "!modifier", "!編集", "!редагувати"],
2626
finishTask: ["!done", "!hecho", "!terminé", "!完了", "!готово"],
2727
deleteTask: ["!delete", "!eliminar", "!supprimer", "!削除", "!видалити"],
28+
focusTask: ["!focus", "!focalizar", "!concentrer", "!集中", "!зосередитись"],
2829
check: ["!check", "!comprobar", "!vérifier", "!チェック", "!перевірити"],
2930
help: ["!help", "!ayuda", "!aide", "!ヘルプ", "!допомога"],
3031
additional: ["!credit", "!crédito", "!crédit", "!クレジット", "!кредит"],
@@ -36,6 +37,7 @@ const _userConfig = {
3637
finishTask: 'Good job on completing task(s) {message}!',
3738
deleteTask: 'Task(s) {message} has been deleted!',
3839
deleteAll: "All of your tasks have been deleted!",
40+
focusTask: 'Prioritizing your focus on task {message}!',
3941
check: 'Your current task(s) are: {message}',
4042
help: "Try using these commands - !task !edit !done !delete, !check",
4143
additional:

‎types/globals.d.js

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
* @property {string} taskDoneFontColor - The task done font color
4747
* @property {string} taskDoneFontStyle - The task done font style
4848
* @property {string} taskDoneTextDecoration - The task done text decoration
49+
* @property {string} taskFocusFontColor - The focus task font color
50+
* @property {string} taskFocusBackgroundColor - The focus task background color
51+
* @property {string} taskFocusBorderRadius - The focus task border radius
4952
*/
5053

5154
/**

0 commit comments

Comments
 (0)
Please sign in to comment.