feat(web): add distance unit toggle between metric and imperial#173
Merged
Conversation
Add a settings option to switch between kilometers and miles for server distance display. The preference persists in localStorage and updates reactively across all components that show distance values. Closes #142
📝 WalkthroughWalkthroughAdds a distance unit settings feature (km/mi): a new settings panel component, a centralized distanceSettings utility with persistence and formatting, and updates server-related UI to use the configurable distance formatting. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant SettingsComp as DistanceSettings<br/>Component
participant Utils as distanceSettings<br/>Utilities
participant Storage as localStorage
participant Clients as ServerList / ServerCard
User->>SettingsComp: Select unit (km/mi)
SettingsComp->>Utils: saveDistanceSettings(newSettings)
Utils->>Storage: write DISTANCE_SETTINGS_KEY
Utils->>Clients: dispatch "distanceSettingsChanged"
Clients->>Utils: useDistanceSettings hook receives update
Clients->>Clients: Re-render using formatDistance(...)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@web/src/components/settings/DistanceSettings.tsx`:
- Around line 28-34: The UI currently shows a success toast unconditionally in
saveSettings; change saveDistanceSettings to return a success indicator (boolean
or resolved/rejected promise) and update saveSettings to await/check that
result: only call setHasChanges(false) and showToast("Distance settings saved",
"success", ...) when persistence succeeded, otherwise call showToast("Failed to
save distance settings", "error", { description: <error or helpful message> })
and keep hasChanges true; reference saveSettings, saveDistanceSettings,
setHasChanges, and showToast when making this change.
In `@web/src/utils/distanceSettings.ts`:
- Around line 45-50: The formatDistance function currently floors converted
miles which can display "0 mi" for nearby servers; update the conversion in
formatDistance to round to the nearest integer instead of using Math.floor for
the miles branch (use Math.round on distanceKm * KM_TO_MI) while leaving or
reconsidering the km branch as needed; reference the formatDistance function and
the KM_TO_MI constant and ensure the returned string still uses the " mi"
suffix.
Prevents displaying "0 mi" or "0 km" for short distances by rounding to the nearest integer instead of truncating.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
timeSettings.ts/TimeFormatSettings.tsxarchitecture patternCloses #142
Test plan
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.