Skip to content

Commit 6328627

Browse files
CopilotMrAlders0n
andcommitted
Address code review: Extract magic numbers to named constants
Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
1 parent 3374e4f commit 6328627

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

content/wardrive.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const GPS_FRESHNESS_BUFFER_MS = 5000; // Buffer time for GPS freshness
1515
const GPS_ACCURACY_THRESHOLD_M = 100; // Maximum acceptable GPS accuracy in meters
1616
const MESHMAPPER_DELAY_MS = 7000; // Delay MeshMapper API call by 7 seconds
1717
const COOLDOWN_MS = 7000; // Cooldown period for manual ping and auto toggle
18+
const STATUS_UPDATE_DELAY_MS = 100; // Brief delay to ensure "Ping sent" status is visible
19+
const MAP_REFRESH_DELAY_MS = 1000; // Delay after API post to ensure backend updated
1820
const WARDROVE_KEY = new Uint8Array([
1921
0x40, 0x76, 0xC3, 0x15, 0xC1, 0xEF, 0x38, 0x5F,
2022
0xA9, 0x3F, 0x06, 0x60, 0x27, 0x32, 0x0F, 0xE5
@@ -464,7 +466,6 @@ async function sendPing(manual = false) {
464466
// Start cooldown period after successful ping
465467
startCooldown();
466468

467-
const nowStr = new Date().toLocaleString();
468469
setStatus(manual ? "Ping sent" : "Auto ping sent", "text-emerald-300");
469470

470471
// Schedule MeshMapper API call with 7-second delay (non-blocking)
@@ -478,12 +479,12 @@ async function sendPing(manual = false) {
478479
if (state.connection) {
479480
setStatus("Waiting to post to API", "text-sky-300");
480481
}
481-
}, 100); // Small delay to ensure "Ping sent" is visible first
482+
}, STATUS_UPDATE_DELAY_MS);
482483

483484
state.meshMapperTimer = setTimeout(async () => {
484485
await postToMeshMapperAPI(lat, lon);
485486

486-
// Update map 1 second after API post to ensure backend updated
487+
// Update map after API post to ensure backend updated
487488
setTimeout(() => {
488489
if (accuracy && accuracy < GPS_ACCURACY_THRESHOLD_M) {
489490
scheduleCoverageRefresh(lat, lon);
@@ -493,10 +494,12 @@ async function sendPing(manual = false) {
493494
if (state.connection) {
494495
setStatus("Idle", "text-slate-300");
495496
}
496-
}, 1000);
497+
}, MAP_REFRESH_DELAY_MS);
497498

498499
state.meshMapperTimer = null;
499500
}, MESHMAPPER_DELAY_MS);
501+
502+
const nowStr = new Date().toLocaleString();
500503
if (lastPingEl) lastPingEl.textContent = `${nowStr}${payload}`;
501504

502505
// Session log

0 commit comments

Comments
 (0)