MCPcopy Create free account
hub / github.com/Thanas-R/Virdis / SidePanel

Function SidePanel

src/components/SidePanel.tsx:24–193  ·  view source on GitHub ↗
({
  allFields,
  selectedFields,
  activeField,
  detailField,
  onFieldClick,
  onFieldDoubleClick,
  onBackFromDetail,
  onUpdateField,
  onDeleteField,
  onEditBoundary,
}: SidePanelProps)

Source from the content-addressed store, hash-verified

22}
23
24const SidePanel = ({
25 allFields,
26 selectedFields,
27 activeField,
28 detailField,
29 onFieldClick,
30 onFieldDoubleClick,
31 onBackFromDetail,
32 onUpdateField,
33 onDeleteField,
34 onEditBoundary,
35}: SidePanelProps) => {
36 const isMobile = useIsMobile();
37 const [search, setSearch] = useState("");
38 const [sortBy, setSortBy] = useState<"name" | "area" | "ndvi">("name");
39 const [filterCrop, setFilterCrop] = useState<string | null>(null);
40 const [showFilterMenu, setShowFilterMenu] = useState(false);
41 const [editingField, setEditingField] = useState<Field | null>(null);
42
43 if (detailField) {
44 return (
45 <div className={`${isMobile ? "w-full" : "w-[320px]"} h-full bg-card/95 backdrop-blur-md border-l border-border flex flex-col animate-fade-in`}>
46 <FieldDetailView
47 field={detailField}
48 onBack={onBackFromDetail}
49 onEditBoundary={onEditBoundary ? () => onEditBoundary(detailField) : undefined}
50 />
51 </div>
52 );
53 }
54
55 const crops = Array.from(new Set(allFields.map(f => f.crop)));
56
57 const filtered = allFields
58 .filter(f =>
59 (f.name.toLowerCase().includes(search.toLowerCase()) ||
60 f.crop.toLowerCase().includes(search.toLowerCase())) &&
61 (!filterCrop || f.crop === filterCrop)
62 )
63 .sort((a, b) => {
64 if (sortBy === "area") return b.area - a.area;
65 if (sortBy === "ndvi") return (b.ndviChange ?? 0) - (a.ndviChange ?? 0);
66 return a.name.localeCompare(b.name);
67 });
68
69 const sortLabel = sortBy === "name" ? "Name" : sortBy === "area" ? "Area" : "NDVI";
70
71 return (
72 <div className="w-[320px] h-full bg-card/95 backdrop-blur-md border-l border-border flex flex-col">
73 <div className="flex items-center justify-between p-4 border-b border-border">
74 <h2 className="text-lg font-semibold text-foreground">Region List</h2>
75 </div>
76
77 <div className="px-3 pt-3">
78 <div className="relative">
79 <input
80 type="text"
81 placeholder="Search regions..."

Callers

nothing calls this directly

Calls 1

useIsMobileFunction · 0.90

Tested by

no test coverage detected