mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
3c040fab11
* fix(share): serve place thumbnails in shared trip links (#1100) Google-sourced place photos are stored as image_url pointing at the JWT-guarded /api/maps/place-photo/:placeId/bytes endpoint, so they 401 for an unauthenticated shared-trip viewer and render as broken images. Rewrite place image_url values in the shared payload to a public, token-scoped proxy (/api/shared/:token/place-photo/:placeId/bytes) and add an unguarded SharedController route that validates the token and that the place belongs to its trip before streaming the cached bytes. Mirrors the existing JourneyPublicController precedent. No client changes needed. * fix(atlas): replace Natural Earth with geoBoundaries for up-to-date regions (#1119) Atlas sourced country and sub-national boundaries from Natural Earth's GitHub `master` at runtime. That data is stale (e.g. it still shows Norway's pre-2020 counties such as Oppland/Hordaland) and depicts some contested territory in unwanted ways (nvkelso/natural-earth-vector#391), so Natural Earth is dropped entirely. - Country borders (admin0) now come from the geoBoundaries CGAZ composite; sub-national regions (admin1) from per-country gbOpen, which carries ISO 3166-2 codes. A new script (server/scripts/build-atlas-geo.mjs) normalizes and quantizes them into committed gzipped bundles under server/assets/atlas, read server-side at runtime (no network at boot, no GitHub CSP allowlist entry). - New GET /addons/atlas/countries/geo serves the country layer; the client fetches it from the API instead of GitHub. - A migration reconciles manually-marked visited_regions against the new bundle (valid code -> keep; region name still matches -> re-code; curated merge crosswalk for renamed reforms; else leave intact), with UNIQUE-safe dedup. bucket_list and visited_countries hold only invariant alpha-2 country codes, so they are untouched. - Attribution added (NOTICE.md + README) per geoBoundaries CC BY 4.0. Closes #1119 * fix(packing): make templates admin-only to create, usable by members Creating a packing-list template was gated only by trip access, so any trip member could create one from the Lists feature, while applying a template silently failed for non-admins because the apply dropdown was populated from the AdminGuard-protected /api/admin/packing-templates endpoint. - save-as-template now returns 403 for non-admins; the Save-as-Template button is hidden unless the user is an admin (both the TripPlanner toolbar and the inline packing header). - add member-accessible GET /api/trips/:tripId/packing/templates so the apply dropdown lists templates for any trip member; client fetches from it instead of the admin endpoint. Closes #1120 Closes #1121 * fix(packing): show bag tracking to non-admin members The global Bag Tracking toggle was only readable via the admin-gated GET /api/admin/bag-tracking, so non-admin trip members got 403 and the weight fields, bag circles, and BAGS sidebar never rendered (#1124). Surface the flag through the already-authenticated GET /api/addons (loaded into the client addon store on app start for every user); the packing hook reads it from the store instead of the admin endpoint. The admin write path stays admin-gated and unchanged.
220 lines
13 KiB
TypeScript
220 lines
13 KiB
TypeScript
import {
|
|
X, Check, CheckCheck, Luggage, Package, FolderPlus, Upload,
|
|
} from 'lucide-react'
|
|
import type { PackingState } from './usePackingListPanel'
|
|
|
|
export function PackingHeader(S: PackingState) {
|
|
const {
|
|
inlineHeader, t, items, abgehakt, fortschritt, canEdit, isAdmin,
|
|
showSaveTemplate, saveTemplateName, setSaveTemplateName, handleSaveAsTemplate, setShowSaveTemplate,
|
|
setShowImportModal, handleClearChecked, availableTemplates, templateDropdownRef,
|
|
showTemplateDropdown, setShowTemplateDropdown, applyingTemplate, handleApplyTemplate,
|
|
bagTrackingEnabled, showBagModal, setShowBagModal,
|
|
addingCategory, newCatName, setNewCatName, handleAddNewCategory, setAddingCategory,
|
|
} = S
|
|
return (
|
|
<div style={{ padding: inlineHeader ? '20px 24px 16px' : '0 0 16px', flexShrink: 0, borderBottom: inlineHeader ? '1px solid rgba(0,0,0,0.06)' : undefined }}>
|
|
<div style={{ display: 'flex', alignItems: inlineHeader ? 'flex-start' : 'center', justifyContent: 'space-between', gap: 14 }}>
|
|
{inlineHeader ? (
|
|
<div>
|
|
<h2 style={{ margin: 0, fontSize: 18, fontWeight: 700, color: 'var(--text-primary)' }}>{t('packing.title')}</h2>
|
|
{items.length > 0 && (
|
|
<p style={{ margin: '2px 0 0', fontSize: 12.5, color: 'var(--text-faint)' }}>
|
|
{t('packing.progress', { packed: abgehakt, total: items.length, percent: fortschritt })}
|
|
</p>
|
|
)}
|
|
</div>
|
|
) : <span />}
|
|
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', justifyContent: 'flex-end' }}>
|
|
{canEdit && isAdmin && items.length > 0 && showSaveTemplate && (
|
|
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
|
<input
|
|
type="text" autoFocus
|
|
value={saveTemplateName}
|
|
onChange={e => setSaveTemplateName(e.target.value)}
|
|
onKeyDown={e => { if (e.key === 'Enter') handleSaveAsTemplate(); if (e.key === 'Escape') { setShowSaveTemplate(false); setSaveTemplateName('') } }}
|
|
placeholder={t('packing.templateName')}
|
|
style={{ fontSize: 12, padding: '5px 10px', borderRadius: 99, border: '1px solid var(--border-primary)', outline: 'none', fontFamily: 'inherit', width: 140, background: 'var(--bg-card)', color: 'var(--text-primary)' }}
|
|
/>
|
|
<button onClick={handleSaveAsTemplate} style={{ background: 'none', border: 'none', cursor: 'pointer', padding: 2, color: '#10b981' }}><Check size={14} /></button>
|
|
<button onClick={() => { setShowSaveTemplate(false); setSaveTemplateName('') }} style={{ background: 'none', border: 'none', cursor: 'pointer', padding: 2, color: 'var(--text-faint)' }}><X size={14} /></button>
|
|
</div>
|
|
)}
|
|
{inlineHeader && canEdit && (
|
|
<button onClick={() => setShowImportModal(true)} style={{
|
|
display: 'flex', alignItems: 'center', gap: 5, padding: '5px 11px', borderRadius: 99,
|
|
border: '1px solid var(--border-primary)', fontSize: 12, fontWeight: 500, cursor: 'pointer',
|
|
fontFamily: 'inherit', background: 'var(--bg-card)', color: 'var(--text-muted)',
|
|
}}>
|
|
<Upload size={12} /> <span className="hidden sm:inline">{t('packing.import')}</span>
|
|
</button>
|
|
)}
|
|
{inlineHeader && canEdit && abgehakt > 0 && (
|
|
<button onClick={handleClearChecked} style={{
|
|
fontSize: 11.5, padding: '5px 10px', borderRadius: 99, border: '1px solid rgba(239,68,68,0.3)',
|
|
background: 'rgba(239,68,68,0.1)', color: '#ef4444', cursor: 'pointer', fontFamily: 'inherit',
|
|
}}>
|
|
<span className="hidden sm:inline">{t('packing.clearChecked', { count: abgehakt })}</span>
|
|
<span className="sm:hidden">{t('packing.clearCheckedShort', { count: abgehakt })}</span>
|
|
</button>
|
|
)}
|
|
{inlineHeader && canEdit && availableTemplates.length > 0 && (
|
|
<div ref={templateDropdownRef} style={{ position: 'relative' }}>
|
|
<button onClick={() => setShowTemplateDropdown(v => !v)} disabled={applyingTemplate} style={{
|
|
display: 'flex', alignItems: 'center', gap: 5, padding: '5px 11px', borderRadius: 99,
|
|
border: '1px solid', fontSize: 12, fontWeight: 500, cursor: 'pointer', fontFamily: 'inherit',
|
|
background: showTemplateDropdown ? 'var(--text-primary)' : 'var(--bg-card)',
|
|
borderColor: showTemplateDropdown ? 'var(--text-primary)' : 'var(--border-primary)',
|
|
color: showTemplateDropdown ? 'var(--bg-primary)' : 'var(--text-muted)',
|
|
}}>
|
|
<Package size={12} /> <span className="hidden sm:inline">{t('packing.applyTemplate')}</span><span className="sm:hidden">{t('packing.template')}</span>
|
|
</button>
|
|
{showTemplateDropdown && (
|
|
<div style={{
|
|
position: 'absolute', right: 0, top: '100%', marginTop: 6, zIndex: 50,
|
|
background: 'var(--bg-card)', border: '1px solid var(--border-primary)', borderRadius: 10,
|
|
boxShadow: '0 4px 16px rgba(0,0,0,0.12)', padding: 4, minWidth: 200,
|
|
}}>
|
|
{availableTemplates.map(tmpl => (
|
|
<button key={tmpl.id} onClick={() => handleApplyTemplate(tmpl.id)}
|
|
style={{
|
|
display: 'flex', alignItems: 'center', gap: 8, width: '100%',
|
|
padding: '8px 12px', borderRadius: 8, border: 'none', cursor: 'pointer',
|
|
background: 'transparent', fontFamily: 'inherit', fontSize: 12, color: 'var(--text-primary)',
|
|
transition: 'background 0.1s',
|
|
}}
|
|
onMouseEnter={e => e.currentTarget.style.background = 'var(--bg-tertiary)'}
|
|
onMouseLeave={e => e.currentTarget.style.background = 'transparent'}
|
|
>
|
|
<Package size={13} className="text-content-faint" />
|
|
<div style={{ flex: 1, textAlign: 'left' }}>
|
|
<div style={{ fontWeight: 600 }}>{tmpl.name}</div>
|
|
<div style={{ fontSize: 10, color: 'var(--text-faint)' }}>{tmpl.item_count} {t('admin.packingTemplates.items')}</div>
|
|
</div>
|
|
</button>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
{inlineHeader && canEdit && isAdmin && items.length > 0 && !showSaveTemplate && (
|
|
<button onClick={() => setShowSaveTemplate(true)} style={{
|
|
display: 'flex', alignItems: 'center', gap: 5, padding: '5px 11px', borderRadius: 99,
|
|
border: '1px solid var(--border-primary)', fontSize: 12, fontWeight: 500, cursor: 'pointer', fontFamily: 'inherit',
|
|
background: 'var(--bg-card)', color: 'var(--text-muted)',
|
|
}}>
|
|
<FolderPlus size={12} /> <span className="hidden sm:inline">{t('packing.saveAsTemplate')}</span>
|
|
</button>
|
|
)}
|
|
{bagTrackingEnabled && (
|
|
<button onClick={() => setShowBagModal(true)} className="xl:!hidden"
|
|
style={{
|
|
display: 'flex', alignItems: 'center', gap: 5, padding: '5px 11px', borderRadius: 99,
|
|
border: '1px solid', fontSize: 12, fontWeight: 500, cursor: 'pointer', fontFamily: 'inherit',
|
|
background: showBagModal ? 'var(--text-primary)' : 'var(--bg-card)',
|
|
borderColor: showBagModal ? 'var(--text-primary)' : 'var(--border-primary)',
|
|
color: showBagModal ? 'var(--bg-primary)' : 'var(--text-muted)',
|
|
}}>
|
|
<Luggage size={12} /> {t('packing.bags')}
|
|
</button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{items.length > 0 && (
|
|
<div className="hidden sm:block" style={{ marginTop: 14, marginBottom: 14 }}>
|
|
<div className="flex items-center" style={{ gap: 14 }}>
|
|
{fortschritt === 100 ? (
|
|
<div style={{
|
|
display: 'flex', alignItems: 'center', gap: 8,
|
|
fontSize: 16, fontWeight: 700, color: '#10b981',
|
|
letterSpacing: '-0.01em', flexShrink: 0,
|
|
}}>
|
|
<CheckCheck size={18} strokeWidth={2.5} />
|
|
<span>{t('packing.allPacked')}</span>
|
|
</div>
|
|
) : (
|
|
<div style={{ display: 'flex', alignItems: 'baseline', gap: 8, flexShrink: 0 }}>
|
|
<div style={{ display: 'flex', alignItems: 'baseline' }}>
|
|
<span style={{
|
|
fontSize: 22, fontWeight: 700, color: 'var(--text-primary)',
|
|
fontVariantNumeric: 'tabular-nums', letterSpacing: '-0.02em',
|
|
lineHeight: 1,
|
|
}}>{abgehakt}</span>
|
|
<span style={{
|
|
fontSize: 14, fontWeight: 500, color: 'var(--text-faint)',
|
|
fontVariantNumeric: 'tabular-nums', lineHeight: 1, marginLeft: 1,
|
|
}}>/{items.length}</span>
|
|
</div>
|
|
<span style={{
|
|
fontSize: 11, fontWeight: 600, padding: '2px 7px',
|
|
borderRadius: 99, background: 'var(--bg-tertiary)',
|
|
color: 'var(--text-muted)',
|
|
fontVariantNumeric: 'tabular-nums',
|
|
lineHeight: 1.4,
|
|
}}>{fortschritt}%</span>
|
|
</div>
|
|
)}
|
|
|
|
<div style={{
|
|
flex: 1,
|
|
height: 8,
|
|
background: 'var(--bg-tertiary)',
|
|
borderRadius: 99,
|
|
overflow: 'hidden',
|
|
position: 'relative',
|
|
width: '100%',
|
|
}}>
|
|
<div style={{
|
|
height: '100%',
|
|
borderRadius: 99,
|
|
transition: 'width 600ms cubic-bezier(0.23, 1, 0.32, 1), background 400ms ease, box-shadow 400ms ease',
|
|
background: fortschritt === 100
|
|
? 'linear-gradient(90deg, #10b981 0%, #34d399 100%)'
|
|
: 'var(--accent)',
|
|
width: `${fortschritt}%`,
|
|
boxShadow: fortschritt === 100 ? '0 0 14px rgba(16,185,129,0.45)' : 'none',
|
|
position: 'relative',
|
|
}}>
|
|
<div style={{
|
|
position: 'absolute', inset: 0,
|
|
background: 'linear-gradient(180deg, rgba(255,255,255,0.22) 0%, rgba(255,255,255,0) 55%)',
|
|
borderRadius: 99,
|
|
pointerEvents: 'none',
|
|
}} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{canEdit && (addingCategory ? (
|
|
<div style={{ display: 'flex', gap: 6 }}>
|
|
<input
|
|
autoFocus
|
|
type="text" value={newCatName} onChange={e => setNewCatName(e.target.value)}
|
|
onKeyDown={e => { if (e.key === 'Enter') handleAddNewCategory(); if (e.key === 'Escape') { setAddingCategory(false); setNewCatName('') } }}
|
|
placeholder={t('packing.newCategoryPlaceholder')}
|
|
style={{ flex: 1, padding: '8px 12px', borderRadius: 10, border: '1px solid var(--border-primary)', fontSize: 13.5, fontFamily: 'inherit', outline: 'none', color: 'var(--text-primary)' }}
|
|
/>
|
|
<button onClick={handleAddNewCategory} disabled={!newCatName.trim()}
|
|
style={{ padding: '8px 12px', borderRadius: 10, border: 'none', background: newCatName.trim() ? 'var(--text-primary)' : 'var(--border-primary)', color: 'var(--bg-primary)', cursor: newCatName.trim() ? 'pointer' : 'default', display: 'flex', alignItems: 'center' }}>
|
|
<Check size={16} />
|
|
</button>
|
|
<button onClick={() => { setAddingCategory(false); setNewCatName('') }}
|
|
style={{ padding: '8px 12px', borderRadius: 10, border: '1px solid var(--border-primary)', background: 'none', cursor: 'pointer', display: 'flex', alignItems: 'center', color: 'var(--text-faint)' }}>
|
|
<X size={16} />
|
|
</button>
|
|
</div>
|
|
) : (
|
|
<button onClick={() => setAddingCategory(true)}
|
|
style={{ display: 'flex', alignItems: 'center', gap: 6, width: '100%', padding: '9px 14px', borderRadius: 10, border: '1px dashed var(--border-primary)', background: 'none', cursor: 'pointer', fontSize: 13, color: 'var(--text-faint)', fontFamily: 'inherit', transition: 'all 0.15s' }}
|
|
onMouseEnter={e => { e.currentTarget.style.borderColor = 'var(--text-muted)'; e.currentTarget.style.color = 'var(--text-secondary)' }}
|
|
onMouseLeave={e => { e.currentTarget.style.borderColor = 'var(--border-primary)'; e.currentTarget.style.color = 'var(--text-faint)' }}>
|
|
<FolderPlus size={14} /> {t('packing.addCategory')}
|
|
</button>
|
|
))}
|
|
</div>
|
|
)
|
|
}
|