Skip to content

Commit 9ecf42b

Browse files
CopilotMrAlders0n
andcommitted
Add countdown timer for API post delay
- Changed "Waiting for API post" to "Wait to post API" - Added countdown display from 7s to 0s during API post delay - Implemented startApiCountdown, stopApiCountdown, and updateApiCountdownStatus functions - Added state variables apiCountdownTimer and apiPostTime - Countdown updates every second similar to auto-ping countdown - Clean up API countdown timer on disconnect Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
1 parent 6a6e0ae commit 9ecf42b

1 file changed

Lines changed: 47 additions & 3 deletions

File tree

content/wardrive.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ const state = {
6262
cooldownEndTime: null, // Timestamp when cooldown period ends
6363
cooldownUpdateTimer: null, // Timer to re-enable controls after cooldown
6464
autoCountdownTimer: null, // Timer for auto-ping countdown display
65-
nextAutoPingTime: null // Timestamp when next auto-ping will occur
65+
nextAutoPingTime: null, // Timestamp when next auto-ping will occur
66+
apiCountdownTimer: null, // Timer for API post countdown display
67+
apiPostTime: null // Timestamp when API post will occur
6668
};
6769

6870
// ---- UI helpers ----
@@ -106,6 +108,42 @@ function stopAutoCountdown() {
106108
}
107109
state.nextAutoPingTime = null;
108110
}
111+
function updateApiCountdownStatus() {
112+
if (!state.apiPostTime) {
113+
return;
114+
}
115+
116+
const remainingMs = state.apiPostTime - Date.now();
117+
if (remainingMs <= 0) {
118+
setStatus("Posting to API...", "text-sky-300");
119+
return;
120+
}
121+
122+
const remainingSec = Math.ceil(remainingMs / 1000);
123+
setStatus(`Wait to post API (${remainingSec}s)`, "text-sky-300");
124+
}
125+
function startApiCountdown(delayMs) {
126+
// Stop any existing countdown
127+
stopApiCountdown();
128+
129+
// Set the API post time
130+
state.apiPostTime = Date.now() + delayMs;
131+
132+
// Update immediately
133+
updateApiCountdownStatus();
134+
135+
// Update every second
136+
state.apiCountdownTimer = setInterval(() => {
137+
updateApiCountdownStatus();
138+
}, 1000);
139+
}
140+
function stopApiCountdown() {
141+
if (state.apiCountdownTimer) {
142+
clearInterval(state.apiCountdownTimer);
143+
state.apiCountdownTimer = null;
144+
}
145+
state.apiPostTime = null;
146+
}
109147
function isInCooldown() {
110148
return state.cooldownEndTime && Date.now() < state.cooldownEndTime;
111149
}
@@ -526,12 +564,13 @@ async function sendPing(manual = false) {
526564
startCooldown();
527565

528566
// Update status after ping is sent
529-
// Brief delay to show "Ping sent" status before moving to "Waiting for API post"
567+
// Brief delay to show "Ping sent" status before moving to countdown
530568
setStatus(manual ? "Ping sent" : "Auto ping sent", "text-emerald-300");
531569

532570
setTimeout(() => {
533571
if (state.connection) {
534-
setStatus("Waiting for API post", "text-sky-300");
572+
// Start countdown for API post
573+
startApiCountdown(MESHMAPPER_DELAY_MS);
535574
}
536575
}, STATUS_UPDATE_DELAY_MS);
537576

@@ -545,6 +584,10 @@ async function sendPing(manual = false) {
545584
// Capture accuracy in closure to ensure it's available in nested callback
546585
const capturedAccuracy = accuracy;
547586

587+
// Stop the API countdown since we're posting now
588+
stopApiCountdown();
589+
setStatus("Posting to API...", "text-sky-300");
590+
548591
try {
549592
await postToMeshMapperAPI(lat, lon);
550593
} catch (error) {
@@ -718,6 +761,7 @@ async function connect() {
718761
state.cooldownUpdateTimer = null;
719762
}
720763
stopAutoCountdown();
764+
stopApiCountdown();
721765
state.cooldownEndTime = null;
722766

723767
state.lastFix = null;

0 commit comments

Comments
 (0)