4
4
<h2 @blur =" updateTitle" contenteditable =" true" ref =" titleInput" @keydown.enter.prevent =" " spellcheck =" false" >
5
5
{{ title }}
6
6
</h2 >
7
- <CheckedBox label =" Due Date?" @checkbox-toggled =" handleCheckboxToggled" />
8
- <DateInput v-if =" dueDate " @date-selected =" handleDateChange" />
7
+ <CheckedBox label =" Due Date?" @checkbox-toggled =" handleCheckboxToggled" />
8
+ <DateInput v-if =" dueDateCheckbox " @date-selected =" handleDateChange" />
9
9
10
- <CheckedBox label =" Recurring task?" @checkbox-toggled =" handleRecurringTask" />
11
- <!-- Later: Recurring task checked = make ui and functions appear for making the list appear every day-->
10
+ <CheckedBox label =" Recurring task?" @checkbox-toggled =" handleRecurringTask" />
11
+ <!-- Later: Recurring task checked = make ui and functions appear for making the list appear every day-->
12
12
13
13
<button v-if =" debugMode" @click =" clearStorage" >clearStorage</button >
14
14
</div >
15
15
<div >
16
16
<div class =" input-container" >
17
- <button @click =" addItem " class =" add-button" >Remove</button >
17
+ <button @click =" removeItem " class =" add-button" >Remove</button >
18
18
</div >
19
19
<div >
20
20
</div >
24
24
<li v-for =" (item, index) in itemsArray" :key =" index" draggable =" true" @dragstart =" dragStart(index)"
25
25
@dragover =" dragOver" @drop =" drop(index)" >
26
26
<div class =" item-container" @click =" focusEditable(index)" >
27
- <button class =" remove-button" @click =" removeItem(index)" >X</button >
27
+ <span v-if =" index === selectedItemIndex" >✔️</span >
28
+ <CheckedBox label =" " @checkbox-toggled =" completeItem(index)" />
28
29
<div class =" text-cursor item-text" ref =" itemSpan" contenteditable =" true"
29
30
@keydown.enter.prevent =" handleEnter(index, $event)" @keydown.backspace =" handleBackspace(index, $event)"
30
31
@keydown.up =" handleArrowUp(index, $event)" @keydown.down =" handleArrowDown(index, $event)"
31
- @blur =" updateItem(index, $event)" spellcheck =" false" >{{ item }}</div >
32
+ @blur =" updateItem(index, $event)" spellcheck =" false" >{{ item.textString }}</div >
32
33
</div >
33
34
</li >
34
35
</ul >
45
46
<script >
46
47
import DateInput from ' ./DateInput.vue' ;
47
48
import CheckedBox from ' ./CheckBox.vue' ;
48
- import ' ./ListElement.css' ;
49
+ import ' ./ListElement.css' ;
49
50
export default {
50
51
name: ' ListElement' ,
51
52
props: {
@@ -57,15 +58,30 @@ export default {
57
58
data () {
58
59
return {
59
60
title: this .listName ,
60
- newItem: ' ' ,
61
61
itemsArray: [],
62
62
titlesArray: [],
63
+ completedItemsArray: [],
64
+ selectedItemIndex: 0 ,
63
65
draggedIndex: null ,
64
66
isDropdownOpen: false ,
65
- selectedMode: ' Mode 1' ,
66
- debugMode: false ,
67
- dueDate: false ,
68
- recurringTask: true
67
+ debugMode: true ,
68
+
69
+ textString: ' ' ,
70
+ dueDateCheckbox: false ,
71
+ dueDateDate: null ,
72
+ dueDateTime: null ,
73
+ taskTimeEstimate: null ,
74
+ recurringTask: false ,
75
+ recurringTaskEndDate: null ,
76
+ addToCalendarCheckbox: false ,
77
+
78
+ defaultDueDateCheckbox: false ,
79
+ defaultDueDateDate: null ,
80
+ defaultDueDateTime: null ,
81
+ defaultTaskTimeEstimate: null ,
82
+ defaultRecurringTask: false ,
83
+ defaultRecurringTaskEndDate: null ,
84
+ defaultAddToCalendarCheckbox: false
69
85
};
70
86
},
71
87
created () {
@@ -75,6 +91,9 @@ export default {
75
91
components: {
76
92
DateInput,
77
93
CheckedBox
94
+ },
95
+ computed: {
96
+
78
97
},
79
98
methods: {
80
99
loadInitialData () {
@@ -102,10 +121,13 @@ export default {
102
121
this .selectedDate = date; // Update the parent component's selectedDate
103
122
},
104
123
handleCheckboxToggled () {
105
- this .dueDate = ! this .dueDate ;
124
+ this .dueDateCheckbox = ! this .dueDateCheckbox ;
125
+ },
126
+ handleRecurringTask () {
127
+ this .recurringTask = ! this .recurringTask ;
106
128
},
107
- handleRecurringTask () {
108
- this . recurringTask = ! this . recurringTask ;
129
+ completeItem ( index ) {
130
+ // Adds item to the dropdownlist
109
131
},
110
132
updateTitle () {
111
133
this .saveList ();// Save the current list items to the title before changing the title
@@ -126,23 +148,42 @@ export default {
126
148
this .saveTitlesArray ();
127
149
}
128
150
localStorage .setItem (' title' , this .title );
129
- let newItems = localStorage .getItem (this .title )
130
- this .itemsArray = JSON .parse (newItems );
151
+ let textStrings = localStorage .getItem (this .title )
152
+ this .itemsArray = JSON .parse (textStrings );
131
153
},
132
154
saveList () {
133
155
localStorage .setItem (this .title , JSON .stringify (this .itemsArray ));
134
156
},
135
157
saveTitlesArray () {
136
158
localStorage .setItem (' titlesArray' , JSON .stringify (this .titlesArray ));
137
159
},
138
- addItem () {
139
- if (this .newItem .trim () !== ' ' ) {
140
- if (! this .itemsArray ) {
141
- this .itemsArray = [];
142
- }
143
- this .itemsArray .push (this .newItem .trim ());
144
- this .newItem = ' ' ;
145
- this .saveList ();
160
+ loadDefaultItemValues () {
161
+ // future makes api call to get this user's default values
162
+ },
163
+ createNewItem (text ) {
164
+ return {
165
+ textString: text,
166
+ dueDateCheckbox: false ,
167
+ dueDateDate: null ,
168
+ dueDateTime: null ,
169
+ taskTimeEstimate: null ,
170
+ recurringTask: false ,
171
+ recurringTaskEndDate: null ,
172
+ addToCalendarCheckbox: false ,
173
+ }
174
+ },
175
+ createItemWithExistingValues (text ) {
176
+ return {
177
+
178
+ // These could all instead be replaced with
179
+ textString: text,
180
+ dueDateCheckbox: this .dueDateCheckbox ,
181
+ dueDateDate: this .dueDateDate ,
182
+ dueDateTime: this .dueDateTime ,
183
+ taskTimeEstimate: this .taskTimeEstimate ,
184
+ recurringTask: this .recurringTask ,
185
+ recurringTaskEndDate: this .recurringTaskEndDate ,
186
+ addToCalendarCheckbox: this .addToCalendarCheckbox ,
146
187
}
147
188
},
148
189
dragStart (index ) {
@@ -158,7 +199,21 @@ export default {
158
199
this .draggedIndex = null ;
159
200
this .saveList ();
160
201
},
202
+ selectCurrentIndex (index ) {
203
+ this .selectedItemIndex = index;
204
+ },/*
205
+ populateCurrentValues(index) {
206
+ this.textString = this.itemsArray.textString[index];
207
+ this.dueDateCheckbox = this.itemsArray.textString[index];
208
+ this.dueDateDate = this.itemsArray[index];
209
+ this.dueDateTime = this.itemsArray[index];
210
+ this.taskTimeEstimate = this.itemsArray[index];
211
+ this.recurringTask = this.itemsArray[index];
212
+ this.recurringTaskEndDate = this.itemsArray[index];
213
+ this.addToCalendarCheckbox = this.itemsArray[index];
214
+ },*/
161
215
focusEditable (index , position = null ) {
216
+ this .selectedItemIndex = index;
162
217
this .$nextTick (() => {
163
218
const element = this .$refs .itemSpan [index];
164
219
if (element) {
@@ -180,8 +235,8 @@ export default {
180
235
const textBeforeCaret = text .substring (0 , caretPosition);
181
236
const textAfterCaret = text .substring (caretPosition);
182
237
183
- this .itemsArray .splice (index, 1 , textBeforeCaret);
184
- this .itemsArray .splice (index + 1 , 0 , textAfterCaret);
238
+ this .itemsArray .splice (index, 1 , this . createItemWithExistingValues ( textBeforeCaret) );
239
+ this .itemsArray .splice (index + 1 , 0 , this . createItemWithExistingValues ( textAfterCaret) );
185
240
186
241
this .$nextTick (() => {
187
242
this .focusEditable (index + 1 , 0 );
@@ -196,22 +251,22 @@ export default {
196
251
const previousText = this .itemsArray [index - 1 ];
197
252
const newText = previousText + currentText;
198
253
199
- this .itemsArray .splice (index - 1 , 1 , newText);
254
+ this .itemsArray .splice (index - 1 , 1 , this . createItemWithExistingValues ( newText) );
200
255
this .itemsArray .splice (index, 1 );
201
256
202
257
this .$nextTick (() => {
203
258
const previousElement = this .$refs .itemSpan [index - 1 ];
204
259
if (previousElement) {
205
260
previousElement .focus ();
206
261
this .setCaretPosition (previousElement, previousText .length );
207
- this .removeItem (index );
262
+ this .removeItem ();
208
263
}
209
264
this .saveList ();
210
265
});
211
266
}
212
267
},
213
268
handleArrowUp (index , event ) {
214
- if (event .target .innerText .length === 0 ) {
269
+ if (event .target .innerText .length === 0 && index - 1 >= 0 ) {
215
270
event .preventDefault (); // Prevent default arrow key behavior
216
271
this .focusEditable (index - 1 , this .itemsArray [index - 1 ].length );
217
272
}
@@ -223,13 +278,13 @@ export default {
223
278
// Check if the caret is in the top row
224
279
const isTopRow = rect .top === elementRect .top ;
225
280
226
- if (isTopRow && index > 0 || event .target .innerText .length === 0 ) {
281
+ if (( isTopRow || event .target .innerText .length === 0 ) && index - 1 > = 0 ) {
227
282
event .preventDefault (); // Prevent default arrow key behavior
228
283
this .focusEditable (index - 1 , this .itemsArray [index - 1 ].length );
229
284
}
230
285
},
231
286
handleArrowDown (index , event ) {
232
- if (event .target .innerText .length === 0 ) {
287
+ if (event .target .innerText .length === 0 && index + 1 < this . itemsArray . length ) {
233
288
event .preventDefault (); // Prevent default arrow key behavior
234
289
this .focusEditable (index + 1 , 0 );
235
290
}
@@ -240,17 +295,17 @@ export default {
240
295
241
296
const isBottomRow = Math .abs (rect .bottom - elementRect .bottom ) < 1 ;
242
297
243
- if (isBottomRow && index < this . itemsArray . length || event .target .innerText .length === 0 ) {
298
+ if (( isBottomRow || event .target .innerText .length === 0 ) && index + 1 < this . itemsArray . length ) {
244
299
event .preventDefault (); // Prevent default arrow key behavior
245
300
this .focusEditable (index + 1 , 0 );
246
301
}
247
302
},
248
303
updateItem (index , event ) {
249
- this .itemsArray .splice (index, 1 , event .target .innerText );
304
+ this .itemsArray .splice (index, 1 , this . createNewItem ( event .target .innerText ) );
250
305
this .saveList ();
251
306
},
252
- removeItem (index ) {
253
- this .itemsArray .splice (index , 1 );
307
+ removeItem () {
308
+ this .itemsArray .splice (this . selectedItemIndex , 1 );
254
309
this .saveList ();
255
310
256
311
// Ensure at least one empty item remains
@@ -260,7 +315,7 @@ export default {
260
315
261
316
// Check if the array is not empty and the index is valid before focusing
262
317
if (this .itemsArray .length > 0 ) {
263
- const newIndex = index === this .itemsArray .length ? index - 1 : index ;
318
+ const newIndex = this . selectedItemIndex === this .itemsArray .length ? this . selectedItemIndex - 1 : this . selectedItemIndex ;
264
319
this .$nextTick (() => {
265
320
this .focusEditable (newIndex);
266
321
});
@@ -285,7 +340,7 @@ export default {
285
340
localStorage .clear ();
286
341
this .title = ' Daily List'
287
342
this .itemsArray = this .titlesArray = [];
288
- this .newItem = ' ' ;
343
+ this .textString = ' ' ;
289
344
this .loadInitialData ();
290
345
},
291
346
toggleDropdown () {
0 commit comments