mirror of
https://github.com/ever-co/ever-gauzy.git
synced 2026-10-02 01:54:50 +08:00
refactor: time tracker component to combine conditions for retrieving remote log and handle API request
This commit is contained in:
@@ -488,19 +488,29 @@ export class TimeTrackerComponent implements OnInit, AfterViewInit {
|
||||
} else {
|
||||
if (!this._isOffline) {
|
||||
try {
|
||||
timelog =
|
||||
// Combine all conditions into a single descriptive boolean
|
||||
const isRetrieveRemoteLog =
|
||||
!isRemoteTimerRunning ||
|
||||
isRemote ||
|
||||
this._remoteSleepLock ||
|
||||
(this.isRemoteTimer && (this._isSpecialLogout || this.quitApp))
|
||||
? this._timeTrackerStatus.remoteTimer.lastLog
|
||||
: await this.preventDuplicateApiRequest(
|
||||
{
|
||||
...params,
|
||||
...lastTimer
|
||||
},
|
||||
(payload) => this.timeTrackerService.toggleApiStop(payload)
|
||||
);
|
||||
(this.isRemoteTimer && (this._isSpecialLogout || this.quitApp));
|
||||
|
||||
if (isRetrieveRemoteLog) {
|
||||
// Retrieve remote timer log
|
||||
timelog = this._timeTrackerStatus.remoteTimer.lastLog;
|
||||
} else {
|
||||
// Create request parameters only when necessary
|
||||
const requestParams = {
|
||||
...params,
|
||||
...lastTimer
|
||||
};
|
||||
// Execute API request to stop timer and store the result in timelog
|
||||
timelog = await this.preventDuplicateApiRequest(requestParams, (payload) =>
|
||||
this.timeTrackerService.toggleApiStop(payload)
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
// Handle any error during the process
|
||||
lastTimer.isStoppedOffline = true;
|
||||
await this.electronService.ipcRenderer.invoke('MARK_AS_STOPPED_OFFLINE');
|
||||
this._loggerService.error(error);
|
||||
|
||||
Reference in New Issue
Block a user