🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Refactor SiteSelector component to streamline site selection logic
Bill Yangb45322aa38ed
diff --git a/client/src/app/[site]/components/Sidebar/SiteSelector.tsx b/client/src/app/[site]/components/Sidebar/SiteSelector.tsxindex e05d8d621..8df34432b 100644--- a/client/src/app/[site]/components/Sidebar/SiteSelector.tsx+++ b/client/src/app/[site]/components/Sidebar/SiteSelector.tsx@@ -6,7 +6,7 @@ import { Favicon } from "../../../../components/Favicon";import { Button } from "../../../../components/ui/button";import { Popover, PopoverContent, PopoverTrigger } from "../../../../components/ui/popover";import { authClient } from "../../../../lib/auth";-import { resetStore, useStore } from "../../../../lib/store";+import { useStore } from "../../../../lib/store";import { userStore } from "../../../../lib/userStore";import { cn, formatter } from "../../../../lib/utils";import { AddSite } from "../../../components/AddSite";@@ -18,8 +18,6 @@ function SiteSelectorContent({ onSiteSelect }: { onSiteSelect: () => void }) {const { data: sites } = useGetSitesFromOrg(activeOrganization?.id);const embed = useEmbedablePage();- const { setSite } = useStore();-const pathname = usePathname();const router = useRouter();const currentSiteId = Number(pathname.split("/")[1]);@@ -51,12 +49,11 @@ function SiteSelectorContent({ onSiteSelect }: { onSiteSelect: () => void }) {onSiteSelect(); // Close popover even if same sitereturn;}- resetStore();- setSite(site.siteId.toString());const pathSegments = pathname.split("/");pathSegments[1] = site.siteId.toString();const newPath = pathSegments.join("/");const queryString = window.location.search;+ // Let the layout's useEffect sync the site from the new pathnamerouter.push(queryString ? `${newPath}${queryString}` : newPath);onSiteSelect(); // Close popover immediately}}@@ -95,12 +92,11 @@ function SiteSelectorContent({ onSiteSelect }: { onSiteSelect: () => void }) {onSiteSelect(); // Close popover even if same sitereturn;}- resetStore();- setSite(site.siteId.toString());const pathSegments = pathname.split("/");pathSegments[1] = site.siteId.toString();const newPath = pathSegments.join("/");const queryString = window.location.search;+ // Let the layout's useEffect sync the site from the new pathnamerouter.push(queryString ? `${newPath}${queryString}` : newPath);onSiteSelect(); // Close popover immediately}}