Skip to content

Commit ff897cf

Browse files
author
Plastique Brian
committed
v0.15.0 - added a "play" and "stop" button
* added a "play" and "stop" button, to launch the task, and to stop tracking it * these buttons are necessary in order to be able to tell if the task is currently being tracked or not * had to add a volatile "isTracking" field on the task model * had to deal with a vicious bug in Todo.svelte. The play / stop font awesome icon, conditionally rendered by svelte, was crashing the app. Had to add an additional container span. cf sveltejs/svelte#5290 (comment) and https://stackoverflow.com/questions/58768701/sapper-how-do-i-fix-parentnode-is-null-when-navigating-away-from-a-page-with * layout => moved the play / stop icon before the task title
1 parent bacb06c commit ff897cf

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

src/Todo.svelte

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,50 @@ export let todo;
1616
text-align: right;
1717
}
1818
19+
/* TODO: messy styles => may be cleaned later maybe. Just did what I needed.. class below
20+
to align the play/stop button with the title... */
21+
.task-title {
22+
/* vertical-align: middle; */
23+
display: flex;
24+
/* align-items: center; */
25+
align-items: stretch;
26+
}
27+
1928
.modify-duration-button {
2029
color: hsl(14, 100%, 53%);
2130
display: none;
2231
}
32+
33+
.stop-button {
34+
height: 100%;
35+
margin-right: 10px;
36+
}
2337
</style>
2438
<!-------------------------------------------------------------------------------->
2539
<!--------------- LAYOUT OF A TASK ---------------->
2640
<!-------------------------------------------------------------------------------->
2741
<div transition:fade class="box">
2842
<div class="content columns is-multiline is-mobile">
29-
<div class="{'done-' + todo.done} column task-title is-5 py-0 is-clickable" on:click={()=> dispatch('switchTracking')}>
30-
<strong>{todo.title}</strong>
43+
<div class="{'done-' + todo.done} column task-title is-5 is-clickable" on:click={()=> dispatch('switchTracking')}>
44+
{#if todo.isTracking}
45+
<span class="task-title">
46+
<!-- must keep this apparently useless span container => fixes conflict between
47+
svelte registering the original span , and font awesome transforming it to an svg
48+
https://github.com/sveltejs/svelte/issues/5290#issuecomment-691712604
49+
https://stackoverflow.com/questions/58768701/sapper-how-do-i-fix-parentnode-is-null-when-navigating-away-from-a-page-with
50+
-->
51+
52+
<span class='stop-button fas fa-stop-circle has-text-danger is-size-5'></span>
53+
54+
<strong>{todo.title}</strong>
55+
</span>
56+
{:else}
57+
<span>
58+
<span class='fas fa-play is-size-7'></span>
59+
|
60+
<strong>{todo.title}</strong>
61+
</span>
62+
{/if}
3163
</div>
3264
<div class="column task-more-info is-2 py-0 modal-button" data-target="my-modal">
3365
<span class="icon has-text-info">

src/TodoList.svelte

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
}
7878
}
7979
80+
function getCurrentTask() {
81+
console.log("current task:" + JSON.stringify(todos.find((task) => task._id === currentTaskTracking.taskId)));
82+
return todos.find((task) => task._id === currentTaskTracking.taskId);
83+
}
84+
85+
8086
/* const moreThanOneHourInSeconds = 3667;
8187
console.log(timeConvert(moreThanOneHourInSeconds)); */
8288
@@ -140,6 +146,7 @@
140146
todos.forEach((todo) => {
141147
todo.duration = todo.durationForToday; // tmp TODO remove!!!!!!!!!!
142148
updateDurationToDisplay(todo);
149+
todo.isTracking = false;
143150
});
144151
145152
// get currentTaskTracking
@@ -153,6 +160,11 @@
153160
154161
updateCurrentTaskTrackingDuration();
155162
163+
if (currentTaskTracking.isTracking) {
164+
let currentTask = getCurrentTask();
165+
currentTask.isTracking = true;
166+
}
167+
156168
// launch the "eternal" timer that updates the display of the duration
157169
interval = setInterval(() => {
158170
updateCurrentTaskTrackingDuration();
@@ -239,6 +251,7 @@
239251
// updates the task duration
240252
previousTodo = todos.find((t) => t._id === currentTaskTracking.taskId);
241253
previousTodo.duration += durationSeconds;
254+
previousTodo.isTracking = false;
242255
243256
// must save the tracking period we've just ended
244257
previousTodo.trackingByDate.push({
@@ -250,33 +263,45 @@
250263
// TODO => bug?? useless call ???? sendUpdateCurrentTaskTracking();
251264
// hack to update the array of todos in child Task.svelte,
252265
// in order to update this previousTodo display
253-
todos = todos;
266+
// todos = todos;
254267
console.log(previousTodo);
255268
sendUpdateTask(previousTodo);
256269
}
257270
258-
const currentTaskTitle = todos.find((t) => t._id === todoId).title;
271+
const newTaskTracking = todos.find((t) => t._id === todoId);
259272
260273
// if we were tracking the selected task of id todoId => just stop tracking
261274
if (currentTaskTracking.taskId == todoId) {
262275
currentTaskTracking = { ...NO_TASK_TRACKING };
263-
console.log(`${getCurrentTimeString()}: stopped task '${currentTaskTitle}'`);
276+
console.log(`${getCurrentTimeString()}: stopped task '${newTaskTracking.title}'`);
264277
} else {
265278
// else switch to selected task
266279
currentTaskTracking.isTracking = true;
267280
currentTaskTracking.taskId = todoId;
268281
currentTaskTracking.timeBeginTracking = Date.now() - 1000;
282+
newTaskTracking.isTracking = true;
283+
console.log(newTaskTracking);
284+
console.log(`${getCurrentTimeString()}: switching to task '${newTaskTracking.title}'`);
269285
}
270286
271287
updateCurrentTaskTrackingDuration();
272-
sendUpdateCurrentTaskTracking();
273-
console.log(`${getCurrentTimeString()}: switching to task '${currentTaskTitle}`);
288+
sendUpdateCurrentTaskTracking();
289+
290+
todos = todos; // hack
291+
console.log('switched to task:' + JSON.stringify(todos.find((t) => t._id === todoId)));
274292
275293
interval = setInterval(() => {
276294
updateCurrentTaskTrackingDuration();
277295
}, 500);
278296
}
279297
298+
function switchTracking2(todoId) {
299+
const newTaskTracking = todos.find((t) => t._id === todoId);
300+
newTaskTracking.isTracking = true;
301+
todos = todos;
302+
303+
}
304+
280305
const createTodo = (title, done = false, duration = 0, enabled = true) => {
281306
// async function createTodo(title, done = false, duration = 0, enabled = true) {
282307
const newTodo = {
@@ -325,6 +350,7 @@
325350
vertical-align: top;
326351
} */
327352
.make-children-div-full-height {
353+
display: flex;
328354
align-items: stretch;
329355
/* a "flex" option apparently, needed to have the info header dv (the one with the nb of tasks) to be full height
330356
to align the text to the new task input field...

0 commit comments

Comments
 (0)