feat(feed): pick the feed's view from its own toolbar
The view mode moves out of Settings into a switcher next to sort, on the feed and channel pages alike. It leaves the Settings prefs draft for its own eager save: a toolbar click must not mark that page dirty and trip its leave-page guard. lib/feedView.ts owns the vocabulary and maps the old grid/list prefs forward on read, so nobody's saved choice is lost.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
// The feed's view vocabulary. Lifted out of Feed (like feedSort.ts) because it has three
|
||||
// consumers that can't share module-private state: App owns the pref, the toolbar's
|
||||
// ViewSwitcher offers it, and VirtualFeed/VideoCard render it.
|
||||
export type FeedView = "cards" | "rows";
|
||||
|
||||
export const FEED_VIEWS: readonly FeedView[] = ["cards", "rows"] as const;
|
||||
export const FEED_VIEW_DEFAULT: FeedView = "cards";
|
||||
|
||||
export function isFeedView(v: unknown): v is FeedView {
|
||||
return typeof v === "string" && (FEED_VIEWS as readonly string[]).includes(v);
|
||||
}
|
||||
|
||||
/** Coerce a stored pref to a view. Up to 0.44 it was "grid" | "list"; those map forward here so
|
||||
* nobody's saved choice is lost. Anything else (a corrupt value, a future view rolled back) falls
|
||||
* back to the default rather than rendering nothing. */
|
||||
export function parseFeedView(raw: unknown): FeedView {
|
||||
if (isFeedView(raw)) return raw;
|
||||
if (raw === "grid") return "cards";
|
||||
if (raw === "list") return "rows";
|
||||
return FEED_VIEW_DEFAULT;
|
||||
}
|
||||
Reference in New Issue
Block a user