Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

remove selection when clicking on currently selected coord

Bill Yang932539b2b56a
diff --git a/client/src/app/[site]/components/Sidebar/Sidebar.tsx b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
index 66d6bacee..1a6c30a3f 100644
--- a/client/src/app/[site]/components/Sidebar/Sidebar.tsx
+++ b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
@@ -7,6 +7,7 @@ import {
Funnel,
Gauge,
Globe,
+ Globe2,
LayoutDashboard,
Map,
MousePointerClick,
@@ -59,23 +60,23 @@ function SidebarContent() {
href={getTabPath("main")}
icon={<LayoutDashboard className="w-4 h-4" />}
/>
- <SidebarComponents.Item
+ {/* <SidebarComponents.Item
label="Realtime"
active={isActiveTab("realtime")}
href={getTabPath("realtime")}
icon={<Earth className="w-4 h-4" />}
- />
- <SidebarComponents.Item
+ /> */}
+ {/* <SidebarComponents.Item
label="Map"
active={isActiveTab("map")}
href={getTabPath("map")}
icon={<Map className="w-4 h-4" />}
- />
+ /> */}
<SidebarComponents.Item
label="Globe"
active={isActiveTab("globe")}
href={getTabPath("globe")}
- icon={<Globe className="w-4 h-4" />}
+ icon={<Globe2 className="w-4 h-4" />}
/>
{IS_CLOUD && (
<SidebarComponents.Item
diff --git a/client/src/app/[site]/globe/hooks/useCoordinatesLayer.ts b/client/src/app/[site]/globe/hooks/useCoordinatesLayer.ts
index ebe68f647..e19905e65 100644
--- a/client/src/app/[site]/globe/hooks/useCoordinatesLayer.ts
+++ b/client/src/app/[site]/globe/hooks/useCoordinatesLayer.ts
@@ -3,7 +3,7 @@ import mapboxgl from "mapbox-gl";
import { scaleSequentialSqrt } from "d3-scale";
import { interpolateYlOrRd } from "d3-scale-chromatic";
import { LiveSessionLocation } from "../../../../api/analytics/useGetSessionLocations";
-import { addFilter, useStore } from "../../../../lib/store";
+import { addFilter, removeFilter, useStore } from "../../../../lib/store";
import { FilterParameter } from "@rybbit/shared/dist/filters";
import { round } from "lodash";
@@ -183,6 +183,7 @@ export function useCoordinatesLayer({
const feature = e.features[0];
const city = feature.properties?.city || "Unknown";
const count = feature.properties?.count || 0;
+ const isCurrentlyFiltered = feature.properties?.isFiltered;
// Use the stored lat/lon properties instead of geometry coordinates
// to avoid Mapbox coordinate transformations at different zoom levels
@@ -191,17 +192,28 @@ export function useCoordinatesLayer({
if (lat === undefined || lon === undefined) return;
- addFilter({
- parameter: "lat" as FilterParameter,
- value: [lat],
- type: "equals",
- });
-
- addFilter({
- parameter: "lon" as FilterParameter,
- value: [lon],
- type: "equals",
- });
+ // If this location is already filtered, remove the filters
+ if (isCurrentlyFiltered) {
+ const { filters } = useStore.getState();
+ const latFilter = filters.find(f => f.parameter === "lat");
+ const lonFilter = filters.find(f => f.parameter === "lon");
+
+ if (latFilter) removeFilter(latFilter);
+ if (lonFilter) removeFilter(lonFilter);
+ } else {
+ // Otherwise, add the filters
+ addFilter({
+ parameter: "lat" as FilterParameter,
+ value: [lat],
+ type: "equals",
+ });
+
+ addFilter({
+ parameter: "lon" as FilterParameter,
+ value: [lon],
+ type: "equals",
+ });
+ }
});
}