add duration
This commit is contained in:
@@ -19,6 +19,7 @@ class ToDoResource extends JsonResource
|
||||
'user_id' => $this->user_id,
|
||||
'name' => $this->name,
|
||||
'checked' => $this->checked,
|
||||
'duration' => $this->duration,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -57,8 +57,9 @@ const ToDoIndex: FC<ToDoIndexProps> = ({reload, setReload}) => {
|
||||
onChange={() =>toggleCheck(toDo)}
|
||||
className=""/>
|
||||
<Link to={"/todos/" + toDo.id}
|
||||
className={`${toDo.checked ? 'line-through' : ''} flex-1`}>
|
||||
{toDo.name}
|
||||
className={`${toDo.checked ? 'line-through' : ''} flex-1 flex justify-between`}>
|
||||
<span>{toDo.name}</span>
|
||||
<span className="text-gray-400 text-md mr-2">{toDo.duration} s</span>
|
||||
</Link>
|
||||
{!toDo.checked && <span className="cursor-pointer flex items-center"
|
||||
title="Commencer"
|
||||
|
||||
@@ -4,6 +4,8 @@ export interface toDo {
|
||||
name: string,
|
||||
checked: string|null,
|
||||
description?: string,
|
||||
duration: number,
|
||||
position: number,
|
||||
}
|
||||
|
||||
export interface timeTracker {
|
||||
|
||||
Reference in New Issue
Block a user