update time visualization
This commit is contained in:
@@ -1,12 +1,41 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from "react";
|
||||||
import { Play, Square, ChevronDown } from 'lucide-react';
|
import { Play, Square, ChevronDown } from "lucide-react";
|
||||||
import { useTimer } from '@/contexts/TimerContext';
|
import { useTimer } from "@/contexts/TimerContext";
|
||||||
import { useProjects } from '@/hooks/useProjects';
|
import { useProjects } from "@/hooks/useProjects";
|
||||||
import { formatDuration } from '@/utils/dateUtils';
|
import { ProjectColorDot } from "@/components/ProjectColorDot";
|
||||||
import { ProjectColorDot } from '@/components/ProjectColorDot';
|
|
||||||
|
function TimerDisplay({ totalSeconds }: { totalSeconds: number }) {
|
||||||
|
const hours = Math.floor(totalSeconds / 3600);
|
||||||
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||||
|
const seconds = totalSeconds % 60;
|
||||||
|
|
||||||
|
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className="text-2xl font-mono font-bold text-gray-900">
|
||||||
|
{hours > 0 && (
|
||||||
|
<>
|
||||||
|
<span className="mr-0.5">{pad(hours)}</span>
|
||||||
|
<span className="text-base font-normal text-gray-500 mr-1.5">h</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<span className="mr-0.5">{pad(minutes)}</span>
|
||||||
|
<span className="text-base font-normal text-gray-500 mr-1.5">m</span>
|
||||||
|
<span className="mr-0.5">{pad(seconds)}</span>
|
||||||
|
<span className="text-base font-normal text-gray-500">s</span>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function TimerWidget() {
|
export function TimerWidget() {
|
||||||
const { ongoingTimer, isLoading, elapsedSeconds, startTimer, stopTimer, updateTimerProject } = useTimer();
|
const {
|
||||||
|
ongoingTimer,
|
||||||
|
isLoading,
|
||||||
|
elapsedSeconds,
|
||||||
|
startTimer,
|
||||||
|
stopTimer,
|
||||||
|
updateTimerProject,
|
||||||
|
} = useTimer();
|
||||||
const { projects } = useProjects();
|
const { projects } = useProjects();
|
||||||
const [showProjectSelect, setShowProjectSelect] = useState(false);
|
const [showProjectSelect, setShowProjectSelect] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
@@ -16,7 +45,7 @@ export function TimerWidget() {
|
|||||||
try {
|
try {
|
||||||
await startTimer();
|
await startTimer();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Failed to start timer');
|
setError(err instanceof Error ? err.message : "Failed to start timer");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,7 +54,7 @@ export function TimerWidget() {
|
|||||||
try {
|
try {
|
||||||
await stopTimer();
|
await stopTimer();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Failed to stop timer');
|
setError(err instanceof Error ? err.message : "Failed to stop timer");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,7 +64,7 @@ export function TimerWidget() {
|
|||||||
await updateTimerProject(projectId);
|
await updateTimerProject(projectId);
|
||||||
setShowProjectSelect(false);
|
setShowProjectSelect(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Failed to update project');
|
setError(err instanceof Error ? err.message : "Failed to update project");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -45,7 +74,7 @@ export function TimerWidget() {
|
|||||||
await updateTimerProject(null);
|
await updateTimerProject(null);
|
||||||
setShowProjectSelect(false);
|
setShowProjectSelect(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Failed to clear project');
|
setError(err instanceof Error ? err.message : "Failed to clear project");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -68,9 +97,7 @@ export function TimerWidget() {
|
|||||||
<div className="flex items-center space-x-4 flex-1">
|
<div className="flex items-center space-x-4 flex-1">
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<div className="w-3 h-3 bg-red-500 rounded-full animate-pulse"></div>
|
<div className="w-3 h-3 bg-red-500 rounded-full animate-pulse"></div>
|
||||||
<span className="text-2xl font-mono font-bold text-gray-900">
|
<TimerDisplay totalSeconds={elapsedSeconds} />
|
||||||
{formatDuration(elapsedSeconds)}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Project Selector */}
|
{/* Project Selector */}
|
||||||
@@ -110,8 +137,12 @@ export function TimerWidget() {
|
|||||||
>
|
>
|
||||||
<ProjectColorDot color={project.color} />
|
<ProjectColorDot color={project.color} />
|
||||||
<div className="min-w-0">
|
<div className="min-w-0">
|
||||||
<div className="font-medium text-gray-900 truncate">{project.name}</div>
|
<div className="font-medium text-gray-900 truncate">
|
||||||
<div className="text-xs text-gray-500 truncate">{project.client.name}</div>
|
{project.name}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-gray-500 truncate">
|
||||||
|
{project.client.name}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { ProjectColorDot } from "@/components/ProjectColorDot";
|
|||||||
import { StatCard } from "@/components/StatCard";
|
import { StatCard } from "@/components/StatCard";
|
||||||
import {
|
import {
|
||||||
formatDate,
|
formatDate,
|
||||||
formatDurationFromDates,
|
formatDurationFromDatesHoursMinutes,
|
||||||
formatDurationHoursMinutes,
|
formatDurationHoursMinutes,
|
||||||
calculateDuration,
|
calculateDuration,
|
||||||
} from "@/utils/dateUtils";
|
} from "@/utils/dateUtils";
|
||||||
@@ -123,8 +123,8 @@ export function DashboardPage() {
|
|||||||
<td className="px-4 py-3 whitespace-nowrap text-sm text-gray-500">
|
<td className="px-4 py-3 whitespace-nowrap text-sm text-gray-500">
|
||||||
{formatDate(entry.startTime)}
|
{formatDate(entry.startTime)}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-4 py-3 whitespace-nowrap text-sm text-gray-900 font-mono">
|
<td className="px-4 py-3 whitespace-nowrap text-sm text-gray-900 font-mono">
|
||||||
{formatDurationFromDates(entry.startTime, entry.endTime)}
|
{formatDurationFromDatesHoursMinutes(entry.startTime, entry.endTime)}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { useStatistics } from "@/hooks/useTimeEntries";
|
|||||||
import { useClients } from "@/hooks/useClients";
|
import { useClients } from "@/hooks/useClients";
|
||||||
import { useProjects } from "@/hooks/useProjects";
|
import { useProjects } from "@/hooks/useProjects";
|
||||||
import { ProjectColorDot } from "@/components/ProjectColorDot";
|
import { ProjectColorDot } from "@/components/ProjectColorDot";
|
||||||
import { formatDuration, toISOTimezone } from "@/utils/dateUtils";
|
import { formatDurationHoursMinutes, toISOTimezone } from "@/utils/dateUtils";
|
||||||
import type { StatisticsFilters } from "@/types";
|
import type { StatisticsFilters } from "@/types";
|
||||||
|
|
||||||
export function StatisticsPage() {
|
export function StatisticsPage() {
|
||||||
@@ -166,7 +166,7 @@ export function StatisticsPage() {
|
|||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<span className="text-2xl">Loading...</span>
|
<span className="text-2xl">Loading...</span>
|
||||||
) : (
|
) : (
|
||||||
formatDuration(statistics?.totalSeconds || 0)
|
formatDurationHoursMinutes(statistics?.totalSeconds || 0)
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -202,7 +202,7 @@ export function StatisticsPage() {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<span className="font-mono font-semibold text-gray-900">
|
<span className="font-mono font-semibold text-gray-900">
|
||||||
{formatDuration(project.totalSeconds)}
|
{formatDurationHoursMinutes(project.totalSeconds)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
@@ -232,7 +232,7 @@ export function StatisticsPage() {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<span className="font-mono font-semibold text-gray-900">
|
<span className="font-mono font-semibold text-gray-900">
|
||||||
{formatDuration(client.totalSeconds)}
|
{formatDurationHoursMinutes(client.totalSeconds)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useProjects } from '@/hooks/useProjects';
|
|||||||
import { Modal } from '@/components/Modal';
|
import { Modal } from '@/components/Modal';
|
||||||
import { Spinner } from '@/components/Spinner';
|
import { Spinner } from '@/components/Spinner';
|
||||||
import { ProjectColorDot } from '@/components/ProjectColorDot';
|
import { ProjectColorDot } from '@/components/ProjectColorDot';
|
||||||
import { formatDate, formatDurationFromDates, getLocalISOString, toISOTimezone } from '@/utils/dateUtils';
|
import { formatDate, formatDurationFromDatesHoursMinutes, getLocalISOString, toISOTimezone } from '@/utils/dateUtils';
|
||||||
import type { TimeEntry, CreateTimeEntryInput, UpdateTimeEntryInput } from '@/types';
|
import type { TimeEntry, CreateTimeEntryInput, UpdateTimeEntryInput } from '@/types';
|
||||||
|
|
||||||
export function TimeEntriesPage() {
|
export function TimeEntriesPage() {
|
||||||
@@ -127,7 +127,7 @@ export function TimeEntriesPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-4 py-3 whitespace-nowrap text-sm font-mono text-gray-900">{formatDurationFromDates(entry.startTime, entry.endTime)}</td>
|
<td className="px-4 py-3 whitespace-nowrap text-sm font-mono text-gray-900">{formatDurationFromDatesHoursMinutes(entry.startTime, entry.endTime)}</td>
|
||||||
<td className="px-4 py-3 whitespace-nowrap text-right">
|
<td className="px-4 py-3 whitespace-nowrap text-right">
|
||||||
<button onClick={() => handleOpenModal(entry)} className="p-1.5 text-gray-400 hover:text-gray-600 mr-1"><Edit2 className="h-4 w-4" /></button>
|
<button onClick={() => handleOpenModal(entry)} className="p-1.5 text-gray-400 hover:text-gray-600 mr-1"><Edit2 className="h-4 w-4" /></button>
|
||||||
<button onClick={() => handleDelete(entry)} className="p-1.5 text-gray-400 hover:text-red-600"><Trash2 className="h-4 w-4" /></button>
|
<button onClick={() => handleDelete(entry)} className="p-1.5 text-gray-400 hover:text-red-600"><Trash2 className="h-4 w-4" /></button>
|
||||||
|
|||||||
@@ -57,6 +57,14 @@ export function formatDurationFromDates(
|
|||||||
return formatDuration(seconds);
|
return formatDuration(seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatDurationFromDatesHoursMinutes(
|
||||||
|
startTime: string,
|
||||||
|
endTime: string,
|
||||||
|
): string {
|
||||||
|
const seconds = calculateDuration(startTime, endTime);
|
||||||
|
return formatDurationHoursMinutes(seconds);
|
||||||
|
}
|
||||||
|
|
||||||
export function getLocalISOString(date: Date = new Date()): string {
|
export function getLocalISOString(date: Date = new Date()): string {
|
||||||
const timezoneOffset = date.getTimezoneOffset() * 60000;
|
const timezoneOffset = date.getTimezoneOffset() * 60000;
|
||||||
const localISOTime = new Date(date.getTime() - timezoneOffset)
|
const localISOTime = new Date(date.getTime() - timezoneOffset)
|
||||||
|
|||||||
Reference in New Issue
Block a user