From 8eb101c5f13c0e5db3ea6c3f61bd6e7610e1439a Mon Sep 17 00:00:00 2001 From: Bkk1234 Date: Sat, 24 Oct 2026 00:09:04 +0700 Subject: [PATCH] Promote 'near me' to the third search tab, gated on secure context Searching now has three peer modes on /stops: by stop code, by place name, and by device location. - StopsView: third tab (data-mode=near) plus its own panel holding the location button, hint and result area; the button no longer sits in the toolbar with Search/Reset/Back - stops.search.ts: setMode handles the near mode, disables the other panels, hides the full stop list while the ranked results are shown, and skips filtering in that mode - stops.nearme.ts: applies the security gate - the tab is revealed only when window.isSecureContext && navigator.geolocation exist, otherwise it is hidden and any active near mode falls back to stop-code search - i18n: stops.modeNear / nearCta / nearHint (th + en, both copies) Distance is computed from each stop's own coordinates (busstop_list.json) against the device position, sorted nearest first. Verified: secure context shows all three tabs and returns a ranked map; a forced insecure context hides the tab and refuses the mode. --- frontend/public/locales/en.json | 5 ++- frontend/public/locales/th.json | 5 ++- frontend/src/components/views/StopsView.tsx | 19 ++++++++--- frontend/src/data/locales/en.json | 5 ++- frontend/src/data/locales/th.json | 5 ++- frontend/src/lib/ui/stops.nearme.ts | 29 +++++++++++++++++ frontend/src/lib/ui/stops.search.ts | 35 ++++++++++++++++----- frontend/tsconfig.tsbuildinfo | 2 +- 8 files changed, 89 insertions(+), 16 deletions(-) diff --git a/frontend/public/locales/en.json b/frontend/public/locales/en.json index 6b31ac8..60893e8 100644 --- a/frontend/public/locales/en.json +++ b/frontend/public/locales/en.json @@ -131,7 +131,10 @@ "stops.noOffset": "No travel time from the first stop yet", "stops.noBusLine": "No bus line listed", "stops.modeCode": "Search by stop code", - "stops.modePlace": "Search by place name", + "stops.modeNear": "Near me", + "stops.nearCta": "Use my location", + "stops.nearHint": "We ask your device for a location, then rank stops by real distance from their coordinates.", +"stops.modePlace": "Search by place name", "stops.codePh": "3+000", "stops.codeHint": "Type 4 digits and the + sign is added automatically (e.g. 3000 → 3+000)", "stops.codeHintBox": "Type digits in the boxes — empty boxes are filled with 0 automatically. For 4-digit codes such as 8+591, enter 08+591", diff --git a/frontend/public/locales/th.json b/frontend/public/locales/th.json index c3170d7..70f825d 100644 --- a/frontend/public/locales/th.json +++ b/frontend/public/locales/th.json @@ -131,7 +131,10 @@ "stops.noOffset": "ยังไม่ระบุเวลาเดินทางจากจุดแรก", "stops.noBusLine": "ยังไม่ระบุสายรถ", "stops.modeCode": "ค้นหาด้วยรหัสป้าย", - "stops.modePlace": "ค้นหาด้วยชื่อสถานที่", + "stops.modeNear": "ป้ายใกล้ฉัน", + "stops.nearCta": "ขอพิกัดและหาป้ายใกล้ฉัน", + "stops.nearHint": "ระบบจะขอตำแหน่งจากเครื่อง แล้วคำนวณระยะจากพิกัดป้าย/ศาลารถ เรียงจากใกล้ไปไกล", +"stops.modePlace": "ค้นหาด้วยชื่อสถานที่", "stops.codePh": "3+000", "stops.codeHint": "พิมพ์ตัวเลข 4 หลัก ระบบจะเติมเครื่องหมาย + ให้อัตโนมัติ (เช่น 3000 → 3+000)", "stops.codeHintBox": "พิมพ์ตัวเลขในช่อง ระบบจะเติม 0 ให้อัตโนมัติเมื่อเว้นว่าง และถ้าเจอรหัส 4 หลัก เช่น 8+591 ให้กรอก 08+591", diff --git a/frontend/src/components/views/StopsView.tsx b/frontend/src/components/views/StopsView.tsx index 73b1935..16c9f91 100644 --- a/frontend/src/components/views/StopsView.tsx +++ b/frontend/src/components/views/StopsView.tsx @@ -30,6 +30,11 @@ export default function StopsView() { ค้นหาด้วยชื่อสถานที่ + {/* หมวดที่ 3: หาป้ายจากพิกัดผู้ใช้ — ซ่อนอัตโนมัติเมื่อไม่ได้ HTTPS (ดู stops.nearme.ts) */} + {/* โหมด 1: รหัสป้าย (5 ช่อง: 2 หน้า + 3 หลัง) */}
@@ -53,13 +58,19 @@ export default function StopsView() { + {/* หมวดที่ 3: ป้ายใกล้ฉัน — ขอพิกัดจากมือถือ แล้วเรียงป้ายตามระยะจริง */} +
- ย้อนกลับ