changes
This commit is contained in:
@@ -76,26 +76,44 @@ export class FusionClockFAB extends Component {
|
||||
async _fetchStatus() {
|
||||
try {
|
||||
const result = await rpc("/fusion_clock/get_status", {});
|
||||
if (result.error) {
|
||||
this.state.isDisplayed = false;
|
||||
return;
|
||||
}
|
||||
if (result.error) return;
|
||||
|
||||
this.state.isDisplayed = result.enable_clock !== false;
|
||||
this.state.isCheckedIn = result.is_checked_in;
|
||||
this.state.locationName = result.location_name || "";
|
||||
this.state.todayHours = (result.today_hours || 0).toFixed(1);
|
||||
this.state.weekHours = (result.week_hours || 0).toFixed(1);
|
||||
|
||||
if (result.is_checked_in && result.check_in) {
|
||||
this.state.checkInTime = new Date(result.check_in + "Z");
|
||||
this._startTimer();
|
||||
} else {
|
||||
const serverTime = new Date(result.check_in + "Z");
|
||||
const wasRunning = this.state.isCheckedIn;
|
||||
this.state.isCheckedIn = true;
|
||||
if (!wasRunning || Math.abs(serverTime - this.state.checkInTime) > 5000) {
|
||||
this.state.checkInTime = serverTime;
|
||||
this._startTimer();
|
||||
}
|
||||
try { localStorage.setItem("fclk_fab_check_in", serverTime.toISOString()); } catch {}
|
||||
} else if (!result.is_checked_in) {
|
||||
this.state.isCheckedIn = false;
|
||||
this.state.checkInTime = null;
|
||||
this._stopTimer();
|
||||
this.state.timerDisplay = "00:00:00";
|
||||
try { localStorage.removeItem("fclk_fab_check_in"); } catch {}
|
||||
}
|
||||
} catch {
|
||||
if (!this.state.isCheckedIn) {
|
||||
try {
|
||||
const saved = localStorage.getItem("fclk_fab_check_in");
|
||||
if (saved) {
|
||||
const t = new Date(saved);
|
||||
if (!isNaN(t.getTime()) && (Date.now() - t.getTime()) < 24 * 60 * 60 * 1000) {
|
||||
this.state.isDisplayed = true;
|
||||
this.state.isCheckedIn = true;
|
||||
this.state.checkInTime = t;
|
||||
this._startTimer();
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
} catch (e) {
|
||||
this.state.isDisplayed = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user