"use client" /** * "Home layout" block for the profile menu — switches between `/home/` * links (`use-home-variant`). * * Lives in the profile menu rather than on the page itself for the same reason * theme does: it is a standing preference about a surface, not an action on the * content in front of you, and putting a layout control in the page's own * header would spend the most valuable row on the page on a setting most people * set once. * * Choosing a layout navigates to that layout's URL and remembers it so bare * `/home` (post-login, All products) still lands on the last one you used. * * Campus carries a second preference — greeting-only vs full cover banner — * in a nested submenu (`use-campus-banner-mode`). Spotlight carries v1 vs v2 * in a nested submenu (`SPOTLIGHT_VARIANTS`). * * Rendered in both profile menus — the utility bar's avatar (the one that is * actually visible on `/home`, since the shell strips the sidebar there) and * the sidebar's `NavUser`, so someone who changes their mind from inside a * product does not have to go back to home to find the control. */ import { useLocation, useNavigate } from "react-router" import { DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, } from "@/components/ui/dropdown-menu" import { CAMPUS_BANNER_MODES, setCampusBannerMode, useCampusBannerMode, type CampusBannerMode, } from "@/hooks/use-campus-banner-mode" import { CAMPUS_VARIANTS, HOME_VARIANTS, SPOTLIGHT_VARIANTS, STOREFRONT_VARIANTS, homeVariantFromPathname, homeVariantPath, setHomeVariant, useHomeVariant, type HomeVariant, } from "@/hooks/use-home-variant" const FLAT_VARIANTS = HOME_VARIANTS.filter( option => option.id !== "campus" && option.id !== "spotlight" && option.id !== "storefront", ) const CAMPUS_VARIANT = HOME_VARIANTS.find(option => option.id === "campus")! const SPOTLIGHT_VARIANT = HOME_VARIANTS.find(option => option.id === "spotlight")! const STOREFRONT_VARIANT = HOME_VARIANTS.find(option => option.id === "storefront")! function isCampusVariant(variant: HomeVariant): variant is "campus" | "campus-v3" { return variant === "campus" || variant === "campus-v3" } function isSpotlightVariant( variant: HomeVariant, ): variant is "spotlight" | "spotlight-v2" | "spotlight-v3" | "spotlight-v4" { return ( variant === "spotlight" || variant === "spotlight-v2" || variant === "spotlight-v3" || variant === "spotlight-v4" ) } function isStorefrontVariant( variant: HomeVariant, ): variant is "storefront" | "storefront-v2" { return variant === "storefront" || variant === "storefront-v2" } export function HomeLayoutMenu() { const navigate = useNavigate() const { pathname } = useLocation() const preferred = useHomeVariant() const variant = homeVariantFromPathname(pathname) ?? preferred const campusBannerMode = useCampusBannerMode() const active = HOME_VARIANTS.find(option => option.id === variant) const activeCampusBanner = CAMPUS_BANNER_MODES.find(option => option.id === campusBannerMode) const activeCampusLayout = CAMPUS_VARIANTS.find(option => option.id === variant) const activeSpotlight = SPOTLIGHT_VARIANTS.find(option => option.id === variant) const activeStorefront = STOREFRONT_VARIANTS.find(option => option.id === variant) const selectCampusLayout = (next: "campus" | "campus-v3" = "campus") => { setHomeVariant(next) navigate(homeVariantPath(next)) } const selectSpotlightLayout = ( next: "spotlight" | "spotlight-v2" | "spotlight-v3" | "spotlight-v4" = "spotlight", ) => { setHomeVariant(next) navigate(homeVariantPath(next)) } const selectStorefrontLayout = ( next: "storefront" | "storefront-v2" = "storefront", ) => { setHomeVariant(next) navigate(homeVariantPath(next)) } const trailingLabel = isCampusVariant(variant) && activeCampusBanner && activeCampusLayout ? `${activeCampusLayout.label} · ${activeCampusBanner.label}` : isSpotlightVariant(variant) && activeSpotlight ? activeSpotlight.label : isStorefrontVariant(variant) && activeStorefront ? activeStorefront.label : active?.label return (