Skip to content

Commit 54ed596

Browse files
committed
Add some comments and TSDoc documentation
1 parent e3f6bae commit 54ed596

File tree

4 files changed

+59
-13
lines changed

4 files changed

+59
-13
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-app",
3-
"version": "0.1.0",
3+
"version": "1.0.0",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",
@@ -33,4 +33,4 @@
3333
"gitHooks": {
3434
"pre-commit": "lint-staged"
3535
}
36-
}
36+
}

src/components/NewTodo.vue

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ import { difficulty, priority, repeatFrequency } from "./TodoList.vue";
6464
import { defineComponent } from "vue";
6565
6666
export interface todoTask {
67-
task: string;
68-
dueDate: Date;
69-
priority: number;
70-
difficulty: number;
71-
repeatOften: number;
72-
repeatFrequency: number;
73-
newId: number;
74-
completed: boolean;
75-
timesCompleted: number;
76-
originalDueDate: Date;
67+
task: string; //task name
68+
dueDate: Date; //task due date
69+
priority: number; //task priority
70+
difficulty: number; //task difficulty
71+
repeatOften: number; //task repetition number of days/weeks/months/years
72+
repeatFrequency: number; //task repetition frequency
73+
newId: number; //task id
74+
completed: boolean; //task completed or not
75+
timesCompleted: number; //times task has been completed
76+
originalDueDate: Date; //task original due date
7777
}
7878
const currentUtcDate: Date = new Date();
7979
const currentLocalDate: Date = new Date(
@@ -102,6 +102,9 @@ export default defineComponent({
102102
dueDateInput.min = currentLocalDate.toISOString().split("T")[0]; //minimum due date must be today
103103
},
104104
methods: {
105+
/**
106+
* Add task to todo list when user presses the Add Todo button.
107+
*/
105108
addTodo: function (): void | todoTask[] {
106109
this.dueDate = this.originalDueDate; //set task due date to entered task original due date
107110
store.dispatch("createTask", this);

src/components/TodoList.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,17 @@ export default defineComponent({
9696
},
9797
},
9898
methods: {
99+
/**
100+
* Complete task based on task ID.
101+
* @param id task id
102+
*/
99103
completeTodo: function (id: number) {
100104
store.dispatch("completeTask", id);
101105
},
106+
/**
107+
* Delete task based on task ID.
108+
* @param id task id
109+
*/
102110
deleteTodo: function (id: number) {
103111
store.dispatch("deleteTask", id);
104112
},

src/store/index.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export default createStore({
1818
getProgress: (state) => state.user.progress, //get user level progress
1919
},
2020
mutations: {
21+
/**
22+
* Update user XP state when user presses Complete button to complete the task.
23+
*/
2124
updateXp: (state, payload) => {
2225
const task = state.todos.find(
2326
(todo: { newId: number }) => todo.newId === payload
@@ -88,6 +91,9 @@ export default createStore({
8891
100; //calculate level progress and if level is 1 set total xp at the start of level 1 to 0 xp
8992
},
9093
create_Todo: (state, payload) => {
94+
/**
95+
* Create the task when user presses the Add Todo button.
96+
*/
9197
const createTask = {
9298
newId: payload.newId as number,
9399
task: payload.task as string,
@@ -104,6 +110,9 @@ export default createStore({
104110
state.todos.unshift(createTask);
105111
},
106112
complete_Todo: (state, payload) => {
113+
/**
114+
* Complete the task when user presses the Complete button.
115+
*/
107116
const item = state.todos.find(
108117
(todo: { newId: number }) => todo.newId === payload
109118
);
@@ -237,6 +246,9 @@ export default createStore({
237246
}
238247
},
239248
delete_Todo: (state, payload) => {
249+
/**
250+
* Delete the task when user confirms task deletion alert after pressing the Delete button.
251+
*/
240252
const index = state.todos.findIndex(
241253
(todo: { newId: number }) => todo.newId === payload
242254
);
@@ -256,35 +268,58 @@ export default createStore({
256268
state.user = user; //set user data
257269
},
258270
setTodos: (state, todos) => {
259-
state.todos = todos; //set user data
271+
state.todos = todos; //set todos data
260272
},
261273
},
262274
actions: {
263275
createTask: (context, payload) => {
276+
/**
277+
* Action to create the task.
278+
*/
264279
context.commit("create_Todo", payload);
265280
},
266281
completeTask: (context, payload) => {
282+
/**
283+
* Action to complete the task.
284+
*/
267285
context.commit("complete_Todo", payload);
268286
context.commit("updateXp", payload);
269287
},
270288
deleteTask: (context, payload) => {
289+
/**
290+
* Action to delete the task.
291+
*/
271292
context.commit("delete_Todo", payload);
272293
},
273294
saveUser(context, user) {
295+
/**
296+
* Action to save user data to local storage.
297+
* @param user the user data
298+
*/
274299
localStorage.setItem("user", JSON.stringify(user)); //save user data
275300
context.commit("setUser", user);
276301
},
277302
loadUser(context) {
303+
/**
304+
* Action to load user data from local storage.
305+
*/
278306
const user = JSON.parse(localStorage.getItem("user") as string); //load user data
279307
if (user) {
280308
context.commit("setUser", user);
281309
}
282310
},
283311
saveTodos(context, todos) {
312+
/**
313+
* Action to save task list data to local storage.
314+
* @param todos the task list data
315+
*/
284316
localStorage.setItem("todos", JSON.stringify(todos)); //save task list data
285317
context.commit("setTodos", todos);
286318
},
287319
loadTodos(context) {
320+
/**
321+
* Action to load task list data to local storage.
322+
*/
288323
const todos = JSON.parse(localStorage.getItem("todos") as string); //load task list data
289324
if (todos) {
290325
context.commit("setTodos", todos);

0 commit comments

Comments
 (0)