diff --git a/app/Http/Resources/ToDoResource.php b/app/Http/Resources/ToDoResource.php index df484c6..8be4c9c 100644 --- a/app/Http/Resources/ToDoResource.php +++ b/app/Http/Resources/ToDoResource.php @@ -19,6 +19,7 @@ class ToDoResource extends JsonResource 'user_id' => $this->user_id, 'name' => $this->name, 'checked' => $this->checked, + 'duration' => $this->duration, ]; } } diff --git a/app/Models/User.php b/app/Models/User.php index d731b09..0aeaa77 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -58,7 +58,12 @@ class User extends Authenticatable public function stopCurrentTimeTracker(): void { - $this->currentTimeTracker()->update(['end_at' => now()]); + $end = now(); + $delay = $end->diffInSeconds($this->currentTimeTracker->start_at); + $toDo = $this->currentTimeTracker->toDo; + $toDo->duration = $toDo->duration + $delay; + $toDo->save(); + $this->currentTimeTracker()->update(['end_at' => $end]); $this->time_tracker_id = null; $this->save(); } diff --git a/database/migrations/2024_02_15_225248_add_position_and_duration_to_to_dos_table.php b/database/migrations/2024_02_15_225248_add_position_and_duration_to_to_dos_table.php new file mode 100644 index 0000000..83ac911 --- /dev/null +++ b/database/migrations/2024_02_15_225248_add_position_and_duration_to_to_dos_table.php @@ -0,0 +1,30 @@ +unsignedInteger('duration')->default(0)->after('description'); + $table->unsignedInteger('position')->default(0)->after('description'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('to_dos', function (Blueprint $table) { + $table->dropColumn('position'); + $table->dropColumn('duration'); + }); + } +}; diff --git a/resources/js/components/toDos/ToDoIndex.tsx b/resources/js/components/toDos/ToDoIndex.tsx index 0bda68a..fde8630 100644 --- a/resources/js/components/toDos/ToDoIndex.tsx +++ b/resources/js/components/toDos/ToDoIndex.tsx @@ -57,8 +57,9 @@ const ToDoIndex: FC = ({reload, setReload}) => { onChange={() =>toggleCheck(toDo)} className=""/> - {toDo.name} + className={`${toDo.checked ? 'line-through' : ''} flex-1 flex justify-between`}> + {toDo.name} + {toDo.duration} s {!toDo.checked &&