add duration

This commit is contained in:
Romulus21
2024-02-15 23:09:13 +01:00
parent b326f79f2d
commit 335fc8b12b
5 changed files with 42 additions and 3 deletions

View File

@@ -19,6 +19,7 @@ class ToDoResource extends JsonResource
'user_id' => $this->user_id, 'user_id' => $this->user_id,
'name' => $this->name, 'name' => $this->name,
'checked' => $this->checked, 'checked' => $this->checked,
'duration' => $this->duration,
]; ];
} }
} }

View File

@@ -58,7 +58,12 @@ class User extends Authenticatable
public function stopCurrentTimeTracker(): void 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->time_tracker_id = null;
$this->save(); $this->save();
} }

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('to_dos', function (Blueprint $table) {
$table->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');
});
}
};

View File

@@ -57,8 +57,9 @@ const ToDoIndex: FC<ToDoIndexProps> = ({reload, setReload}) => {
onChange={() =>toggleCheck(toDo)} onChange={() =>toggleCheck(toDo)}
className=""/> className=""/>
<Link to={"/todos/" + toDo.id} <Link to={"/todos/" + toDo.id}
className={`${toDo.checked ? 'line-through' : ''} flex-1`}> className={`${toDo.checked ? 'line-through' : ''} flex-1 flex justify-between`}>
{toDo.name} <span>{toDo.name}</span>
<span className="text-gray-400 text-md mr-2">{toDo.duration} s</span>
</Link> </Link>
{!toDo.checked && <span className="cursor-pointer flex items-center" {!toDo.checked && <span className="cursor-pointer flex items-center"
title="Commencer" title="Commencer"

View File

@@ -4,6 +4,8 @@ export interface toDo {
name: string, name: string,
checked: string|null, checked: string|null,
description?: string, description?: string,
duration: number,
position: number,
} }
export interface timeTracker { export interface timeTracker {