Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/hooks/usePinnedSectionOpen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useCallback, useState } from 'react';

export const PINNED_SECTION_OPEN_KEY = 'roastmap:pinnedRoastersOpen';

/**
* Whether the visitor has explicitly opened or closed the pinned-roasters
* group on the directory. Tri-state: true / false / null (never chosen).
* The page decides the default from the pin count; this only remembers an
* explicit choice, in localStorage so it sticks across visits. Storage
* failures (Safari private mode, blocked site data) degrade to session-only.
*/
export function usePinnedSectionOpen() {
const [pref, setPref] = useState(() => {
try {
const v = localStorage.getItem(PINNED_SECTION_OPEN_KEY);
return v === '1' ? true : v === '0' ? false : null;
} catch {
return null;
}
});

const set = useCallback((open) => {
setPref(open);
try {
localStorage.setItem(PINNED_SECTION_OPEN_KEY, open ? '1' : '0');
} catch {
// localStorage unavailable — the choice lasts for this session only.
}
}, []);

return [pref, set];
}
Loading
Loading