Skip to content

Commit

Permalink
fix(map): improve controls on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Dec 11, 2024
1 parent 02f1a79 commit ff64d26
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 72 deletions.
9 changes: 9 additions & 0 deletions src/map/HistoryControls.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.history-controls {
display: none;
}

@media screen and (min-width: 500px) {
.history-controls {
display: block;
}
}
106 changes: 56 additions & 50 deletions src/map/HistoryControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { formatInt } from '#utils/format.js'
import { HistoryIcon } from 'lucide-preact'
import { useState } from 'preact/hooks'

import './HistoryControls.css'

const byTimeSpan = (timeSpan: TimeSpan | undefined) => (t: TimeSpanInfo) =>
t.id === timeSpan

Expand All @@ -15,71 +17,75 @@ export const HistoryControls = () => {

if (!expanded) {
return (
<div
class="mt-2 d-flex justify-content-start align-items-center controls"
style={{ color: 'var(--color-nordic-dark-grey)' }}
>
<HistoryIcon class="ms-2" />
<button
type="button"
class="control"
onClick={() => {
setExpanded(true)
}}
<div class="history-controls">
<div
class="mt-2 d-flex justify-content-start align-items-center controls"
style={{ color: 'var(--color-nordic-dark-grey)' }}
>
{trail.length >= 500 && (
<span>last {formatInt(trail.length)} locations</span>
)}
{trail.length < 500 && (
<span>
History: {timeSpans.find(byTimeSpan(timeSpan))?.title ?? 'off'}
</span>
)}
</button>
<HistoryIcon class="ms-2" />
<button
type="button"
class="control"
onClick={() => {
setExpanded(true)
}}
>
{trail.length >= 500 && (
<span>last {formatInt(trail.length)} locations</span>
)}
{trail.length < 500 && (
<span>
History: {timeSpans.find(byTimeSpan(timeSpan))?.title ?? 'off'}
</span>
)}
</button>
</div>
</div>
)
}

return (
<div
class="mt-2 d-flex justify-content-start align-items-center controls horizontal"
style={{ color: 'var(--color-nordic-dark-grey)' }}
>
<HistoryIcon class="ms-2" title={'History'} />
<button
type="button"
class="control"
onClick={() => {
setTimeSpan(undefined)
setExpanded(false)
}}
<div class="history-controls">
<div
class="history-controls mt-2 d-flex justify-content-start align-items-center controls horizontal"
style={{ color: 'var(--color-nordic-dark-grey)' }}
>
off
</button>
{timeSpans.map(({ id, title }) => (
<HistoryIcon class="ms-2" title={'History'} />
<button
type="button"
class="control ms-1"
class="control"
onClick={() => {
setTimeSpan(id)
setTimeSpan(undefined)
setExpanded(false)
}}
>
{title}
off
</button>
))}
<div class="button control">
<label htmlFor="clusterLocations" class="d-flex align-items-center">
<input
type="checkbox"
id="clusterLocations"
checked={clustering}
onChange={(ev) => {
enableClustering((ev.target as HTMLInputElement).checked)
{timeSpans.map(({ id, title }) => (
<button
type="button"
class="control ms-1"
onClick={() => {
setTimeSpan(id)
setExpanded(false)
}}
/>{' '}
<span class="ms-2">cluster nearby locations </span>
</label>
>
{title}
</button>
))}
<div class="button control">
<label htmlFor="clusterLocations" class="d-flex align-items-center">
<input
type="checkbox"
id="clusterLocations"
checked={clustering}
onChange={(ev) => {
enableClustering((ev.target as HTMLInputElement).checked)
}}
/>{' '}
<span class="ms-2">cluster nearby locations </span>
</label>
</div>
</div>
</div>
)
Expand Down
10 changes: 10 additions & 0 deletions src/map/LocationSourceSelector.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
background-color: #959595;
color: #3d3a3a;
}

.location-source-selector.controls .label {
display: none;
}

@media screen and (min-width: 500px) {
.location-source-selector.controls .label {
display: inline;
}
}
21 changes: 5 additions & 16 deletions src/map/LocationSourceSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import {
LocationSourceLabels,
} from '#map/LocationSourceLabels.js'
import cx from 'classnames'
import {
BlendIcon,
EyeOffIcon,
HexagonIcon,
SatelliteIcon,
WifiIcon,
} from 'lucide-preact'
import { BlendIcon, HexagonIcon, SatelliteIcon, WifiIcon } from 'lucide-preact'

import './LocationSourceSelector.css'

Expand Down Expand Up @@ -45,15 +39,10 @@ export const LocationSourceSelector = () => {
disabled: !enabled,
})}
>
{enabled && (
<span>
{src === LocationSource.SCELL && <HexagonIcon />}
{src === LocationSource.MCELL && <BlendIcon />}
{src === LocationSource.WIFI && <WifiIcon />}
{src === LocationSource.GNSS && <SatelliteIcon />}
</span>
)}
{!enabled && <EyeOffIcon />}
{src === LocationSource.SCELL && <HexagonIcon />}
{src === LocationSource.MCELL && <BlendIcon />}
{src === LocationSource.WIFI && <WifiIcon />}
{src === LocationSource.GNSS && <SatelliteIcon />}
{LocationSourceLabels.has(src) && (
<span class="ms-2 label">{LocationSourceLabels.get(src)}</span>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/map/LockInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMapState } from '#context/MapState.js'
import { LockIcon } from 'lucide-preact'
import { UnlockIcon } from 'lucide-preact'

export const LockInfo = () => {
const mapState = useMapState()
Expand All @@ -14,7 +14,7 @@ export const LockInfo = () => {
mapState.unlock()
}}
>
<LockIcon />
<UnlockIcon />
</button>{' '}
to enable the map.
</span>
Expand Down
8 changes: 7 additions & 1 deletion src/map/Map.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#map {
width: 100%;
min-height: 50vh;
overflow: clip;
aspect-ratio: 3/4;
}

@media screen and (min-width: 500px) {
#map {
min-height: 50vh;
}
}

section.map {
Expand Down
6 changes: 3 additions & 3 deletions src/map/MapZoomControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const MapZoomControls = ({
setStyle(MapStyle.LIGHT)
}}
>
<MoonIcon />
<SunIcon />
</button>
) : (
<button
Expand All @@ -98,7 +98,7 @@ export const MapZoomControls = ({
setStyle(MapStyle.DARK)
}}
>
<SunIcon />
<MoonIcon />
</button>
)}
{(canBeLocked ?? true) && (
Expand All @@ -110,7 +110,7 @@ export const MapZoomControls = ({
toggleLock()
}}
>
{locked ? <LockIcon /> : <UnlockIcon />}
{locked ? <UnlockIcon /> : <LockIcon />}
</button>
)}
</>
Expand Down

0 comments on commit ff64d26

Please sign in to comment.