mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 13:36:48 +00:00
ba70ad28b8
Arabic runs the app right to left, but margins, paddings, insets, text alignment, borders and corner radii were written for the left side, so icons sat against the wrong edge of their labels, indents and badges pointed the wrong way and amount columns aligned left. They now use the logical forms (ms-, ps-, start-, text-start, marginInlineStart, insetInlineEnd and their CSS equivalents), which are the very same sides in a left to right language. Geometry stays physical on purpose: maps, positions measured from the pointer or a bounding box, time axes, sliders, transforms and print output. Amounts drawn as several spans keep their order in a right to left row, the time picker keeps hours before minutes, and two switches whose thumb slid out of its track in Arabic now move the right way. lint:rtl counts what is still physical per file against a baseline that may only shrink (1512 uses in 370 files before, 319 in 113 now), and CI runs it, so new code reaches for the logical forms.
97 lines
4.4 KiB
TypeScript
97 lines
4.4 KiB
TypeScript
import { useState } from 'react'
|
|
import { Plus, X, MapPin } from 'lucide-react'
|
|
import { useTranslation } from '../../i18n'
|
|
import type { Place, AssignmentsMap } from '../../types'
|
|
import { placeMatchesSearch } from '../../utils/placeSearch'
|
|
|
|
export function MobileAddPlaceButton({ dayId, places, assignments, onAssign, onAddNew }: {
|
|
dayId: number
|
|
places: Place[]
|
|
assignments: AssignmentsMap
|
|
onAssign?: (placeId: number, dayId: number) => void
|
|
onAddNew?: () => void
|
|
}) {
|
|
const { t } = useTranslation()
|
|
const [open, setOpen] = useState(false)
|
|
const [search, setSearch] = useState('')
|
|
|
|
// Find places not assigned to this day
|
|
const assignedToDay = new Set((assignments[String(dayId)] || []).map(a => a.place_id))
|
|
const available = places.filter(p => !assignedToDay.has(p.id))
|
|
const filtered = available.filter(p => placeMatchesSearch(p, search))
|
|
|
|
return (
|
|
<div className="md:hidden" style={{ padding: '8px 12px 12px' }}>
|
|
{!open ? (
|
|
<button type="button"
|
|
onClick={e => { e.stopPropagation(); setOpen(true) }}
|
|
style={{
|
|
width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6,
|
|
padding: '10px 0', borderRadius: 12,
|
|
border: '1.5px dashed var(--border-primary)',
|
|
background: 'transparent', color: 'var(--text-muted)',
|
|
fontSize: 'calc(12px * var(--fs-scale-body, 1))', fontWeight: 600, fontFamily: 'inherit', cursor: 'pointer',
|
|
}}
|
|
>
|
|
<Plus size={14} />
|
|
Add Place
|
|
</button>
|
|
) : (
|
|
<div style={{ borderRadius: 14, border: '1px solid var(--border-primary)', background: 'var(--bg-card)', overflow: 'hidden' }}>
|
|
<div style={{ padding: '8px 10px', borderBottom: '1px solid var(--border-faint)', display: 'flex', gap: 6 }}>
|
|
<input
|
|
autoFocus
|
|
value={search}
|
|
onChange={e => setSearch(e.target.value)}
|
|
placeholder={t('dayplan.mobile.searchPlaces')}
|
|
style={{ flex: 1, border: 'none', outline: 'none', background: 'transparent', fontSize: 'calc(13px * var(--fs-scale-body, 1))', fontFamily: 'inherit', color: 'var(--text-primary)' }}
|
|
/>
|
|
<button type="button" onClick={() => { setOpen(false); setSearch('') }} style={{ background: 'none', border: 'none', cursor: 'pointer', padding: 2, color: 'var(--text-faint)' }}>
|
|
<X size={14} />
|
|
</button>
|
|
</div>
|
|
<div style={{ maxHeight: 200, overflowY: 'auto' }}>
|
|
{filtered.length === 0 && (
|
|
<div style={{ padding: '16px 12px', textAlign: 'center', fontSize: 'calc(12px * var(--fs-scale-body, 1))', color: 'var(--text-faint)' }}>
|
|
{available.length === 0 ? t('dayplan.mobile.allAssigned') : t('dayplan.mobile.noMatch')}
|
|
</div>
|
|
)}
|
|
{filtered.slice(0, 20).map(p => (
|
|
<button type="button"
|
|
key={p.id}
|
|
onClick={() => {
|
|
onAssign?.(p.id, dayId)
|
|
setOpen(false)
|
|
setSearch('')
|
|
}}
|
|
style={{
|
|
width: '100%', display: 'flex', alignItems: 'center', gap: 8,
|
|
padding: '10px 12px', border: 'none', background: 'transparent',
|
|
cursor: 'pointer', fontFamily: 'inherit', textAlign: 'start',
|
|
}}
|
|
>
|
|
<MapPin size={13} style={{ color: 'var(--text-faint)', flexShrink: 0 }} />
|
|
<span style={{ fontSize: 'calc(13px * var(--fs-scale-body, 1))', fontWeight: 500, color: 'var(--text-primary)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{p.name}</span>
|
|
</button>
|
|
))}
|
|
</div>
|
|
{onAddNew && (
|
|
<button type="button"
|
|
onClick={() => { onAddNew(); setOpen(false); setSearch('') }}
|
|
style={{
|
|
width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6,
|
|
padding: '10px 0', borderTop: '1px solid var(--border-faint)',
|
|
background: 'transparent', border: 'none', color: 'var(--text-muted)',
|
|
fontSize: 'calc(12px * var(--fs-scale-body, 1))', fontWeight: 600, fontFamily: 'inherit', cursor: 'pointer',
|
|
}}
|
|
>
|
|
<Plus size={13} />
|
|
Create new place
|
|
</button>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|