mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
d758f4c592
The desktop dialog and the phone sheet of a place show its overview, notes, tours and bookings, photos and files and its history in tabs, with the tags of each list and trip, a markdown notes editor, uploads and the place picture. The rating bar of All places is the rating row the lists show, with its voters, and votes once for every copy. All places filters by a lowest rating and sorts by it, and the edit form changes the first copy the reader may edit, which the server carries to the others.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { useRef } from 'react';
|
|
import type { MediaTarget, usePlaceMedia } from './usePlaceMedia';
|
|
|
|
/**
|
|
* Adding a picture or file: one target opens the file dialog at once; several ask
|
|
* first where it goes (a trip keeps any file, a list a picture of the place).
|
|
* The trigger is the card's action, or the empty card's own wide button.
|
|
*/
|
|
export function useMediaAdd(m: ReturnType<typeof usePlaceMedia>) {
|
|
const input = useRef<HTMLInputElement>(null);
|
|
const target = useRef<readonly MediaTarget[]>([]);
|
|
/** One trip or list, or every one of them at once (`'all'`). */
|
|
const pick = (next: MediaTarget | 'all') => {
|
|
target.current = next === 'all' ? m.targets : [next];
|
|
m.setChoosing(false);
|
|
if (input.current) {
|
|
input.current.accept = target.current.every((x) => x.kind === 'list') ? 'image/*' : '';
|
|
input.current.click();
|
|
}
|
|
};
|
|
const start = () => {
|
|
if (m.targets.length === 1) pick(m.targets[0]);
|
|
else m.setChoosing(!m.choosing);
|
|
};
|
|
const field = (
|
|
<input
|
|
ref={input}
|
|
type="file"
|
|
multiple
|
|
className="hidden"
|
|
onChange={(e) => {
|
|
const files = Array.from(e.target.files ?? []);
|
|
e.target.value = '';
|
|
if (target.current.length) void m.upload(target.current, files);
|
|
}}
|
|
/>
|
|
);
|
|
return { start, pick, field };
|
|
}
|