show timming in hh:mm:ss
This commit is contained in:
parent
2212359c96
commit
45a3040614
|
|
@ -116,22 +116,22 @@ const DashboardLayout = () => {
|
|||
const [loadingStop, setLoadingStop] = useState(false);
|
||||
|
||||
|
||||
// ✅ Create a ref to store the stop function so it can be called from the hook
|
||||
// Create a ref to store the stop function so it can be called from the hook
|
||||
const stopTrackingRef = useRef<(() => Promise<void>) | null>(null);
|
||||
|
||||
// ✅ Define handleStopTracking FIRST
|
||||
// Define handleStopTracking FIRST
|
||||
const handleStopTracking = useCallback(async () => {
|
||||
if (loadingStop || loadingStart) return;
|
||||
|
||||
if (!selectedProject) {
|
||||
console.warn("⚠️ No selected project to stop");
|
||||
console.warn("No selected project to stop");
|
||||
return;
|
||||
}
|
||||
|
||||
const projectId = selectedProject.projectId;
|
||||
|
||||
console.log("🛑 Stop tracking initiated for:", selectedProject.projectName);
|
||||
console.log("📊 Current elapsed time:", elapsedTime);
|
||||
console.log(" Stop tracking initiated for:", selectedProject.projectName);
|
||||
console.log(" Current elapsed time:", elapsedTime);
|
||||
|
||||
setLoadingStop(true);
|
||||
|
||||
|
|
@ -139,11 +139,11 @@ const DashboardLayout = () => {
|
|||
// This ensures the last window activity is recorded before logout
|
||||
if (stopTrackingRef.current) {
|
||||
try {
|
||||
console.log("📤 Sending final PATCH to record last activity...");
|
||||
console.log(" Sending final PATCH to record last activity...");
|
||||
await stopTrackingRef.current();
|
||||
console.log("✅ Final tracking data sent successfully");
|
||||
console.log(" Final tracking data sent successfully");
|
||||
} catch (error) {
|
||||
console.error("❌ Error sending final tracking data:", error);
|
||||
console.error(" Error sending final tracking data:", error);
|
||||
// Continue with stop even if PATCH fails
|
||||
}
|
||||
} else {
|
||||
|
|
@ -169,9 +169,9 @@ const DashboardLayout = () => {
|
|||
|
||||
console.log("📡 Sending LOGOUT request:", payload);
|
||||
const res = await window.electron.stopProjectTracking(payload);
|
||||
console.log("✅ LOGOUT successful:", res);
|
||||
console.log(" LOGOUT successful:", res);
|
||||
} catch (error) {
|
||||
console.error("❌ Failed to send LOGOUT:", error);
|
||||
console.error(" Failed to send LOGOUT:", error);
|
||||
}
|
||||
|
||||
// STEP 4: Update UI (window restore)
|
||||
|
|
@ -179,9 +179,9 @@ const DashboardLayout = () => {
|
|||
await window.electron.toggleCloseBtn(true);
|
||||
await window.electron.resizeWindow(500, 600);
|
||||
toggleWindowSize.current = true;
|
||||
console.log("✅ Window UI restored");
|
||||
console.log(" Window UI restored");
|
||||
} catch (error) {
|
||||
console.error("❌ Error restoring window:", error);
|
||||
console.error(" Error restoring window:", error);
|
||||
}
|
||||
|
||||
// STEP 5: Update Redux tracking state → THIS TRIGGERS UI UPDATE
|
||||
|
|
@ -194,7 +194,7 @@ const DashboardLayout = () => {
|
|||
|
||||
// Allow React to process the state update
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
console.log("✅ Redux state updated - isTracking is now false");
|
||||
console.log(" Redux state updated - isTracking is now false");
|
||||
|
||||
// STEP 6: Clear active project log ID
|
||||
setActiveProjectLogId("");
|
||||
|
|
@ -212,12 +212,12 @@ const DashboardLayout = () => {
|
|||
console.log("=".repeat(50));
|
||||
}, [selectedProject, projectSummary, elapsedTime, dispatch]);
|
||||
|
||||
// ✅ NOW define handleLimitExceeded using the defined handleStopTracking
|
||||
// NOW define handleLimitExceeded using the defined handleStopTracking
|
||||
const handleLimitExceeded = useCallback(async () => {
|
||||
console.log("🚨 LIMIT EXCEEDED - Auto-stopping tracking");
|
||||
|
||||
if (!selectedProject) {
|
||||
console.error("❌ No selected project for limit exceeded");
|
||||
console.error(" No selected project for limit exceeded");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ const DashboardLayout = () => {
|
|||
await handleStopTracking();
|
||||
}, [selectedProject, handleStopTracking]);
|
||||
|
||||
// ✅ Initialize useActiveAppTracker and store finalizeTracking in ref
|
||||
// Initialize useActiveAppTracker and store finalizeTracking in ref
|
||||
const { finalizeTracking } = useActiveAppTracker(
|
||||
isTracking,
|
||||
activeProjectLogId,
|
||||
|
|
@ -242,7 +242,7 @@ const DashboardLayout = () => {
|
|||
handleLimitExceeded
|
||||
);
|
||||
|
||||
// ✅ Update the ref whenever finalizeTracking changes
|
||||
// Update the ref whenever finalizeTracking changes
|
||||
useEffect(() => {
|
||||
stopTrackingRef.current = finalizeTracking;
|
||||
}, [finalizeTracking]);
|
||||
|
|
@ -267,7 +267,7 @@ const DashboardLayout = () => {
|
|||
await handleStopTracking(); // Wait until stop is completed
|
||||
console.log("🛑 Tracking stopped successfully before logout");
|
||||
} catch (err) {
|
||||
console.error("❌ Error while stopping tracking after token expiry:", err);
|
||||
console.error(" Error while stopping tracking after token expiry:", err);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -302,7 +302,7 @@ const DashboardLayout = () => {
|
|||
|
||||
if (loadingStart || loadingStop) return;
|
||||
|
||||
// ✅ Check limit before starting
|
||||
// Check limit before starting
|
||||
const limitCheck = canStartTracking(project);
|
||||
if (!limitCheck.canStart) {
|
||||
alert(
|
||||
|
|
@ -346,7 +346,7 @@ const DashboardLayout = () => {
|
|||
);
|
||||
|
||||
setActiveProjectLogId(res?.data?.logId);
|
||||
console.log("✅ Tracking started. Log ID:", res?.data?.logId);
|
||||
console.log(" Tracking started. Log ID:", res?.data?.logId);
|
||||
|
||||
// ⬇️ Calculate time limit in seconds
|
||||
const parseTimeToSeconds = (timeStr: string): number => {
|
||||
|
|
@ -381,7 +381,7 @@ const DashboardLayout = () => {
|
|||
})
|
||||
);
|
||||
|
||||
// ✅ Check if time limit reached
|
||||
// Check if time limit reached
|
||||
const totalTimeWorked = alreadyWorkedSeconds + Math.floor((Date.now() - now) / 1000);
|
||||
|
||||
if (totalTimeWorked >= dedicatedSeconds) {
|
||||
|
|
@ -400,7 +400,7 @@ const DashboardLayout = () => {
|
|||
}, 1000);
|
||||
|
||||
} catch (error) {
|
||||
console.error("❌ Failed to sync project start:", error);
|
||||
console.error(" Failed to sync project start:", error);
|
||||
alert("Something went wrong!");
|
||||
await window.electron.toggleCloseBtn(true);
|
||||
} finally {
|
||||
|
|
@ -457,7 +457,9 @@ const DashboardLayout = () => {
|
|||
const formatTime = (seconds: number) => {
|
||||
const hrs = Math.floor(seconds / 3600);
|
||||
const mins = Math.floor((seconds % 3600) / 60);
|
||||
return `${hrs}h ${mins}m`;
|
||||
const secs = seconds % 60;
|
||||
return `${hrs}h ${mins}m ${secs}s`;
|
||||
// return `${hrs}h ${mins}m `;
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ const formatTime = (seconds: number) => {
|
|||
const hrs = Math.floor(seconds / 3600);
|
||||
const mins = Math.floor((seconds % 3600) / 60);
|
||||
const secs = seconds % 60;
|
||||
// return `${hrs}h ${mins}m ${secs}s`;
|
||||
return `${hrs}h ${mins}m `;
|
||||
return `${hrs}h ${mins}m ${secs}s`;
|
||||
// return `${hrs}h ${mins}m `;
|
||||
};
|
||||
|
||||
// Widget Component
|
||||
|
|
@ -369,9 +369,9 @@ const Dashboard: React.FC = () => {
|
|||
<span className="font-mono text-xs">
|
||||
{formatWorkTime(project.totalWorkTime)}
|
||||
</span>
|
||||
<span className="text-xs opacity-60">
|
||||
{/* <span className="text-xs opacity-60">
|
||||
of {project.dedicatedHours}
|
||||
</span>
|
||||
</span> */}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
|
|
@ -384,11 +384,11 @@ const Dashboard: React.FC = () => {
|
|||
>
|
||||
{isCurrentlySelected ? "Selected" : "Select"}
|
||||
</button>
|
||||
{!limitReached && (
|
||||
{/* {!limitReached && (
|
||||
<span className="text-xs text-success">
|
||||
{remainingTime} left
|
||||
</span>
|
||||
)}
|
||||
)} */}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
|||
|
|
@ -535,7 +535,7 @@ const LeaveAndAdjustments: React.FC = () => {
|
|||
|
||||
{/* Header */}
|
||||
<div className=" ">
|
||||
<h1 className="text-mb font-bold mb-2">Adjust Timesheet</h1>
|
||||
<h1 className="text-mb font-bold mb-2">Leave & Adjust Timesheet</h1>
|
||||
</div>
|
||||
|
||||
{/* General Error Alert */}
|
||||
|
|
@ -545,6 +545,9 @@ const LeaveAndAdjustments: React.FC = () => {
|
|||
</div>
|
||||
)}
|
||||
|
||||
|
||||
|
||||
|
||||
{/* Main Container */}
|
||||
<div className="rounded-lg bg-base-100 overflow-hidden">
|
||||
{/* Tabs Navigation */}
|
||||
|
|
|
|||
Loading…
Reference in New Issue