mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +00:00
fix(ci): repair Journey route registration and shared client behavior
Register the public view route, align generated entities and test fixtures, and share the scoped reads and access switches. Keep gallery and notification writes in order, and submit the email subscription from the dialog footer.
This commit is contained in:
@@ -84,17 +84,11 @@ describe('journeyRecordingsApi', () => {
|
||||
});
|
||||
|
||||
it('FE-API-JOURNEY-RECORDINGS-004: sends a GPX file with its fields and drops the day of one source (#3085)', async () => {
|
||||
const sent: Array<{ file: string | null; date: unknown; utcOffsetMinutes: unknown }> = [];
|
||||
const sent: Array<{ contentType: string | null; body: string }> = [];
|
||||
const deleted: string[] = [];
|
||||
server.use(
|
||||
http.post(`${BASE}/import-gpx`, async ({ request }) => {
|
||||
const form = await request.formData();
|
||||
const file = form.get('file');
|
||||
sent.push({
|
||||
file: file instanceof Blob ? await file.text() : null,
|
||||
date: form.get('date'),
|
||||
utcOffsetMinutes: form.get('utcOffsetMinutes'),
|
||||
});
|
||||
sent.push({ contentType: request.headers.get('content-type'), body: await request.text() });
|
||||
return HttpResponse.json({ days: [], untimedPoints: 0 });
|
||||
}),
|
||||
http.delete(`${BASE}/2026-05-14`, ({ request }) => {
|
||||
@@ -112,10 +106,15 @@ describe('journeyRecordingsApi', () => {
|
||||
await journeyRecordingsApi.remove(7, '2026-05-14', 'gpx');
|
||||
await journeyRecordingsApi.remove(7, '2026-05-14');
|
||||
|
||||
expect(sent).toEqual([
|
||||
{ file: '<gpx></gpx>', date: '2026-05-14', utcOffsetMinutes: '-300' },
|
||||
{ file: '<gpx></gpx>', date: null, utcOffsetMinutes: null },
|
||||
]);
|
||||
expect(sent).toHaveLength(2);
|
||||
for (const part of sent) {
|
||||
expect(part.contentType).toMatch(/^multipart\/form-data;\s*boundary=/i);
|
||||
expect(part.body).toContain('name="file"');
|
||||
expect(part.body).toContain('<gpx></gpx>');
|
||||
}
|
||||
expect(sent[0]?.body).toMatch(/name="date"\s+2026-05-14/);
|
||||
expect(sent[0]?.body).toMatch(/name="utcOffsetMinutes"\s+-300/);
|
||||
expect(sent[1]?.body).not.toMatch(/name="(?:date|utcOffsetMinutes)"/);
|
||||
expect(deleted).toEqual(['?source=gpx', '']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -98,7 +98,7 @@ describe('the journal entries card', () => {
|
||||
expect(screen.getByText('4 photos')).toBeInTheDocument();
|
||||
expect(screen.getByText('Opens with a video')).toBeInTheDocument();
|
||||
expect(screen.getByText('Berlin 2026')).toBeInTheDocument();
|
||||
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/7/preview');
|
||||
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/7/thumbnail');
|
||||
});
|
||||
|
||||
it('FE-AI-JOURNEY-002: an entry without a photo takes the width, and a known mood and weather are named', () => {
|
||||
@@ -236,7 +236,7 @@ describe('a change row of a journal entry', () => {
|
||||
expect(screen.getByText('Tue, Oct 21')).toBeInTheDocument();
|
||||
expect(screen.getByText('Museum Island')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Not a fact')).toBeNull();
|
||||
expect(document.querySelector('img')).toHaveAttribute('src', '/api/photos/7/preview');
|
||||
expect(document.querySelector('img')).toHaveAttribute('src', '/api/photos/7/thumbnail');
|
||||
first.unmount();
|
||||
|
||||
const second = inView(<AssistantChangeCard items={[item('applied', held)]} />, { onOpen });
|
||||
|
||||
@@ -108,66 +108,21 @@ export default function JourneyDayRecordingButton({
|
||||
}
|
||||
|
||||
if (gpx?.day) {
|
||||
const { distance, label } = keptLabel(gpx.day);
|
||||
const full = `${label} ${t('journey.recording.gpx.source')}`;
|
||||
return (
|
||||
<>
|
||||
{fileInput}
|
||||
<Tooltip label={full} placement="top" disabled={!!menu.menu}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={
|
||||
canImportGpx
|
||||
? (e) =>
|
||||
menu.open(
|
||||
e,
|
||||
[
|
||||
{ label: t('journey.recording.replace'), icon: RefreshCw, onClick: pickFile },
|
||||
{ label: t('journey.recording.remove'), icon: Trash2, onClick: gpx.onRemove, danger: true },
|
||||
],
|
||||
true
|
||||
)
|
||||
: undefined
|
||||
}
|
||||
aria-disabled={!canImportGpx || gpx.busy}
|
||||
aria-label={full}
|
||||
aria-haspopup={canImportGpx ? 'menu' : undefined}
|
||||
data-testid="journey-day-recording"
|
||||
className={PILL}
|
||||
style={{ ...fs(10.5), background: 'var(--vg-surf2)', color: 'var(--vg-ink)' }}
|
||||
>
|
||||
<FileUp size={12} strokeWidth={2.4} aria-hidden="true" />
|
||||
{distance}
|
||||
</button>
|
||||
</Tooltip>
|
||||
<ContextMenu menu={menu.menu} onClose={menu.close} />
|
||||
</>
|
||||
<GpxRecordingPill
|
||||
gpx={gpx}
|
||||
detail={keptLabel(gpx.day)}
|
||||
canImport={canImportGpx}
|
||||
fileInput={fileInput}
|
||||
pickFile={pickFile}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (!canTakeOver && !needsConnection && !canImportGpx) return null;
|
||||
|
||||
// Only a file to read: the button opens the file picker straight away.
|
||||
if (canImportGpx && !canTakeOver) {
|
||||
const label = t('journey.recording.gpx.import');
|
||||
return (
|
||||
<>
|
||||
{fileInput}
|
||||
<Tooltip label={label} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
onClick={gpx?.busy ? undefined : pickFile}
|
||||
aria-disabled={!!gpx?.busy}
|
||||
aria-label={label}
|
||||
data-testid="journey-day-recording"
|
||||
className={ROUND}
|
||||
style={{ background: 'var(--vg-surf2)', color: 'var(--vg-ink3)' }}
|
||||
>
|
||||
<Route size={14} strokeWidth={2.2} />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</>
|
||||
);
|
||||
return <ImportGpxButton busy={!!gpx?.busy} fileInput={fileInput} pickFile={pickFile} />;
|
||||
}
|
||||
|
||||
const label = canTakeOver ? t('journey.recording.takeOver') : t('dawarich.error.offline');
|
||||
@@ -190,11 +145,9 @@ export default function JourneyDayRecordingButton({
|
||||
true
|
||||
)
|
||||
: onOpen
|
||||
: canImportGpx
|
||||
? pickFile
|
||||
: undefined
|
||||
: undefined
|
||||
}
|
||||
aria-disabled={!canTakeOver && !canImportGpx}
|
||||
aria-disabled={!canTakeOver}
|
||||
aria-label={label}
|
||||
aria-haspopup={canTakeOver && canImportGpx ? 'menu' : undefined}
|
||||
data-testid="journey-day-recording"
|
||||
@@ -208,3 +161,87 @@ export default function JourneyDayRecordingButton({
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ImportGpxButton({
|
||||
busy,
|
||||
fileInput,
|
||||
pickFile,
|
||||
}: {
|
||||
busy: boolean;
|
||||
fileInput: React.ReactNode;
|
||||
pickFile: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const label = t('journey.recording.gpx.import');
|
||||
return (
|
||||
<>
|
||||
{fileInput}
|
||||
<Tooltip label={label} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
onClick={busy ? undefined : pickFile}
|
||||
aria-disabled={busy}
|
||||
aria-label={label}
|
||||
data-testid="journey-day-recording"
|
||||
className={ROUND}
|
||||
style={{ background: 'var(--vg-surf2)', color: 'var(--vg-ink3)' }}
|
||||
>
|
||||
<Route size={14} strokeWidth={2.2} />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function GpxRecordingPill({
|
||||
gpx,
|
||||
detail,
|
||||
canImport,
|
||||
fileInput,
|
||||
pickFile,
|
||||
}: {
|
||||
gpx: DayGpx;
|
||||
detail: { distance: string; label: string };
|
||||
canImport: boolean;
|
||||
fileInput: React.ReactNode;
|
||||
pickFile: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const menu = useContextMenu();
|
||||
const { distance, label } = detail;
|
||||
const actionable = canImport && !gpx.busy;
|
||||
const full = `${label} ${t('journey.recording.gpx.source')}`;
|
||||
return (
|
||||
<>
|
||||
{fileInput}
|
||||
<Tooltip label={full} placement="top" disabled={!!menu.menu}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={
|
||||
actionable
|
||||
? (e) =>
|
||||
menu.open(
|
||||
e,
|
||||
[
|
||||
{ label: t('journey.recording.replace'), icon: RefreshCw, onClick: pickFile },
|
||||
{ label: t('journey.recording.remove'), icon: Trash2, onClick: gpx.onRemove, danger: true },
|
||||
],
|
||||
true
|
||||
)
|
||||
: undefined
|
||||
}
|
||||
aria-disabled={!actionable}
|
||||
aria-label={full}
|
||||
aria-haspopup={actionable ? 'menu' : undefined}
|
||||
data-testid="journey-day-recording"
|
||||
className={PILL}
|
||||
style={{ ...fs(10.5), background: 'var(--vg-surf2)', color: 'var(--vg-ink)' }}
|
||||
>
|
||||
<FileUp size={12} strokeWidth={2.4} aria-hidden="true" />
|
||||
{distance}
|
||||
</button>
|
||||
</Tooltip>
|
||||
<ContextMenu menu={menu.menu} onClose={menu.close} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ export function EntryCard({ entry, readOnly, onEdit, onDelete, onPhotoClick, com
|
||||
</div>
|
||||
)}
|
||||
|
||||
{comments && <div className="pt-3 mt-3 border-t border-zinc-100 dark:border-zinc-800">{comments}</div>}
|
||||
{comments && <div className="pt-3 mt-3 border-t border-edge-faint">{comments}</div>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -8,10 +8,10 @@ import { Tooltip } from '../shared/Tooltip';
|
||||
/** One comment as the thread draws it: in the app and on the shared page alike. */
|
||||
export interface EntryCommentItem {
|
||||
id: number;
|
||||
author_name: string | null;
|
||||
author_name?: string | null;
|
||||
is_guest: boolean;
|
||||
body: string;
|
||||
created_at: string | null;
|
||||
created_at?: string | null;
|
||||
hidden?: boolean;
|
||||
own?: boolean;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ export default function JourneyEntryComments({
|
||||
setBody('');
|
||||
};
|
||||
|
||||
const dateOf = (iso: string | null) =>
|
||||
const dateOf = (iso: string | null | undefined) =>
|
||||
iso ? new Date(iso).toLocaleDateString(locale || undefined, { day: 'numeric', month: 'short' }) : '';
|
||||
|
||||
const toggle = (
|
||||
@@ -158,7 +158,7 @@ export default function JourneyEntryComments({
|
||||
<button
|
||||
type="button"
|
||||
aria-label={c.hidden ? t('journey.comments.show') : t('journey.comments.hide')}
|
||||
onClick={() => void onHide!(c.id, !c.hidden)}
|
||||
onClick={() => void onHide?.(c.id, !c.hidden)}
|
||||
className="flex h-7 w-7 items-center justify-center rounded-full text-content-faint hover:bg-surface-secondary hover:text-content"
|
||||
>
|
||||
{c.hidden ? <Eye size={13} /> : <EyeOff size={13} />}
|
||||
@@ -170,7 +170,7 @@ export default function JourneyEntryComments({
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t('common.delete')}
|
||||
onClick={() => void onDelete!(c.id)}
|
||||
onClick={() => void onDelete?.(c.id)}
|
||||
className="flex h-7 w-7 items-center justify-center rounded-full text-content-faint hover:bg-danger-soft hover:text-danger"
|
||||
>
|
||||
<Trash2 size={13} />
|
||||
|
||||
@@ -56,6 +56,36 @@ function ShareFollowers({ access }: { access: ShareAccess }) {
|
||||
)
|
||||
}
|
||||
|
||||
function ShareDetailToggle({ icon: Icon, label, hint, on, disabledReason, toggle }: {
|
||||
icon: typeof MessageCircle
|
||||
label: string
|
||||
hint: string
|
||||
on: boolean
|
||||
disabledReason: string
|
||||
toggle: () => void
|
||||
}) {
|
||||
return (
|
||||
<Tooltip label={disabledReason} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={on}
|
||||
disabled={!!disabledReason}
|
||||
onClick={toggle}
|
||||
className={`flex w-full items-start gap-2.5 rounded-xl border px-3 py-2 text-start transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${
|
||||
on ? 'border-accent bg-accent text-accent-text' : 'border-edge text-content-muted hover:border-content-faint'
|
||||
}`}
|
||||
>
|
||||
<Icon size={13} className="mt-0.5 flex-none" />
|
||||
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
||||
<span className="font-medium" style={fs(12, 'body')}>{label}</span>
|
||||
<span className={on ? 'text-accent-text opacity-80' : 'text-content-faint'} style={fs(11)}>{hint}</span>
|
||||
</span>
|
||||
{on && <Check size={12} className="mt-0.5 flex-none" />}
|
||||
</button>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
/** What readers of the link may do besides reading (#1702, #1669): each off until switched on. */
|
||||
function ShareReaders({ link, access, onToggle }: { link: JourneyShareLink; access: ShareAccess; onToggle: (key: JourneyShareInteraction) => void }) {
|
||||
const { t } = useTranslation()
|
||||
@@ -66,24 +96,15 @@ function ShareReaders({ link, access, onToggle }: { link: JourneyShareLink; acce
|
||||
const blocked = key === 'allow_comments' && !link.share_timeline
|
||||
const on = !blocked && !!link[key]
|
||||
return (
|
||||
<Tooltip key={key} label={blocked ? t('journey.share.needsTimeline') : ''} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={on}
|
||||
disabled={blocked}
|
||||
onClick={() => onToggle(key)}
|
||||
className={`flex w-full items-start gap-2.5 rounded-xl border px-3 py-2 text-start transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${
|
||||
on ? 'border-accent bg-accent text-accent-text' : 'border-edge text-content-muted hover:border-content-faint'
|
||||
}`}
|
||||
>
|
||||
<Icon size={13} className="mt-0.5 flex-none" />
|
||||
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
||||
<span className="font-medium" style={fs(12, 'body')}>{t(labelKey)}</span>
|
||||
<span className={on ? 'text-accent-text opacity-80' : 'text-content-faint'} style={fs(11)}>{t(hintKey)}</span>
|
||||
</span>
|
||||
{on && <Check size={12} className="mt-0.5 flex-none" />}
|
||||
</button>
|
||||
</Tooltip>
|
||||
<ShareDetailToggle
|
||||
key={key}
|
||||
icon={Icon}
|
||||
label={t(labelKey)}
|
||||
hint={t(hintKey)}
|
||||
on={on}
|
||||
disabledReason={blocked ? t('journey.share.needsTimeline') : ''}
|
||||
toggle={() => onToggle(key)}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
{link.allow_subscriptions && <ShareFollowers access={access} />}
|
||||
@@ -149,24 +170,15 @@ function ShareMapExtras({ link, onToggle }: { link: JourneyShareLink; onToggle:
|
||||
const Icon = EXTRA_ICONS[key]
|
||||
const on = mapShared && !!link[key]
|
||||
return (
|
||||
<Tooltip key={key} label={mapShared ? '' : t('journey.share.needsMap')} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={on}
|
||||
disabled={!mapShared}
|
||||
onClick={() => onToggle(key)}
|
||||
className={`flex w-full items-start gap-2.5 rounded-xl border px-3 py-2 text-start transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${
|
||||
on ? 'border-accent bg-accent text-accent-text' : 'border-edge text-content-muted hover:border-content-faint'
|
||||
}`}
|
||||
>
|
||||
<Icon size={13} className="mt-0.5 flex-none" />
|
||||
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
||||
<span className="font-medium" style={fs(12, 'body')}>{t(labelKey)}</span>
|
||||
<span className={on ? 'text-accent-text opacity-80' : 'text-content-faint'} style={fs(11)}>{t(hintKey)}</span>
|
||||
</span>
|
||||
{on && <Check size={12} className="mt-0.5 flex-none" />}
|
||||
</button>
|
||||
</Tooltip>
|
||||
<ShareDetailToggle
|
||||
key={key}
|
||||
icon={Icon}
|
||||
label={t(labelKey)}
|
||||
hint={t(hintKey)}
|
||||
on={on}
|
||||
disabledReason={mapShared ? '' : t('journey.share.needsMap')}
|
||||
toggle={() => onToggle(key)}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -295,7 +295,7 @@ export default function MobileEntryView({ entry, readOnly, publicPhotoUrl, onClo
|
||||
</div>
|
||||
)}
|
||||
|
||||
{comments && <div className="mt-6 border-t border-zinc-100 pt-4 dark:border-zinc-800">{comments}</div>}
|
||||
{comments && <div className="mt-6 border-t border-edge-faint pt-4">{comments}</div>}
|
||||
</div>
|
||||
</div>
|
||||
</div >
|
||||
|
||||
@@ -105,6 +105,6 @@ describe('journeyRecordingModel', () => {
|
||||
expect(gpxImportErrorText(httpError('gpx_no_times'), t)).toBe('t:journey.recording.gpx.error.noTimes');
|
||||
expect(gpxImportErrorText(httpError('recording_empty'), t)).toBe('t:journey.recording.gpx.error.emptyDay');
|
||||
expect(gpxImportErrorText(httpError('gpx_too_many_days'), t)).toBe('t:journey.recording.gpx.error.tooManyDays');
|
||||
expect(gpxImportErrorText(new Error('boom'), t)).toBe('t:common.errorTitle');
|
||||
expect(gpxImportErrorText(new Error('boom'), t)).toBe('t:journey.recording.gpx.failed');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
import type { JourneyComment } from '@trek/shared';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { journeySocialRepo } from '../../repo/journeySocialRepo';
|
||||
import { useServerPing } from '../../sync/useServerPing';
|
||||
import { useJourneyLiveData } from './useJourneyLiveData';
|
||||
|
||||
interface Loaded {
|
||||
journeyId: number | null;
|
||||
comments: JourneyComment[];
|
||||
canModerate: boolean;
|
||||
}
|
||||
|
||||
const NOTHING: Loaded = { journeyId: null, comments: [], canModerate: false };
|
||||
const NO_COMMENTS: JourneyComment[] = [];
|
||||
|
||||
interface JourneyCommentsState {
|
||||
@@ -36,41 +29,8 @@ interface JourneyCommentsState {
|
||||
* can say so.
|
||||
*/
|
||||
export function useJourneyComments(journeyId: number | null): JourneyCommentsState {
|
||||
const [loaded, setLoaded] = useState<Loaded>(NOTHING);
|
||||
const [failedFor, setFailedFor] = useState<number | null>(null);
|
||||
const current = loaded.journeyId === journeyId ? loaded : null;
|
||||
const comments = current?.comments ?? NO_COMMENTS;
|
||||
const status = journeyId === null ? 'idle' : current ? 'ready' : failedFor === journeyId ? 'failed' : 'loading';
|
||||
|
||||
const read = useCallback(async (): Promise<Loaded | null> => {
|
||||
if (journeyId === null) return null;
|
||||
try {
|
||||
const answer = await journeySocialRepo.comments(journeyId);
|
||||
return { journeyId, comments: answer.comments, canModerate: answer.can_moderate };
|
||||
} catch {
|
||||
// What was read before stays: a thread does not vanish because one read failed.
|
||||
return null;
|
||||
}
|
||||
}, [journeyId]);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
void read().then((next) => {
|
||||
if (cancelled) return;
|
||||
if (next) setLoaded(next);
|
||||
else setFailedFor(journeyId);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [read, journeyId]);
|
||||
|
||||
const reload = useCallback(async () => {
|
||||
const next = await read();
|
||||
if (next) setLoaded(next);
|
||||
}, [read]);
|
||||
|
||||
useServerPing('journey:entry:commented', journeyId !== null, reload);
|
||||
const { data, status, update } = useJourneyLiveData(journeyId, 'journey:entry:commented', journeySocialRepo.comments);
|
||||
const comments = data?.comments ?? NO_COMMENTS;
|
||||
|
||||
const byEntry = useMemo(() => {
|
||||
const map = new Map<number, JourneyComment[]>();
|
||||
@@ -83,13 +43,13 @@ export function useJourneyComments(journeyId: number | null): JourneyCommentsSta
|
||||
if (journeyId === null || !body.trim()) return false;
|
||||
try {
|
||||
const comment = await journeySocialRepo.addComment(journeyId, entryId, body);
|
||||
setLoaded((prev) => (prev.journeyId === journeyId ? { ...prev, comments: [...prev.comments, comment] } : prev));
|
||||
update((prev) => (prev ? { ...prev, comments: [...prev.comments, comment] } : null));
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
[journeyId]
|
||||
[journeyId, update]
|
||||
);
|
||||
|
||||
const setHidden = useCallback(
|
||||
@@ -97,16 +57,15 @@ export function useJourneyComments(journeyId: number | null): JourneyCommentsSta
|
||||
if (journeyId === null) return false;
|
||||
try {
|
||||
await journeySocialRepo.setCommentHidden(journeyId, commentId, hidden);
|
||||
setLoaded((prev) => ({
|
||||
...prev,
|
||||
comments: prev.comments.map((c) => (c.id === commentId ? { ...c, hidden } : c)),
|
||||
}));
|
||||
update((prev) =>
|
||||
prev ? { ...prev, comments: prev.comments.map((c) => (c.id === commentId ? { ...c, hidden } : c)) } : null
|
||||
);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
[journeyId]
|
||||
[journeyId, update]
|
||||
);
|
||||
|
||||
const remove = useCallback(
|
||||
@@ -114,14 +73,14 @@ export function useJourneyComments(journeyId: number | null): JourneyCommentsSta
|
||||
if (journeyId === null) return false;
|
||||
try {
|
||||
await journeySocialRepo.deleteComment(journeyId, commentId);
|
||||
setLoaded((prev) => ({ ...prev, comments: prev.comments.filter((c) => c.id !== commentId) }));
|
||||
update((prev) => (prev ? { ...prev, comments: prev.comments.filter((c) => c.id !== commentId) } : null));
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
[journeyId]
|
||||
[journeyId, update]
|
||||
);
|
||||
|
||||
return { comments, byEntry, canModerate: current?.canModerate ?? false, status, add, setHidden, remove };
|
||||
return { comments, byEntry, canModerate: data?.can_moderate ?? false, status, add, setHidden, remove };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
||||
import { useServerPing } from '../../sync/useServerPing';
|
||||
|
||||
type LoadStatus = 'idle' | 'loading' | 'ready' | 'failed';
|
||||
|
||||
/** Read journey data on open and server updates. Keep the last good read when a refresh fails. */
|
||||
export function useJourneyLiveData<T>(journeyId: number | null, eventName: string, read: (id: number) => Promise<T>) {
|
||||
const [loaded, setLoaded] = useState<{ journeyId: number; data: T } | null>(null);
|
||||
const [failedFor, setFailedFor] = useState<number | null>(null);
|
||||
const activeId = useRef(journeyId);
|
||||
const latestRead = useRef(0);
|
||||
useLayoutEffect(() => {
|
||||
activeId.current = journeyId;
|
||||
return () => {
|
||||
activeId.current = null;
|
||||
latestRead.current++;
|
||||
};
|
||||
}, [journeyId]);
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
if (journeyId === null) return;
|
||||
const version = ++latestRead.current;
|
||||
await read(journeyId).then(
|
||||
(data) => {
|
||||
if (latestRead.current === version) setLoaded({ journeyId, data });
|
||||
},
|
||||
() => {
|
||||
if (latestRead.current === version) setFailedFor(journeyId);
|
||||
}
|
||||
);
|
||||
}, [journeyId, read]);
|
||||
|
||||
useEffect(() => {
|
||||
void refresh();
|
||||
}, [refresh]);
|
||||
|
||||
useServerPing(eventName, journeyId !== null, refresh);
|
||||
|
||||
const update = useCallback(
|
||||
(change: (data: T | null) => T | null) => {
|
||||
if (journeyId === null || activeId.current !== journeyId) return;
|
||||
setLoaded((previous) => {
|
||||
const data = change(previous?.journeyId === journeyId ? previous.data : null);
|
||||
return data === null ? previous : { journeyId, data };
|
||||
});
|
||||
},
|
||||
[journeyId]
|
||||
);
|
||||
const current = loaded?.journeyId === journeyId ? loaded : null;
|
||||
const status: LoadStatus =
|
||||
journeyId === null ? 'idle' : current ? 'ready' : failedFor === journeyId ? 'failed' : 'loading';
|
||||
|
||||
return { data: current?.data ?? null, status, update };
|
||||
}
|
||||
@@ -4,11 +4,11 @@ import {
|
||||
type JourneyRecordingSource,
|
||||
type JourneyTrack,
|
||||
} from '@trek/shared';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useTranslation } from '../../i18n';
|
||||
import { journeyRecordingsRepo } from '../../repo/journeyRecordingsRepo';
|
||||
import { useServerPing } from '../../sync/useServerPing';
|
||||
import { DAWARICH_TRAIL_COLOR } from '../Map/dawarichTrail';
|
||||
import { useJourneyLiveData } from './useJourneyLiveData';
|
||||
import type { JourneyRecordingViewProps } from './useJourneyRecordingDay';
|
||||
|
||||
interface JourneyRecordingsState {
|
||||
@@ -53,52 +53,15 @@ export function useJourneyRecordings(
|
||||
const journeyId = journey?.id ?? null;
|
||||
const journeyTitle = journey?.title ?? '';
|
||||
const { t, locale } = useTranslation();
|
||||
// Held with the journey they belong to, so a journey opened after another
|
||||
// never shows the other one's days, and nothing has to be reset in an effect.
|
||||
const [loaded, setLoaded] = useState<{ journeyId: number | null; days: JourneyRecordedDay[] }>(NOTHING_LOADED);
|
||||
const { data, status, update } = useJourneyLiveData(
|
||||
journeyId,
|
||||
'journey:recording:updated',
|
||||
journeyRecordingsRepo.list
|
||||
);
|
||||
const days = data ?? NO_DAYS;
|
||||
const [opened, setOpened] = useState<{ journeyId: number | null; date: string | null }>(NOTHING_OPEN);
|
||||
const [failedFor, setFailedFor] = useState<number | null>(null);
|
||||
const days = loaded.journeyId === journeyId ? loaded.days : NO_DAYS;
|
||||
const status =
|
||||
journeyId === null
|
||||
? 'idle'
|
||||
: loaded.journeyId === journeyId
|
||||
? 'ready'
|
||||
: failedFor === journeyId
|
||||
? 'failed'
|
||||
: 'loading';
|
||||
const openDate = opened.journeyId === journeyId ? opened.date : null;
|
||||
|
||||
const read = useCallback(async () => {
|
||||
if (journeyId === null) return null;
|
||||
try {
|
||||
return { journeyId, days: await journeyRecordingsRepo.list(journeyId) };
|
||||
} catch {
|
||||
// What was read before stays on the map; a kept day does not vanish
|
||||
// because one read of it failed.
|
||||
return null;
|
||||
}
|
||||
}, [journeyId]);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
void read().then((next) => {
|
||||
if (cancelled) return;
|
||||
if (next) setLoaded(next);
|
||||
else setFailedFor(journeyId);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [read, journeyId]);
|
||||
|
||||
const reload = useCallback(async () => {
|
||||
const next = await read();
|
||||
if (next) setLoaded(next);
|
||||
}, [read]);
|
||||
|
||||
useServerPing('journey:recording:updated', journeyId !== null, reload);
|
||||
|
||||
const shown = useMemo(() => oneRecordingPerDay(days), [days]);
|
||||
const byDate = useMemo(() => new Map(shown.map((day) => [day.date, day])), [shown]);
|
||||
const bySource = useMemo(
|
||||
@@ -131,16 +94,15 @@ export function useJourneyRecordings(
|
||||
);
|
||||
|
||||
const keptMany = useCallback(
|
||||
(fresh: readonly JourneyRecordedDay[]) =>
|
||||
setLoaded((prev) => ({ journeyId, days: withKeptDays(prev.days, fresh) })),
|
||||
[journeyId]
|
||||
(fresh: readonly JourneyRecordedDay[]) => update((prev) => withKeptDays(prev ?? NO_DAYS, fresh)),
|
||||
[update]
|
||||
);
|
||||
const kept = useCallback((day: JourneyRecordedDay) => keptMany([day]), [keptMany]);
|
||||
|
||||
const removed = useCallback(
|
||||
(date: string, source: JourneyRecordingSource = 'dawarich') =>
|
||||
setLoaded((prev) => ({ journeyId, days: prev.days.filter((d) => d.date !== date || d.source !== source) })),
|
||||
[journeyId]
|
||||
update((prev) => (prev ?? NO_DAYS).filter((d) => d.date !== date || d.source !== source)),
|
||||
[update]
|
||||
);
|
||||
|
||||
const open = useCallback((date: string) => setOpened({ journeyId, date }), [journeyId]);
|
||||
@@ -178,5 +140,4 @@ export function withKeptDays(
|
||||
|
||||
/** Stable empty identity, so a journey without kept days never re-renders its map for nothing. */
|
||||
const NO_DAYS: JourneyRecordedDay[] = [];
|
||||
const NOTHING_LOADED = { journeyId: null, days: NO_DAYS };
|
||||
const NOTHING_OPEN = { journeyId: null, date: null };
|
||||
|
||||
@@ -56,7 +56,9 @@ describe('owner access settings', () => {
|
||||
expect(mocks.toast.success).toHaveBeenCalledWith('journey.share.passwordSaved');
|
||||
await act(async () => result.current.removePassword());
|
||||
expect(write).toHaveBeenLastCalledWith({ password: null });
|
||||
act(() => result.current.setExpiry(''));
|
||||
await act(async () => {
|
||||
result.current.setExpiry('');
|
||||
});
|
||||
expect(write).toHaveBeenLastCalledWith({ expires_at: null });
|
||||
});
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ export function useJourneyShareLink(journeyId: number) {
|
||||
const setProtection = async (change: JourneyShareProtectionChange): Promise<boolean> => {
|
||||
if (!link) return false;
|
||||
try {
|
||||
await journeyApi.createShareLink(journeyId, change);
|
||||
await journeyApi.createShareLink(journeyId, { ...change });
|
||||
setLink((current) => (current ? applyProtection(current, change) : current));
|
||||
return true;
|
||||
} catch {
|
||||
|
||||
@@ -368,18 +368,7 @@ function MapContent({ el, set, t, stats, journeyPath }: MapPropsInput) {
|
||||
</Line>
|
||||
</Section>
|
||||
|
||||
{el.countries.length > 0 && ((el.source === 'vector' && el.showLand) || el.clip === 'country') && (
|
||||
<Section label={t('journey.studio.mapCoastDetail')} defaultOpen={false}>
|
||||
<Choice
|
||||
value={el.coastDetail ?? 'auto'}
|
||||
options={BOOK_MAP_COAST_DETAILS.map(value => ({
|
||||
value,
|
||||
label: t(`journey.studio.mapCoastDetail.${value}`),
|
||||
}))}
|
||||
onPick={coastDetail => set({ coastDetail } as Partial<BookElement>)}
|
||||
/>
|
||||
</Section>
|
||||
)}
|
||||
<MapCoastSection el={el} set={set} t={t} />
|
||||
|
||||
{el.source === 'tiles' && (
|
||||
<Section label={t('journey.studio.tileDetail')} defaultOpen={mapZoomInUse(el)}>
|
||||
@@ -397,6 +386,23 @@ function MapContent({ el, set, t, stats, journeyPath }: MapPropsInput) {
|
||||
)
|
||||
}
|
||||
|
||||
function MapCoastSection({ el, set, t }: Props<BookMapElement>) {
|
||||
const drawsCoast = (el.source === 'vector' && el.showLand) || el.clip === 'country'
|
||||
if (!drawsCoast || el.countries.length === 0) return null
|
||||
return (
|
||||
<Section label={t('journey.studio.mapCoastDetail')} defaultOpen={false}>
|
||||
<Choice
|
||||
value={el.coastDetail ?? 'auto'}
|
||||
options={BOOK_MAP_COAST_DETAILS.map(value => ({
|
||||
value,
|
||||
label: t(`journey.studio.mapCoastDetail.${value}`),
|
||||
}))}
|
||||
onPick={coastDetail => set({ coastDetail } as Partial<BookElement>)}
|
||||
/>
|
||||
</Section>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* How a map looks: the line of the route, whether it follows the roads, and
|
||||
* which layers are drawn. After the position, like the look of every kind.
|
||||
|
||||
@@ -77,7 +77,7 @@ async function fetchDetail(code: string): Promise<CountryShape | null> {
|
||||
function loadOne(code: string): Promise<void> {
|
||||
if (loaded.has(code)) return Promise.resolve();
|
||||
const running = inFlight.get(code);
|
||||
if (running) return running;
|
||||
if (running !== undefined) return running;
|
||||
const load = fetchDetail(code).then((shape) => {
|
||||
loaded.set(code, shape);
|
||||
inFlight.delete(code);
|
||||
|
||||
@@ -175,6 +175,7 @@ describe('the order of the groups', () => {
|
||||
expect(groups(m.container)).toEqual([
|
||||
'journey.studio.routeMap',
|
||||
'journey.studio.mapFraming',
|
||||
'journey.studio.mapCoastDetail',
|
||||
'journey.studio.position',
|
||||
'journey.studio.routeLook',
|
||||
'journey.studio.mapLayers',
|
||||
|
||||
@@ -56,11 +56,6 @@ export default function MJourneySettingsSheet({
|
||||
journeyId: journey.id,
|
||||
onLinked: () => { setAddTripOpen(false); onRefresh() },
|
||||
})
|
||||
const {
|
||||
link: shareLink, copied, shareUrl, createLink: createShareLink, togglePerm: toggleSharePerm,
|
||||
deleteLink: deleteShareLink, copyLink: copyShareUrl, setProtection,
|
||||
} = useJourneyShareLink(journey.id)
|
||||
const shareAccess = useJourneyShareAccess(journey.id, shareLink, setProtection)
|
||||
const coverRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
const coverSrc = journeyCoverSrc(journey.cover_image)
|
||||
@@ -241,72 +236,7 @@ export default function MJourneySettingsSheet({
|
||||
|
||||
<MTripAccessList access={journey.trip_access} />
|
||||
|
||||
<SheetSection title={t('journey.share.publicShare')}>
|
||||
{!shareLink ? (
|
||||
<button type="button" onClick={createShareLink} className={`${SHEET_PRIMARY} justify-center`}>
|
||||
<LinkIcon size={14} strokeWidth={2.2} />
|
||||
{t('journey.share.createLink')}
|
||||
</button>
|
||||
) : (
|
||||
<>
|
||||
{shareUrl && (
|
||||
<MLinkField
|
||||
url={shareUrl}
|
||||
copied={copied}
|
||||
onCopy={copyShareUrl}
|
||||
copyLabel={t('journey.share.copy')}
|
||||
copiedLabel={t('journey.share.copied')}
|
||||
shareLabel={t('common.share')}
|
||||
/>
|
||||
)}
|
||||
{shareAccess.views > 0 && (
|
||||
<div className="flex items-center gap-1.5 ps-1 font-geist text-caption text-m-muted">
|
||||
<Eye size={12} strokeWidth={2} />
|
||||
<span>{t('journey.share.views', { count: shareAccess.views })}</span>
|
||||
{shareAccess.lastViewed && <span>{t('journey.share.lastViewed', { date: shareAccess.lastViewed })}</span>}
|
||||
</div>
|
||||
)}
|
||||
{([
|
||||
{ key: 'share_timeline' as const, label: t('journey.share.timeline'), icon: List },
|
||||
{ key: 'share_gallery' as const, label: t('journey.share.gallery'), icon: Grid3x3 },
|
||||
{ key: 'share_map' as const, label: t('journey.share.map'), icon: MapPin },
|
||||
]).map(({ key, label, icon: Icon }) => (
|
||||
<ToggleRow
|
||||
key={key}
|
||||
icon={<Icon size={16} strokeWidth={2} />}
|
||||
label={label}
|
||||
checked={shareLink[key]}
|
||||
onChange={() => toggleSharePerm(key)}
|
||||
/>
|
||||
))}
|
||||
<MShareMapExtras link={shareLink} onToggle={toggleSharePerm} />
|
||||
<ToggleRow
|
||||
icon={<MessageCircle size={16} strokeWidth={2} />}
|
||||
label={t('journey.share.allowComments')}
|
||||
hint={shareLink.share_timeline ? t('journey.share.allowCommentsHint') : t('journey.share.needsTimeline')}
|
||||
checked={!!shareLink.share_timeline && !!shareLink.allow_comments}
|
||||
disabled={!shareLink.share_timeline}
|
||||
onChange={() => { void toggleSharePerm('allow_comments') }}
|
||||
/>
|
||||
<ToggleRow
|
||||
icon={<BellPlus size={16} strokeWidth={2} />}
|
||||
label={t('journey.share.allowFollowers')}
|
||||
hint={t('journey.share.allowFollowersHint')}
|
||||
checked={!!shareLink.allow_subscriptions}
|
||||
onChange={() => { void toggleSharePerm('allow_subscriptions') }}
|
||||
/>
|
||||
{shareLink.allow_subscriptions && <MShareFollowers access={shareAccess} />}
|
||||
<MShareAccess access={shareAccess} />
|
||||
<button
|
||||
type="button"
|
||||
onClick={deleteShareLink}
|
||||
className="flex h-[38px] w-full items-center justify-center gap-1.5 rounded-full text-[length:calc(12px*var(--fs-scale-body,1))] font-semibold text-[color:var(--m-st-danger)]"
|
||||
>
|
||||
<Trash2 size={13} strokeWidth={2.2} /> {t('journey.share.removeLink')}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</SheetSection>
|
||||
<MShareSection journeyId={journey.id} />
|
||||
|
||||
<button type="button" onClick={handleArchiveToggle} disabled={archiving} className={`${SHEET_SECONDARY} flex-none`}>
|
||||
{journey.status === 'archived' ? <ArchiveRestore size={14} strokeWidth={2.2} /> : <Archive size={14} strokeWidth={2.2} />}
|
||||
@@ -437,6 +367,83 @@ function MRecordingPrepRow({ prep, enabled }: { prep: JourneyRecordingPrepState;
|
||||
)
|
||||
}
|
||||
|
||||
function MShareSection({ journeyId }: { journeyId: number }) {
|
||||
const { t } = useTranslation()
|
||||
const {
|
||||
link: shareLink, copied, shareUrl, createLink: createShareLink, togglePerm: toggleSharePerm,
|
||||
deleteLink: deleteShareLink, copyLink: copyShareUrl, setProtection,
|
||||
} = useJourneyShareLink(journeyId)
|
||||
const shareAccess = useJourneyShareAccess(journeyId, shareLink, setProtection)
|
||||
return (
|
||||
<SheetSection title={t('journey.share.publicShare')}>
|
||||
{!shareLink ? (
|
||||
<button type="button" onClick={createShareLink} className={`${SHEET_PRIMARY} justify-center`}>
|
||||
<LinkIcon size={14} strokeWidth={2.2} />
|
||||
{t('journey.share.createLink')}
|
||||
</button>
|
||||
) : (
|
||||
<>
|
||||
{shareUrl && (
|
||||
<MLinkField
|
||||
url={shareUrl}
|
||||
copied={copied}
|
||||
onCopy={copyShareUrl}
|
||||
copyLabel={t('journey.share.copy')}
|
||||
copiedLabel={t('journey.share.copied')}
|
||||
shareLabel={t('common.share')}
|
||||
/>
|
||||
)}
|
||||
{shareAccess.views > 0 && (
|
||||
<div className="flex items-center gap-1.5 ps-1 font-geist text-caption text-m-muted">
|
||||
<Eye size={12} strokeWidth={2} />
|
||||
<span>{t('journey.share.views', { count: shareAccess.views })}</span>
|
||||
{shareAccess.lastViewed && <span>{t('journey.share.lastViewed', { date: shareAccess.lastViewed })}</span>}
|
||||
</div>
|
||||
)}
|
||||
{([
|
||||
{ key: 'share_timeline' as const, label: t('journey.share.timeline'), icon: List },
|
||||
{ key: 'share_gallery' as const, label: t('journey.share.gallery'), icon: Grid3x3 },
|
||||
{ key: 'share_map' as const, label: t('journey.share.map'), icon: MapPin },
|
||||
]).map(({ key, label, icon: Icon }) => (
|
||||
<ToggleRow
|
||||
key={key}
|
||||
icon={<Icon size={16} strokeWidth={2} />}
|
||||
label={label}
|
||||
checked={shareLink[key]}
|
||||
onChange={() => toggleSharePerm(key)}
|
||||
/>
|
||||
))}
|
||||
<MShareMapExtras link={shareLink} onToggle={toggleSharePerm} />
|
||||
<ToggleRow
|
||||
icon={<MessageCircle size={16} strokeWidth={2} />}
|
||||
label={t('journey.share.allowComments')}
|
||||
hint={shareLink.share_timeline ? t('journey.share.allowCommentsHint') : t('journey.share.needsTimeline')}
|
||||
checked={!!shareLink.share_timeline && !!shareLink.allow_comments}
|
||||
disabled={!shareLink.share_timeline}
|
||||
onChange={() => { void toggleSharePerm('allow_comments') }}
|
||||
/>
|
||||
<ToggleRow
|
||||
icon={<BellPlus size={16} strokeWidth={2} />}
|
||||
label={t('journey.share.allowFollowers')}
|
||||
hint={t('journey.share.allowFollowersHint')}
|
||||
checked={!!shareLink.allow_subscriptions}
|
||||
onChange={() => { void toggleSharePerm('allow_subscriptions') }}
|
||||
/>
|
||||
{shareLink.allow_subscriptions && <MShareFollowers access={shareAccess} />}
|
||||
<MShareAccess access={shareAccess} />
|
||||
<button
|
||||
type="button"
|
||||
onClick={deleteShareLink}
|
||||
className="flex h-[38px] w-full items-center justify-center gap-1.5 rounded-full text-[length:calc(12px*var(--fs-scale-body,1))] font-semibold text-[color:var(--m-st-danger)]"
|
||||
>
|
||||
<Trash2 size={13} strokeWidth={2.2} /> {t('journey.share.removeLink')}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</SheetSection>
|
||||
)
|
||||
}
|
||||
|
||||
type ShareAccess = ReturnType<typeof useJourneyShareAccess>
|
||||
|
||||
/** The addresses following the link (#1669): two counts, the list behind them. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BellOff, BellRing, CircleAlert, Loader2 } from 'lucide-react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Link } from 'react-router';
|
||||
import { useTranslation } from '../i18n';
|
||||
import { useJourneyFollowPage } from './journeyFollow/useJourneyFollowPage';
|
||||
|
||||
|
||||
@@ -565,7 +565,7 @@ function JourneyPublicContent() {
|
||||
)}
|
||||
|
||||
{social.commentsOpen && (
|
||||
<div className="mt-3 border-t border-zinc-100 pt-3 dark:border-zinc-800">
|
||||
<div className="mt-3 border-t border-edge-faint pt-3">
|
||||
<GuestEntryComments entryId={entry.id} thread={social} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -95,20 +95,13 @@ export function useJourneyDetailLayers({
|
||||
].join('|'),
|
||||
[current?.entries, current?.trips, showTripTracks]
|
||||
);
|
||||
// The kept days and the live trail are read by this screen, not by the layers' read.
|
||||
const recordedRead =
|
||||
recordings.status === 'failed' || dawarichTrail.status === 'unavailable'
|
||||
? 'unavailable'
|
||||
: recordings.status === 'loading' || dawarichTrail.status === 'loading'
|
||||
? 'loading'
|
||||
: 'ready';
|
||||
const mapLayers = useJourneyMapLayers({
|
||||
source: journeyLoaded && current ? { journeyId: current.id } : null,
|
||||
refreshKey: mapRefreshKey,
|
||||
entryIdsOnMap,
|
||||
photoCount,
|
||||
recordedTracks: mapTracks,
|
||||
recordedRead,
|
||||
recordedRead: recordedLayerStatus(recordings.status, dawarichTrail.status),
|
||||
colorOfDay,
|
||||
dateOfEntry,
|
||||
});
|
||||
@@ -154,3 +147,13 @@ export function useJourneyDetailLayers({
|
||||
dayImportDates,
|
||||
};
|
||||
}
|
||||
|
||||
/** A failed route source stays visible as unavailable while the other layers load. */
|
||||
function recordedLayerStatus(
|
||||
recordings: ReturnType<typeof useJourneyDetailRecordings>['recordings']['status'],
|
||||
dawarich: ReturnType<typeof useDawarichJournalTrail>['status']
|
||||
): 'unavailable' | 'loading' | 'ready' {
|
||||
if (recordings === 'failed' || dawarich === 'unavailable') return 'unavailable';
|
||||
if (recordings === 'loading' || dawarich === 'loading') return 'loading';
|
||||
return 'ready';
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useParams, useSearchParams } from 'react-router-dom';
|
||||
import { useParams, useSearchParams } from 'react-router';
|
||||
import { useJourneyFollow } from './useJourneyFollow';
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,8 +47,8 @@ export function JourneyPublicFollow({
|
||||
setError(null);
|
||||
};
|
||||
|
||||
const submit = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
const submit = async (e?: FormEvent) => {
|
||||
e?.preventDefault();
|
||||
if (busy || sent || !email.trim()) return;
|
||||
// Only a bot fills the field people never see: it is told all went well.
|
||||
if (trap) {
|
||||
@@ -68,7 +68,7 @@ export function JourneyPublicFollow({
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(true)}
|
||||
className={`${GLASS} hover:bg-white/25`}
|
||||
className={`${GLASS} hover:opacity-90`}
|
||||
style={fs(12, 'body')}
|
||||
>
|
||||
<BellPlus size={13} strokeWidth={2} aria-hidden />
|
||||
@@ -99,7 +99,7 @@ export function JourneyPublicFollow({
|
||||
{t('common.close')}
|
||||
</DialogButton>
|
||||
) : (
|
||||
<DialogButton variant="primary" type="submit" disabled={busy || !email.trim()}>
|
||||
<DialogButton variant="primary" onClick={() => void submit()} disabled={busy || !email.trim()}>
|
||||
{t('journey.follow.title')}
|
||||
</DialogButton>
|
||||
)}
|
||||
|
||||
@@ -167,7 +167,7 @@ describe('useJourneyPublic', () => {
|
||||
expect(outcome).toBe('ok');
|
||||
expect(sent).toEqual([{ password: 'secret' }]);
|
||||
await waitFor(() => expect(result.current.access).toBe('open'));
|
||||
expect(result.current.timelineEntries).toHaveLength(1);
|
||||
await waitFor(() => expect(result.current.timelineEntries).toHaveLength(1));
|
||||
});
|
||||
|
||||
it('FE-JRN-PUBHOOK-007: a wrong password, too many tries and a dead link each say so', async () => {
|
||||
|
||||
@@ -22,17 +22,7 @@ type PublicJourneyRead = { token: string; revision: number } & (
|
||||
| { status: 'locked' | 'expired' | 'error' }
|
||||
)
|
||||
|
||||
/**
|
||||
* Public-journey (read-only share) data hook — owns the token fetch, the
|
||||
* loading/error state, the view state (timeline/gallery/map, lightbox, language
|
||||
* picker, active + viewing entry) and all the timeline/map derivations.
|
||||
* JourneyPublicPage stays a wiring container: it keeps the presentational
|
||||
* helpers (photoUrl, formatDate, mood/weather config) and the render functions
|
||||
* next to the JSX, and computes the t()-dependent `availableViews` itself.
|
||||
* Behaviour is identical to the previous in-component logic.
|
||||
*/
|
||||
export function useJourneyPublic() {
|
||||
const { token } = useParams()
|
||||
function usePublicJourneyAccess(token: string | undefined) {
|
||||
const [response, setResponse] = useState<PublicJourneyRead | null>(null)
|
||||
const [reloadKey, setReloadKey] = useState(0)
|
||||
// React can keep the page mounted when the visitor follows a different link.
|
||||
@@ -41,23 +31,6 @@ export function useJourneyPublic() {
|
||||
const loading = !!token && !current
|
||||
const error = !token || current?.status === 'error'
|
||||
const access: PublicLinkAccess = current?.status === 'locked' || current?.status === 'expired' ? current.status : 'open'
|
||||
const isMobile = useIsMobile()
|
||||
const [view, setView] = useState<'timeline' | 'gallery' | 'map'>('timeline')
|
||||
const [lightbox, setLightbox] = useState<{ photos: { id: string; src: string; thumbSrc?: string; caption?: string | null; mediaType?: string | null }[]; index: number } | null>(null)
|
||||
const [showLangPicker, setShowLangPicker] = useState(false)
|
||||
const locale = useSettingsStore(s => s.settings.language) || 'en'
|
||||
const mapRef = useRef<JourneyMapHandle>(null)
|
||||
// The desktop feed, for the day picker to scroll (#2998).
|
||||
const feedRef = useRef<HTMLDivElement>(null)
|
||||
const [activeEntryId, setActiveEntryId] = useState<string | null>(null)
|
||||
const [viewingEntry, setViewingEntry] = useState<PublicEntry | null>(null)
|
||||
|
||||
const handleMarkerClick = useCallback((entryId: string) => {
|
||||
setActiveEntryId(entryId)
|
||||
mapRef.current?.highlightMarker(entryId)
|
||||
document.querySelector(`[data-entry-id="${entryId}"]`)
|
||||
?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) return
|
||||
@@ -96,6 +69,39 @@ export function useJourneyPublic() {
|
||||
return 'ok'
|
||||
}, [token, reloadKey])
|
||||
|
||||
return { data, loading, error, access, unlock }
|
||||
}
|
||||
|
||||
/**
|
||||
* Public-journey (read-only share) data hook — owns the token fetch, the
|
||||
* loading/error state, the view state (timeline/gallery/map, lightbox, language
|
||||
* picker, active + viewing entry) and all the timeline/map derivations.
|
||||
* JourneyPublicPage stays a wiring container: it keeps the presentational
|
||||
* helpers (photoUrl, formatDate, mood/weather config) and the render functions
|
||||
* next to the JSX, and computes the t()-dependent `availableViews` itself.
|
||||
* Behaviour is identical to the previous in-component logic.
|
||||
*/
|
||||
export function useJourneyPublic() {
|
||||
const { token } = useParams()
|
||||
const { data, loading, error, access, unlock } = usePublicJourneyAccess(token)
|
||||
const isMobile = useIsMobile()
|
||||
const [view, setView] = useState<'timeline' | 'gallery' | 'map'>('timeline')
|
||||
const [lightbox, setLightbox] = useState<{ photos: { id: string; src: string; thumbSrc?: string; caption?: string | null; mediaType?: string | null }[]; index: number } | null>(null)
|
||||
const [showLangPicker, setShowLangPicker] = useState(false)
|
||||
const locale = useSettingsStore(s => s.settings.language) || 'en'
|
||||
const mapRef = useRef<JourneyMapHandle>(null)
|
||||
// The desktop feed, for the day picker to scroll (#2998).
|
||||
const feedRef = useRef<HTMLDivElement>(null)
|
||||
const [activeEntryId, setActiveEntryId] = useState<string | null>(null)
|
||||
const [viewingEntry, setViewingEntry] = useState<PublicEntry | null>(null)
|
||||
|
||||
const handleMarkerClick = useCallback((entryId: string) => {
|
||||
setActiveEntryId(entryId)
|
||||
mapRef.current?.highlightMarker(entryId)
|
||||
document.querySelector(`[data-entry-id="${entryId}"]`)
|
||||
?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
}, [])
|
||||
|
||||
// #1702, #1669: what a reader may do besides reading, as the owner allows it.
|
||||
const social = useJourneyPublicSocial(token, data?.interaction)
|
||||
|
||||
|
||||
@@ -40,8 +40,18 @@ export function useJourneyPublicSocial(token: string | undefined, interaction: P
|
||||
}, [token, commentsOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
void read();
|
||||
}, [read]);
|
||||
if (!commentsOpen || !token) return;
|
||||
let active = true;
|
||||
void journeySocialRepo.publicComments(token).then(
|
||||
({ comments }) => {
|
||||
if (active) setLoaded({ token, comments });
|
||||
},
|
||||
() => {}
|
||||
);
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [commentsOpen, token]);
|
||||
|
||||
const byEntry = useMemo(() => {
|
||||
const map = new Map<number, JourneyPublicComment[]>();
|
||||
|
||||
@@ -68,7 +68,7 @@ function buildTiff(little: boolean, fields: TiffFields): Uint8Array {
|
||||
return new Uint8Array(buffer);
|
||||
}
|
||||
|
||||
function concat(...parts: Uint8Array[]): Uint8Array {
|
||||
function concat(...parts: Uint8Array[]): Uint8Array<ArrayBuffer> {
|
||||
const out = new Uint8Array(parts.reduce((sum, part) => sum + part.length, 0));
|
||||
let at = 0;
|
||||
for (const part of parts) {
|
||||
|
||||
Reference in New Issue
Block a user