mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
fix(places): the first CI run on the place view and the copies in step
Imports the picture icon the media sections draw for "use as the place picture", narrows the types the type check refused, moves the dropdown open state and the media lightbox into one module each for both views, replaces an await in a loop, and lowers the ratchet baselines to the counts the run measured. The tests follow the place view: the vote route of a trip place lives with the votes now, the history holds an entry per copy that followed an edit, the rate_library_place tool has its broadcast case, and the row tags of a list are dots behind the name.
This commit is contained in:
@@ -346,7 +346,8 @@ describe('useCollabChatData on a box that changes size', () => {
|
||||
it('FE-COLLAB-CHATDATA-017: a list at its newest message stays there when a rotation or a fold resizes it', async () => {
|
||||
vi.stubGlobal('ResizeObserver', Observer);
|
||||
const { list, grow } = await mountList(400);
|
||||
expect(observed).toContain(list);
|
||||
// The observer starts in an effect after the list is drawn; under load that comes a tick later.
|
||||
await waitFor(() => expect(observed).toContain(list));
|
||||
grow(900);
|
||||
report();
|
||||
expect(list.scrollTop).toBe(900);
|
||||
|
||||
@@ -112,7 +112,7 @@ function StatusSegment({
|
||||
|
||||
type Form = ReturnType<typeof useCollectionPlaceForm>;
|
||||
|
||||
/** The cover: the picture or a gradient, the category, the picture controls, close, and the name. */
|
||||
/** The cover: the picture or a gradient, the category, the picture controls and the name. */
|
||||
function Cover({
|
||||
place,
|
||||
form,
|
||||
@@ -120,7 +120,6 @@ function Cover({
|
||||
categories,
|
||||
labelId,
|
||||
onUploadImage,
|
||||
onClose,
|
||||
t,
|
||||
}: {
|
||||
place: CollectionPlace;
|
||||
@@ -129,7 +128,6 @@ function Cover({
|
||||
categories: Category[];
|
||||
labelId: string;
|
||||
onUploadImage?: (file: File) => Promise<void>;
|
||||
onClose: () => void;
|
||||
t: TranslationFn;
|
||||
}) {
|
||||
const coverInputRef = useRef<HTMLInputElement>(null);
|
||||
@@ -478,7 +476,6 @@ export default function CollectionPlaceDetail({
|
||||
categories={categories}
|
||||
labelId={labelId}
|
||||
onUploadImage={onUploadImage}
|
||||
onClose={onClose}
|
||||
t={t}
|
||||
/>
|
||||
<div className="place-aside-body">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Check, ChevronDown } from 'lucide-react';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import React from 'react';
|
||||
import { useDropdownOpen } from './useDropdownOpen';
|
||||
|
||||
export interface FilterOption {
|
||||
key: string | number;
|
||||
@@ -20,23 +21,7 @@ export default function FilterDropdown({
|
||||
onSelect: (key: string | number) => void;
|
||||
lead: React.ReactNode;
|
||||
}): React.ReactElement {
|
||||
const [open, setOpen] = useState(false);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onDoc = (e: MouseEvent) => {
|
||||
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
||||
};
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') setOpen(false);
|
||||
};
|
||||
document.addEventListener('mousedown', onDoc);
|
||||
document.addEventListener('keydown', onKey);
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', onDoc);
|
||||
document.removeEventListener('keydown', onKey);
|
||||
};
|
||||
}, [open]);
|
||||
const { open, setOpen, ref } = useDropdownOpen();
|
||||
|
||||
const cur = options.find((o) => o.key === current) ?? options[0];
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
import PhotoLightbox from '../Journey/PhotoLightbox';
|
||||
import type { usePlaceMedia } from './usePlaceMedia';
|
||||
|
||||
/** The open picture of a place's media, for the desktop sheet and the phone sheet alike. */
|
||||
export default function PlaceMediaLightbox({
|
||||
media,
|
||||
label,
|
||||
}: {
|
||||
media: ReturnType<typeof usePlaceMedia>;
|
||||
label: string;
|
||||
}): React.ReactElement | null {
|
||||
if (media.open === null) return null;
|
||||
return (
|
||||
<PhotoLightbox
|
||||
photos={media.photos.map((p) => ({
|
||||
id: p.id,
|
||||
src: p.src,
|
||||
thumbSrc: p.thumbSrc,
|
||||
caption: p.caption,
|
||||
provider: p.provider,
|
||||
mediaType: p.mediaType,
|
||||
}))}
|
||||
startIndex={media.open}
|
||||
onClose={media.close}
|
||||
label={label}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { PlacesLibraryEntry } from '@trek/shared';
|
||||
import { Bookmark, FileText, Images, Layers, Loader2, Luggage, Plus, Upload } from 'lucide-react';
|
||||
import { Bookmark, FileText, ImageUp, Images, Layers, Loader2, Luggage, Plus, Upload } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import type { TranslationFn } from '../../types';
|
||||
import PhotoLightbox from '../Journey/PhotoLightbox';
|
||||
import { Tooltip } from '../shared/Tooltip';
|
||||
import PlaceCard from './PlaceCard';
|
||||
import PlaceMediaLightbox from './PlaceMediaLightbox';
|
||||
import { useMediaAdd } from './mediaAdd';
|
||||
import { usePlaceMedia, type MediaTarget } from './usePlaceMedia';
|
||||
|
||||
@@ -134,21 +134,7 @@ export function PlaceMediaView({
|
||||
))}
|
||||
</PlaceCard>
|
||||
)}
|
||||
{m.open !== null && (
|
||||
<PhotoLightbox
|
||||
photos={m.photos.map((p) => ({
|
||||
id: p.id,
|
||||
src: p.src,
|
||||
thumbSrc: p.thumbSrc,
|
||||
caption: p.caption,
|
||||
provider: p.provider,
|
||||
mediaType: p.mediaType,
|
||||
}))}
|
||||
startIndex={m.open}
|
||||
onClose={m.close}
|
||||
label={label}
|
||||
/>
|
||||
)}
|
||||
<PlaceMediaLightbox media={m} label={label} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Check, ChevronDown, Tag } from 'lucide-react';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import React from 'react';
|
||||
import type { TranslationFn } from '../../types';
|
||||
import { useDropdownOpen } from './useDropdownOpen';
|
||||
|
||||
/**
|
||||
* The tag filter of All places, shaped like the dropdowns beside it but with
|
||||
@@ -18,23 +19,7 @@ export default function TagFilterDropdown({
|
||||
onToggle: (name: string) => void;
|
||||
t: TranslationFn;
|
||||
}): React.ReactElement | null {
|
||||
const [open, setOpen] = useState(false);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onDoc = (e: MouseEvent) => {
|
||||
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
||||
};
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') setOpen(false);
|
||||
};
|
||||
document.addEventListener('mousedown', onDoc);
|
||||
document.addEventListener('keydown', onKey);
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', onDoc);
|
||||
document.removeEventListener('keydown', onKey);
|
||||
};
|
||||
}, [open]);
|
||||
const { open, setOpen, ref } = useDropdownOpen();
|
||||
|
||||
if (tags.length === 0) return null;
|
||||
const label =
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
/**
|
||||
* Whether a compact filter dropdown is open, closed again by a press outside
|
||||
* its element or by Escape. The filter dropdowns of the lists and All places
|
||||
* share it.
|
||||
*/
|
||||
export function useDropdownOpen() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onDoc = (e: MouseEvent) => {
|
||||
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
||||
};
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') setOpen(false);
|
||||
};
|
||||
document.addEventListener('mousedown', onDoc);
|
||||
document.addEventListener('keydown', onKey);
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', onDoc);
|
||||
document.removeEventListener('keydown', onKey);
|
||||
};
|
||||
}, [open]);
|
||||
return { open, setOpen, ref };
|
||||
}
|
||||
@@ -102,7 +102,7 @@ describe('usePlaceSheet', () => {
|
||||
it('FE-COMP-PLACESHEET-003: each tab counts what it holds, the files and pictures together', () => {
|
||||
parts.notes = { notes: [1, 2], targets: [] };
|
||||
parts.activities = { activities: [1], canLink: false };
|
||||
parts.media = { photos: [1, 2], files: [1] };
|
||||
parts.media = { photos: [1, 2], files: [1], targets: [] };
|
||||
parts.history = { entries: [1, 2, 3, 4] };
|
||||
const { result } = setup(bothOrigins());
|
||||
expect(result.current.counts).toEqual({ overview: 0, notes: 2, activities: 1, media: 3, history: 4 });
|
||||
|
||||
@@ -234,7 +234,7 @@ export default function PlaceInspector({
|
||||
.catch(() => { if (!cancelled) setProviderDetails([]) })
|
||||
return () => { cancelled = true }
|
||||
}, [placeIdForDetails])
|
||||
const { t, locale, language } = useTranslation()
|
||||
const { t, locale } = useTranslation()
|
||||
const placeLang = usePlaceLanguage()
|
||||
// Currency-less prices mean "the trip's currency"; null in collection mode (EUR fallback below).
|
||||
const tripCurrency = useTripStore(s => s.trip?.currency)
|
||||
|
||||
Reference in New Issue
Block a user