show timming in hh:mm:ss

This commit is contained in:
JaiPandey425 2025-11-20 12:27:43 +05:30
parent 2212359c96
commit 45a3040614
3 changed files with 36 additions and 31 deletions

View File

@ -116,22 +116,22 @@ const DashboardLayout = () => {
const [loadingStop, setLoadingStop] = useState(false); 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); const stopTrackingRef = useRef<(() => Promise<void>) | null>(null);
// ✅ Define handleStopTracking FIRST // Define handleStopTracking FIRST
const handleStopTracking = useCallback(async () => { const handleStopTracking = useCallback(async () => {
if (loadingStop || loadingStart) return; if (loadingStop || loadingStart) return;
if (!selectedProject) { if (!selectedProject) {
console.warn("⚠️ No selected project to stop"); console.warn("No selected project to stop");
return; return;
} }
const projectId = selectedProject.projectId; const projectId = selectedProject.projectId;
console.log("🛑 Stop tracking initiated for:", selectedProject.projectName); console.log(" Stop tracking initiated for:", selectedProject.projectName);
console.log("📊 Current elapsed time:", elapsedTime); console.log(" Current elapsed time:", elapsedTime);
setLoadingStop(true); setLoadingStop(true);
@ -139,11 +139,11 @@ const DashboardLayout = () => {
// This ensures the last window activity is recorded before logout // This ensures the last window activity is recorded before logout
if (stopTrackingRef.current) { if (stopTrackingRef.current) {
try { try {
console.log("📤 Sending final PATCH to record last activity..."); console.log(" Sending final PATCH to record last activity...");
await stopTrackingRef.current(); await stopTrackingRef.current();
console.log("✅ Final tracking data sent successfully"); console.log(" Final tracking data sent successfully");
} catch (error) { } 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 // Continue with stop even if PATCH fails
} }
} else { } else {
@ -169,9 +169,9 @@ const DashboardLayout = () => {
console.log("📡 Sending LOGOUT request:", payload); console.log("📡 Sending LOGOUT request:", payload);
const res = await window.electron.stopProjectTracking(payload); const res = await window.electron.stopProjectTracking(payload);
console.log("✅ LOGOUT successful:", res); console.log(" LOGOUT successful:", res);
} catch (error) { } catch (error) {
console.error("❌ Failed to send LOGOUT:", error); console.error(" Failed to send LOGOUT:", error);
} }
// STEP 4: Update UI (window restore) // STEP 4: Update UI (window restore)
@ -179,9 +179,9 @@ const DashboardLayout = () => {
await window.electron.toggleCloseBtn(true); await window.electron.toggleCloseBtn(true);
await window.electron.resizeWindow(500, 600); await window.electron.resizeWindow(500, 600);
toggleWindowSize.current = true; toggleWindowSize.current = true;
console.log("✅ Window UI restored"); console.log(" Window UI restored");
} catch (error) { } catch (error) {
console.error("❌ Error restoring window:", error); console.error(" Error restoring window:", error);
} }
// STEP 5: Update Redux tracking state → THIS TRIGGERS UI UPDATE // STEP 5: Update Redux tracking state → THIS TRIGGERS UI UPDATE
@ -194,7 +194,7 @@ const DashboardLayout = () => {
// Allow React to process the state update // Allow React to process the state update
await new Promise(resolve => setTimeout(resolve, 50)); 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 // STEP 6: Clear active project log ID
setActiveProjectLogId(""); setActiveProjectLogId("");
@ -212,12 +212,12 @@ const DashboardLayout = () => {
console.log("=".repeat(50)); console.log("=".repeat(50));
}, [selectedProject, projectSummary, elapsedTime, dispatch]); }, [selectedProject, projectSummary, elapsedTime, dispatch]);
// ✅ NOW define handleLimitExceeded using the defined handleStopTracking // NOW define handleLimitExceeded using the defined handleStopTracking
const handleLimitExceeded = useCallback(async () => { const handleLimitExceeded = useCallback(async () => {
console.log("🚨 LIMIT EXCEEDED - Auto-stopping tracking"); console.log("🚨 LIMIT EXCEEDED - Auto-stopping tracking");
if (!selectedProject) { if (!selectedProject) {
console.error("❌ No selected project for limit exceeded"); console.error(" No selected project for limit exceeded");
return; return;
} }
@ -233,7 +233,7 @@ const DashboardLayout = () => {
await handleStopTracking(); await handleStopTracking();
}, [selectedProject, handleStopTracking]); }, [selectedProject, handleStopTracking]);
// ✅ Initialize useActiveAppTracker and store finalizeTracking in ref // Initialize useActiveAppTracker and store finalizeTracking in ref
const { finalizeTracking } = useActiveAppTracker( const { finalizeTracking } = useActiveAppTracker(
isTracking, isTracking,
activeProjectLogId, activeProjectLogId,
@ -242,7 +242,7 @@ const DashboardLayout = () => {
handleLimitExceeded handleLimitExceeded
); );
// ✅ Update the ref whenever finalizeTracking changes // Update the ref whenever finalizeTracking changes
useEffect(() => { useEffect(() => {
stopTrackingRef.current = finalizeTracking; stopTrackingRef.current = finalizeTracking;
}, [finalizeTracking]); }, [finalizeTracking]);
@ -267,7 +267,7 @@ const DashboardLayout = () => {
await handleStopTracking(); // Wait until stop is completed await handleStopTracking(); // Wait until stop is completed
console.log("🛑 Tracking stopped successfully before logout"); console.log("🛑 Tracking stopped successfully before logout");
} catch (err) { } 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; if (loadingStart || loadingStop) return;
// ✅ Check limit before starting // Check limit before starting
const limitCheck = canStartTracking(project); const limitCheck = canStartTracking(project);
if (!limitCheck.canStart) { if (!limitCheck.canStart) {
alert( alert(
@ -346,7 +346,7 @@ const DashboardLayout = () => {
); );
setActiveProjectLogId(res?.data?.logId); 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 // ⬇️ Calculate time limit in seconds
const parseTimeToSeconds = (timeStr: string): number => { 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); const totalTimeWorked = alreadyWorkedSeconds + Math.floor((Date.now() - now) / 1000);
if (totalTimeWorked >= dedicatedSeconds) { if (totalTimeWorked >= dedicatedSeconds) {
@ -400,7 +400,7 @@ const DashboardLayout = () => {
}, 1000); }, 1000);
} catch (error) { } catch (error) {
console.error("❌ Failed to sync project start:", error); console.error(" Failed to sync project start:", error);
alert("Something went wrong!"); alert("Something went wrong!");
await window.electron.toggleCloseBtn(true); await window.electron.toggleCloseBtn(true);
} finally { } finally {
@ -457,7 +457,9 @@ const DashboardLayout = () => {
const formatTime = (seconds: number) => { const formatTime = (seconds: number) => {
const hrs = Math.floor(seconds / 3600); const hrs = Math.floor(seconds / 3600);
const mins = Math.floor((seconds % 3600) / 60); 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 ( return (

View File

@ -48,8 +48,8 @@ const formatTime = (seconds: number) => {
const hrs = Math.floor(seconds / 3600); const hrs = Math.floor(seconds / 3600);
const mins = Math.floor((seconds % 3600) / 60); const mins = Math.floor((seconds % 3600) / 60);
const secs = seconds % 60; const secs = seconds % 60;
// return `${hrs}h ${mins}m ${secs}s`; return `${hrs}h ${mins}m ${secs}s`;
return `${hrs}h ${mins}m `; // return `${hrs}h ${mins}m `;
}; };
// Widget Component // Widget Component
@ -369,9 +369,9 @@ const Dashboard: React.FC = () => {
<span className="font-mono text-xs"> <span className="font-mono text-xs">
{formatWorkTime(project.totalWorkTime)} {formatWorkTime(project.totalWorkTime)}
</span> </span>
<span className="text-xs opacity-60"> {/* <span className="text-xs opacity-60">
of {project.dedicatedHours} of {project.dedicatedHours}
</span> </span> */}
</div> </div>
</td> </td>
<td> <td>
@ -384,11 +384,11 @@ const Dashboard: React.FC = () => {
> >
{isCurrentlySelected ? "Selected" : "Select"} {isCurrentlySelected ? "Selected" : "Select"}
</button> </button>
{!limitReached && ( {/* {!limitReached && (
<span className="text-xs text-success"> <span className="text-xs text-success">
{remainingTime} left {remainingTime} left
</span> </span>
)} )} */}
</div> </div>
</td> </td>
</tr> </tr>

View File

@ -535,7 +535,7 @@ const LeaveAndAdjustments: React.FC = () => {
{/* Header */} {/* Header */}
<div className=" "> <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> </div>
{/* General Error Alert */} {/* General Error Alert */}
@ -545,6 +545,9 @@ const LeaveAndAdjustments: React.FC = () => {
</div> </div>
)} )}
{/* Main Container */} {/* Main Container */}
<div className="rounded-lg bg-base-100 overflow-hidden"> <div className="rounded-lg bg-base-100 overflow-hidden">
{/* Tabs Navigation */} {/* Tabs Navigation */}