mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
feat(tours): let a background check hint at changes of your own wanderer trails
Settings, Integrations, wanderer gains an optional background check of the trails you imported, off until you switch it on. While on, TREK reads the short record of each such trail at most once a day (never its GPX file) and leaves a hint when the trail may have moved on: "may have changed" when only wanderer's change time moved, "changed" when its name or description proves it, and "not checkable" when the trail is gone, no longer yours or carries no change time. Nothing is ever said to be unchanged. A new hint arrives as a notification that opens the tour (a new ?place= link in the planner); the tour's provenance shows it with the source check right beside it, and the card lists all open hints in a dialog, each leading to its tour. The check reads the source in full as before and spends the hint; taking a change in stays the confirmed reimport. No tour is ever changed or deleted. The check only asks through your own connection, only about trails your account imported into trips you can still open, and stops when you switch it off, remove the connection, wanderer refuses the token (until a test passes or a new token is saved) or the admin switches wanderer off; hints and snapshots stay. A run asks at most 25 connections for at most 10 records each, one after another, and an instance that fails (an outage, a rate limit) is left alone for an hour, doubling up to two days. Server: migration 046120 adds the switch and the run bookkeeping to wanderer_connections and the tour_source_hints table (one row per snapshot, for its importer, gone with it). WandererWatchService and an hourly wanderer-watch job on the CronRegistrar live in the tours domain and read through WandererService; GET and PUT /api/integrations/wanderer/watch and GET /api/trips/:tripId/tours/wanderer/sources/:placeId/hint (place_edit, like the check) answer with @trek/shared contracts. A new user notification event, wanderer_source_hint, can be muted per channel. Saving a new token now clears what the last check said about the old one. There is no MCP tool, as for the rest of the personal wanderer connection. All 27 locales carry the strings, and the admin wiki page says what the check does.
This commit is contained in:
@@ -16,11 +16,14 @@ import {
|
||||
} from './settingsKit';
|
||||
import ToggleSwitch from './ToggleSwitch';
|
||||
import { useWandererConnection } from './useWandererConnection';
|
||||
import WandererWatchRow from './WandererWatchRow';
|
||||
|
||||
/**
|
||||
* Settings → Integrations → wanderer: the reader's own trail database, from
|
||||
* which the Tours workspace imports trails. Laid out like the Dawarich and
|
||||
* AirTrail cards beside it; the behaviour is in `useWandererConnection`.
|
||||
* Under the form, the optional background check of the imported trails
|
||||
* (WAN-02), which switches on its own and needs no save.
|
||||
*/
|
||||
export default function WandererConnectionSection(): React.ReactElement {
|
||||
const { t } = useTranslation();
|
||||
@@ -136,6 +139,8 @@ export default function WandererConnectionSection(): React.ReactElement {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<WandererWatchRow connected={S.connected} />
|
||||
</Section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import type { WandererSourceHintItem, WandererWatch } from '@trek/shared';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { render, screen, waitFor, within } from '../../../tests/helpers/render';
|
||||
import WandererWatchRow from './WandererWatchRow';
|
||||
|
||||
const repo = vi.hoisted(() => ({ getWatch: vi.fn(), setWatch: vi.fn() }));
|
||||
const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() }));
|
||||
const navigate = vi.hoisted(() => vi.fn());
|
||||
vi.mock('../../repo/wandererRepo', () => ({ wandererRepo: repo }));
|
||||
vi.mock('../shared/Toast', () => ({ useToast: () => toast }));
|
||||
vi.mock('react-router', async () => ({
|
||||
...(await vi.importActual<typeof import('react-router')>('react-router')),
|
||||
useNavigate: () => navigate,
|
||||
}));
|
||||
|
||||
const off: WandererWatch = {
|
||||
enabled: false,
|
||||
connected: true,
|
||||
lastRunAt: null,
|
||||
pausedUntil: null,
|
||||
blocked: false,
|
||||
hints: [],
|
||||
};
|
||||
const hints: WandererSourceHintItem[] = [
|
||||
{
|
||||
placeId: 7,
|
||||
tripId: 3,
|
||||
tripTitle: 'Alps',
|
||||
tourName: 'Ridge',
|
||||
state: 'changed',
|
||||
changes: ['name'],
|
||||
reason: null,
|
||||
externalUpdated: '2026-10-14',
|
||||
checkedAt: '2026-10-20T10:00:00Z',
|
||||
},
|
||||
{
|
||||
placeId: 8,
|
||||
tripId: 3,
|
||||
tripTitle: 'Alps',
|
||||
tourName: 'Gorge',
|
||||
state: 'unverifiable',
|
||||
changes: [],
|
||||
reason: 'unavailable',
|
||||
externalUpdated: null,
|
||||
checkedAt: '2026-10-19T10:00:00Z',
|
||||
},
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('WandererWatchRow (WAN-02)', () => {
|
||||
it('is off by default and dimmed, not hidden, without a connection', async () => {
|
||||
repo.getWatch.mockResolvedValue({ ...off, connected: false });
|
||||
render(<WandererWatchRow connected={false} />);
|
||||
await waitFor(() => expect(repo.getWatch).toHaveBeenCalled());
|
||||
const toggle = await screen.findByRole('button', { name: 'Check my trails for changes', pressed: false });
|
||||
expect(toggle).toHaveAttribute('aria-pressed', 'false');
|
||||
expect(toggle.closest('[aria-disabled="true"]')).not.toBeNull();
|
||||
expect(screen.queryByTestId('wanderer-watch-status')).toBeNull();
|
||||
});
|
||||
|
||||
it('switches on at once and then says when it last looked', async () => {
|
||||
repo.getWatch.mockResolvedValue(off);
|
||||
repo.setWatch.mockResolvedValue({ ...off, enabled: true });
|
||||
render(<WandererWatchRow connected />);
|
||||
const toggle = await screen.findByRole('button', { name: 'Check my trails for changes', pressed: false });
|
||||
await waitFor(() => expect(toggle.closest('[aria-disabled="true"]')).toBeNull());
|
||||
await userEvent.click(toggle);
|
||||
expect(repo.setWatch).toHaveBeenCalledWith(true);
|
||||
expect(await screen.findByText('Not looked yet')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /Hints/ })).toBeDisabled();
|
||||
});
|
||||
|
||||
it('counts the open hints on the button and opens each tour from the dialog', async () => {
|
||||
repo.getWatch.mockResolvedValue({ ...off, enabled: true, lastRunAt: '2026-10-20T10:00:00Z', hints });
|
||||
render(<WandererWatchRow connected />);
|
||||
expect(await screen.findByTestId('wanderer-hint-count')).toHaveTextContent('2');
|
||||
await userEvent.click(screen.getByRole('button', { name: /Hints/ }));
|
||||
|
||||
const dialog = await screen.findByRole('dialog');
|
||||
expect(within(dialog).getByText('Hints on your trails')).toBeInTheDocument();
|
||||
expect(within(dialog).getByText('2 open hints')).toBeInTheDocument();
|
||||
const ridge = within(dialog).getByTestId('wanderer-hint-7');
|
||||
expect(within(ridge).getByText('Changed')).toBeInTheDocument();
|
||||
expect(within(ridge).getByText('Name')).toBeInTheDocument();
|
||||
expect(within(within(dialog).getByTestId('wanderer-hint-8')).getByText('Trail out of reach')).toBeInTheDocument();
|
||||
|
||||
await userEvent.click(ridge);
|
||||
expect(navigate).toHaveBeenCalledWith('/trips/3?tab=plan&place=7');
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
||||
});
|
||||
|
||||
it('names a refused token instead of a last look', async () => {
|
||||
repo.getWatch.mockResolvedValue({ ...off, enabled: true, blocked: true });
|
||||
render(<WandererWatchRow connected />);
|
||||
expect(await screen.findByText('Token refused')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,97 @@
|
||||
import { BellRing } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { useTranslation } from '../../i18n';
|
||||
import { fs } from '../shared/DialogShell';
|
||||
import { Tooltip } from '../shared/Tooltip';
|
||||
import { InfoDot } from '../Tours/tourParts';
|
||||
import WandererHintsDialog from '../Tours/wanderer/WandererHintsDialog';
|
||||
import { SETTINGS_BUTTON, SettingRow, SettingRows, StatusPill } from './settingsKit';
|
||||
import ToggleSwitch from './ToggleSwitch';
|
||||
import { useWandererWatch, type WandererWatchController } from './useWandererWatch';
|
||||
|
||||
/** The switch, dimmed with a word on why while there is no connection to watch with. */
|
||||
function WatchSwitch({ W }: { W: WandererWatchController }) {
|
||||
const { t } = useTranslation();
|
||||
const toggle = (
|
||||
<ToggleSwitch on={W.enabled} onToggle={() => void W.toggle()} label={t('wanderer.watch.label')} />
|
||||
);
|
||||
if (W.available) return toggle;
|
||||
return (
|
||||
<Tooltip label={t('wanderer.watch.notConnected')}>
|
||||
<span className="inline-flex opacity-50" aria-disabled="true">
|
||||
<span className="pointer-events-none inline-flex">{toggle}</span>
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
/** The open hints behind a button, their number as a badge on its corner; dimmed while there are none. */
|
||||
function HintsButton({ W }: { W: WandererWatchController }) {
|
||||
const { t } = useTranslation();
|
||||
const count = W.hints.length;
|
||||
return (
|
||||
<Tooltip label={count ? t('wanderer.watch.hintsCount', { count }) : t('wanderer.watch.empty')}>
|
||||
<span className="inline-flex">
|
||||
<button
|
||||
type="button"
|
||||
onClick={W.openHints}
|
||||
disabled={count === 0}
|
||||
className={`${SETTINGS_BUTTON} relative`}
|
||||
style={fs(12.5, 'body')}
|
||||
>
|
||||
<BellRing size={13} strokeWidth={2.2} />
|
||||
{t('wanderer.watch.hints')}
|
||||
{count > 0 && (
|
||||
<span
|
||||
aria-label={t('wanderer.watch.hintsCount', { count })}
|
||||
data-testid="wanderer-hint-count"
|
||||
className="absolute -end-1.5 -top-1.5 grid h-[18px] min-w-[18px] place-items-center rounded-full bg-accent px-1 font-geist font-semibold tabular-nums text-accent-text ring-2 ring-[color:var(--bg-card)]"
|
||||
style={fs(10)}
|
||||
>
|
||||
{count}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* WAN-02 in the wanderer card: the optional background check of the user's
|
||||
* own imported trails. Off until switched on; while on, what it last did and
|
||||
* its open hints, which open in a dialog that leads to each tour.
|
||||
*/
|
||||
export default function WandererWatchRow({ connected }: { connected: boolean }): React.ReactElement {
|
||||
const { t } = useTranslation();
|
||||
const W = useWandererWatch(connected);
|
||||
return (
|
||||
<SettingRows>
|
||||
<SettingRow
|
||||
label={
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
{t('wanderer.watch.label')}
|
||||
<InfoDot label={t('wanderer.watch.label')} description={t('wanderer.watch.info')} />
|
||||
</span>
|
||||
}
|
||||
hint={t('wanderer.watch.hint')}
|
||||
dimmed={W.saving}
|
||||
control={<WatchSwitch W={W} />}
|
||||
>
|
||||
{W.status && (
|
||||
<div className="flex flex-wrap items-center gap-2" data-testid="wanderer-watch-status">
|
||||
<Tooltip label={W.status.why ?? ''} disabled={!W.status.why}>
|
||||
<span className="inline-flex">
|
||||
<StatusPill tone={W.status.tone}>{W.status.text}</StatusPill>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<span className="ms-auto">
|
||||
<HintsButton W={W} />
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</SettingRow>
|
||||
<WandererHintsDialog open={W.hintsOpen} hints={W.hints} onClose={W.closeHints} onOpenTour={W.openTour} />
|
||||
</SettingRows>
|
||||
);
|
||||
}
|
||||
@@ -27,6 +27,7 @@ export const EVENT_LABEL_KEYS: Record<string, string> = {
|
||||
photos_shared: 'settings.notifyPhotosShared',
|
||||
collab_message: 'settings.notifyCollabMessage',
|
||||
packing_tagged: 'settings.notifyPackingTagged',
|
||||
wanderer_source_hint: 'settings.notifyWandererSourceHint',
|
||||
version_available: 'settings.notifyVersionAvailable',
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
import { act, renderHook, waitFor } from '@testing-library/react';
|
||||
import type { WandererSourceHintItem, WandererWatch } from '@trek/shared';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { useWandererWatch, watchStatusOf } from './useWandererWatch';
|
||||
|
||||
const repo = vi.hoisted(() => ({ getWatch: vi.fn(), setWatch: vi.fn() }));
|
||||
const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() }));
|
||||
const navigate = vi.hoisted(() => vi.fn());
|
||||
vi.mock('../../repo/wandererRepo', () => ({ wandererRepo: repo }));
|
||||
vi.mock('../shared/Toast', () => ({ useToast: () => toast }));
|
||||
vi.mock('../../i18n', () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, params?: Record<string, unknown>) => (params ? `${key} ${JSON.stringify(params)}` : key),
|
||||
locale: 'en',
|
||||
}),
|
||||
}));
|
||||
vi.mock('react-router', async () => ({
|
||||
...(await vi.importActual<typeof import('react-router')>('react-router')),
|
||||
useNavigate: () => navigate,
|
||||
}));
|
||||
|
||||
const t = (key: string) => key;
|
||||
const off: WandererWatch = {
|
||||
enabled: false,
|
||||
connected: true,
|
||||
lastRunAt: null,
|
||||
pausedUntil: null,
|
||||
blocked: false,
|
||||
hints: [],
|
||||
};
|
||||
const hint: WandererSourceHintItem = {
|
||||
placeId: 7,
|
||||
tripId: 3,
|
||||
tripTitle: 'Alps',
|
||||
tourName: 'Ridge',
|
||||
state: 'possible_change',
|
||||
changes: [],
|
||||
reason: null,
|
||||
externalUpdated: '2026-10-14',
|
||||
checkedAt: '2026-10-20T10:00:00Z',
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
repo.getWatch.mockResolvedValue(off);
|
||||
repo.setWatch.mockImplementation(async (enabled: boolean) => ({ ...off, enabled }));
|
||||
});
|
||||
|
||||
describe('watchStatusOf (WAN-02)', () => {
|
||||
const now = Date.parse('2026-10-20T12:00:00Z');
|
||||
|
||||
it('says nothing while the watch is off', () => {
|
||||
expect(watchStatusOf(null, t, 'en', now)).toBeNull();
|
||||
expect(watchStatusOf(off, t, 'en', now)).toBeNull();
|
||||
});
|
||||
|
||||
it('names a refused token first, then a pause still running, then the last look', () => {
|
||||
const on = { ...off, enabled: true };
|
||||
expect(watchStatusOf({ ...on, blocked: true, pausedUntil: '2026-10-21T00:00:00Z' }, t, 'en', now)).toEqual({
|
||||
tone: 'danger',
|
||||
text: 'wanderer.watch.blocked',
|
||||
why: 'wanderer.watch.blockedHint',
|
||||
});
|
||||
expect(watchStatusOf({ ...on, pausedUntil: '2026-10-20T14:00:00Z' }, t, 'en', now)).toMatchObject({
|
||||
tone: 'warning',
|
||||
text: 'wanderer.watch.paused',
|
||||
why: 'wanderer.watch.pausedHint',
|
||||
});
|
||||
expect(
|
||||
watchStatusOf({ ...on, pausedUntil: '2026-10-20T11:00:00Z', lastRunAt: '2026-10-20T10:00:00Z' }, t, 'en', now)
|
||||
).toEqual({ tone: 'neutral', text: 'wanderer.watch.lastRun', why: null });
|
||||
expect(watchStatusOf(on, t, 'en', now)).toEqual({ tone: 'neutral', text: 'wanderer.watch.neverRun', why: null });
|
||||
});
|
||||
});
|
||||
|
||||
describe('useWandererWatch (WAN-02)', () => {
|
||||
it('loads with the card and again when the connection comes or goes', async () => {
|
||||
const { result, rerender } = renderHook(({ connected }) => useWandererWatch(connected), {
|
||||
initialProps: { connected: true },
|
||||
});
|
||||
await waitFor(() => expect(result.current.available).toBe(true));
|
||||
expect(result.current.enabled).toBe(false);
|
||||
expect(result.current.status).toBeNull();
|
||||
rerender({ connected: false });
|
||||
await waitFor(() => expect(repo.getWatch).toHaveBeenCalledTimes(2));
|
||||
});
|
||||
|
||||
it('switches at once, and says so either way', async () => {
|
||||
const { result } = renderHook(() => useWandererWatch(true));
|
||||
await waitFor(() => expect(result.current.available).toBe(true));
|
||||
await act(async () => {
|
||||
await result.current.toggle();
|
||||
});
|
||||
expect(repo.setWatch).toHaveBeenCalledWith(true);
|
||||
expect(result.current.enabled).toBe(true);
|
||||
expect(toast.success).toHaveBeenCalledWith('wanderer.watch.on');
|
||||
|
||||
repo.setWatch.mockRejectedValueOnce(new Error('down'));
|
||||
await act(async () => {
|
||||
await result.current.toggle();
|
||||
});
|
||||
expect(toast.error).toHaveBeenCalledWith('wanderer.watch.failed');
|
||||
expect(result.current.enabled).toBe(true);
|
||||
});
|
||||
|
||||
it('leaves the switch alone without a connection, or when the watch could not be read', async () => {
|
||||
repo.getWatch.mockResolvedValueOnce({ ...off, connected: false });
|
||||
const { result } = renderHook(() => useWandererWatch(false));
|
||||
await waitFor(() => expect(repo.getWatch).toHaveBeenCalled());
|
||||
await act(async () => {
|
||||
await result.current.toggle();
|
||||
});
|
||||
expect(repo.setWatch).not.toHaveBeenCalled();
|
||||
|
||||
repo.getWatch.mockRejectedValueOnce(new Error('offline'));
|
||||
const failed = renderHook(() => useWandererWatch(true));
|
||||
await waitFor(() => expect(repo.getWatch).toHaveBeenCalledTimes(2));
|
||||
expect(failed.result.current.available).toBe(false);
|
||||
});
|
||||
|
||||
it('lists the hints and opens the tour one is about', async () => {
|
||||
repo.getWatch.mockResolvedValue({ ...off, enabled: true, hints: [hint] });
|
||||
const { result } = renderHook(() => useWandererWatch(true));
|
||||
await waitFor(() => expect(result.current.hints).toEqual([hint]));
|
||||
act(() => result.current.openHints());
|
||||
expect(result.current.hintsOpen).toBe(true);
|
||||
act(() => result.current.openTour(hint));
|
||||
expect(navigate).toHaveBeenCalledWith('/trips/3?tab=plan&place=7');
|
||||
expect(result.current.hintsOpen).toBe(false);
|
||||
act(() => result.current.openHints());
|
||||
act(() => result.current.closeHints());
|
||||
expect(result.current.hintsOpen).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
import type { WandererSourceHintItem, WandererWatch } from '@trek/shared';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { useTranslation } from '../../i18n';
|
||||
import { wandererRepo } from '../../repo/wandererRepo';
|
||||
import { useToast } from '../shared/Toast';
|
||||
import { hintWhen } from '../Tours/wanderer/sourceHintParts';
|
||||
|
||||
type Translate = (key: string, params?: Record<string, unknown>) => string;
|
||||
|
||||
/** What the watch last did, as one pill: refused, waiting after errors, last looked, or not yet. */
|
||||
interface WandererWatchStatus {
|
||||
tone: 'neutral' | 'warning' | 'danger';
|
||||
text: string;
|
||||
/** Why, for the tooltip; null where the text says it all. */
|
||||
why: string | null;
|
||||
}
|
||||
|
||||
/** The pill for a switched-on watch; null while it is off, since then nothing runs to report on. */
|
||||
export function watchStatusOf(
|
||||
watch: WandererWatch | null,
|
||||
t: Translate,
|
||||
locale: string,
|
||||
now = Date.now()
|
||||
): WandererWatchStatus | null {
|
||||
if (!watch?.enabled) return null;
|
||||
if (watch.blocked) return { tone: 'danger', text: t('wanderer.watch.blocked'), why: t('wanderer.watch.blockedHint') };
|
||||
const pausedUntil = watch.pausedUntil ? new Date(watch.pausedUntil).getTime() : Number.NaN;
|
||||
if (pausedUntil > now) {
|
||||
return {
|
||||
tone: 'warning',
|
||||
text: t('wanderer.watch.paused', { time: hintWhen(watch.pausedUntil, locale) }),
|
||||
why: t('wanderer.watch.pausedHint'),
|
||||
};
|
||||
}
|
||||
const lastRun = hintWhen(watch.lastRunAt, locale);
|
||||
return {
|
||||
tone: 'neutral',
|
||||
text: lastRun ? t('wanderer.watch.lastRun', { date: lastRun }) : t('wanderer.watch.neverRun'),
|
||||
why: null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* WAN-02: the background watch in the wanderer card. It loads with the card
|
||||
* and again whenever the connection comes or goes, switches on and off at
|
||||
* once (there is nothing to save with the form), and opens the tour a hint is
|
||||
* about. Online-only like the rest of the connection: the watch runs on the
|
||||
* server and its hints are read from there.
|
||||
*/
|
||||
export function useWandererWatch(connected: boolean) {
|
||||
const { t, locale } = useTranslation();
|
||||
const toast = useToast();
|
||||
const navigate = useNavigate();
|
||||
const [watch, setWatch] = useState<WandererWatch | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [hintsOpen, setHintsOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
wandererRepo.getWatch().then(
|
||||
(next) => {
|
||||
if (!cancelled) setWatch(next);
|
||||
},
|
||||
() => {
|
||||
// The card above already says when the connection cannot be read; without
|
||||
// an answer the switch simply stays dimmed.
|
||||
if (!cancelled) setWatch(null);
|
||||
}
|
||||
);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [connected]);
|
||||
|
||||
const toggle = useCallback(async () => {
|
||||
if (!watch?.connected || saving) return;
|
||||
setSaving(true);
|
||||
try {
|
||||
const next = await wandererRepo.setWatch(!watch.enabled);
|
||||
setWatch(next);
|
||||
toast.success(next.enabled ? t('wanderer.watch.on') : t('wanderer.watch.off'));
|
||||
} catch {
|
||||
toast.error(t('wanderer.watch.failed'));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}, [saving, t, toast, watch]);
|
||||
|
||||
const openTour = useCallback(
|
||||
(hint: WandererSourceHintItem) => {
|
||||
setHintsOpen(false);
|
||||
navigate(`/trips/${hint.tripId}?tab=plan&place=${hint.placeId}`);
|
||||
},
|
||||
[navigate]
|
||||
);
|
||||
|
||||
return {
|
||||
/** The switch can act: the server knows a connection to watch with. */
|
||||
available: !!watch?.connected,
|
||||
enabled: !!watch?.enabled,
|
||||
saving,
|
||||
status: watchStatusOf(watch, t, locale),
|
||||
hints: watch?.hints ?? [],
|
||||
hintsOpen,
|
||||
openHints: useCallback(() => setHintsOpen(true), []),
|
||||
closeHints: useCallback(() => setHintsOpen(false), []),
|
||||
openTour,
|
||||
toggle,
|
||||
};
|
||||
}
|
||||
|
||||
export type WandererWatchController = ReturnType<typeof useWandererWatch>;
|
||||
Reference in New Issue
Block a user