mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 07:26:30 +00:00
9cd227fd81
The planner's cards fold to their head: waypoints, the paddle time estimate, the wind and the checklist on the left, the open tour's summary on the right. The title or the chevron folds a card, and the choice is kept in this browser, so a reload finds the rails as they were left. A folded card still says what matters in its head: the checklist what is open, the wind its day, and the time estimate now its total as a badge, in the warning tone while parts of it are unknown. The "planning values" badge and info dot of the estimate go; what the starting values are is said once under its figures. The obstacle entry dialog sits outside the checklist's body, so an obstacle picked on the map still opens with the card folded. The trip totals start folded to their counts and show each type's sums as the row's white badges, each named in its tooltip, an incomplete one marked as at least that much with how many tours it is known for. The info text is shorter. The Tours locale contract counts the 574 general keys the planned cards brought in.
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { useCallback, useState } from 'react';
|
|
|
|
/**
|
|
* Whether a card of the tours rails is folded, kept per browser so a reload
|
|
* finds the rail as it was left. A view convenience, nothing shared: a blocked
|
|
* or cleared storage gives every card its default again.
|
|
*/
|
|
const keyOf = (id: string) => `trek.tours.fold.${id}`;
|
|
|
|
/** The stored choice, else the card's own default. */
|
|
function readFolded(id: string, byDefault = false): boolean {
|
|
try {
|
|
const stored = localStorage.getItem(keyOf(id));
|
|
return stored === null ? byDefault : stored === '1';
|
|
} catch {
|
|
return byDefault;
|
|
}
|
|
}
|
|
|
|
function storeFolded(id: string, folded: boolean): void {
|
|
try {
|
|
localStorage.setItem(keyOf(id), folded ? '1' : '0');
|
|
} catch {
|
|
// Private mode or blocked storage: the card takes its default again next time.
|
|
}
|
|
}
|
|
|
|
/** A card's folded state under `id`, remembered in this browser; `byDefault` until the user chose. */
|
|
export function useRailFold(id: string, byDefault = false) {
|
|
const [folded, setFolded] = useState(() => readFolded(id, byDefault));
|
|
const toggle = useCallback(() => {
|
|
setFolded((value) => {
|
|
storeFolded(id, !value);
|
|
return !value;
|
|
});
|
|
}, [id]);
|
|
return { folded, toggle };
|
|
}
|