feat: allow dismissing address suggestions
This commit is contained in:
parent
3ed7ec9825
commit
69b47a8d94
@ -207,6 +207,11 @@ export default function CalendarEventModal({
|
|||||||
const locationRequestRef = useRef(0);
|
const locationRequestRef = useRef(0);
|
||||||
const locationSearchTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
const locationSearchTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
const locationAbortRef = useRef<AbortController | null>(null);
|
const locationAbortRef = useRef<AbortController | null>(null);
|
||||||
|
const dismissedLocationSuggestionsRef = useRef<Set<string>>(new Set());
|
||||||
|
const dismissLocationSuggestion = useCallback((label: string) => {
|
||||||
|
dismissedLocationSuggestionsRef.current.add(label.toLowerCase());
|
||||||
|
setLocationSuggestions(current => current.filter(suggestion => suggestion.label !== label));
|
||||||
|
}, []);
|
||||||
const dismissLocationSuggestions = useCallback(() => {
|
const dismissLocationSuggestions = useCallback(() => {
|
||||||
++locationRequestRef.current;
|
++locationRequestRef.current;
|
||||||
locationAbortRef.current?.abort();
|
locationAbortRef.current?.abort();
|
||||||
@ -244,6 +249,7 @@ export default function CalendarEventModal({
|
|||||||
if (requestId !== locationRequestRef.current) return;
|
if (requestId !== locationRequestRef.current) return;
|
||||||
const mapMatches: LocationSuggestion[] = (data.suggestions || [])
|
const mapMatches: LocationSuggestion[] = (data.suggestions || [])
|
||||||
.filter((suggestion: any) => suggestion.label)
|
.filter((suggestion: any) => suggestion.label)
|
||||||
|
.filter((suggestion: any) => !dismissedLocationSuggestionsRef.current.has(suggestion.label.toLowerCase()))
|
||||||
.map((suggestion: any) => ({ ...suggestion, source: 'openstreetmap' }));
|
.map((suggestion: any) => ({ ...suggestion, source: 'openstreetmap' }));
|
||||||
const localLabels = new Set(localMatches.map(suggestion => suggestion.label.toLowerCase()));
|
const localLabels = new Set(localMatches.map(suggestion => suggestion.label.toLowerCase()));
|
||||||
setLocationSuggestions([
|
setLocationSuggestions([
|
||||||
@ -885,7 +891,21 @@ export default function CalendarEventModal({
|
|||||||
<MapPin size={11} style={{ opacity: 0.4, flexShrink: 0 }} />
|
<MapPin size={11} style={{ opacity: 0.4, flexShrink: 0 }} />
|
||||||
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{suggestion.label}</span>
|
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{suggestion.label}</span>
|
||||||
{suggestion.source === 'openstreetmap' && (
|
{suggestion.source === 'openstreetmap' && (
|
||||||
<span style={{ marginLeft: 'auto', fontSize: '0.65rem', opacity: 0.5, whiteSpace: 'nowrap' }}>OpenStreetMap</span>
|
<>
|
||||||
|
<span style={{ marginLeft: 'auto', fontSize: '0.65rem', opacity: 0.5, whiteSpace: 'nowrap' }}>OpenStreetMap</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={language === 'de' ? 'Vorschlag entfernen' : 'Remove suggestion'}
|
||||||
|
title={language === 'de' ? 'Vorschlag entfernen' : 'Remove suggestion'}
|
||||||
|
onMouseDown={e => { e.preventDefault(); e.stopPropagation(); dismissLocationSuggestion(suggestion.label); }}
|
||||||
|
style={{
|
||||||
|
border: 'none', background: 'transparent', color: 'var(--weekly-text-light)',
|
||||||
|
cursor: 'pointer', padding: '0 2px', fontSize: '0.9rem', lineHeight: 1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user