Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

685: Bug Fix: Selected Panels 'Selected' State #688

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/app/FilterProviderWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use client";

import { FilterProvider } from "@/context/FilterContext";

export const FilterProviderWrapper = ({
children,
}: {
children: React.ReactNode;
}) => {
return <FilterProvider>{children}</FilterProvider>
}
2 changes: 0 additions & 2 deletions src/app/find-properties/[[...opa_id]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ const MapPage = ({ params }: MapPageProps) => {
}, [currentView, selectedProperty, shouldFilterSavedProperties]);

return (
<FilterProvider>
<NextUIProvider>
<div className="flex flex-col">
<div className="flex flex-grow overflow-hidden">
Expand Down Expand Up @@ -321,7 +320,6 @@ const MapPage = ({ params }: MapPageProps) => {
</div>
</div>
</NextUIProvider>
</FilterProvider>
);
};

Expand Down
7 changes: 6 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Metadata } from "next";
import "./globals.css";
import { CookieProviderWrapper } from "./CookieProviderWrapper";
import { FilterProviderWrapper } from "./FilterProviderWrapper";

export const metadata: Metadata = {
title: {
Expand Down Expand Up @@ -29,7 +30,11 @@ export default function RootLayout({
>
Skip to main content
</a>
<CookieProviderWrapper>{children}</CookieProviderWrapper>
<CookieProviderWrapper>
<FilterProviderWrapper>
{children}
</FilterProviderWrapper>
</CookieProviderWrapper>
</body>
</html>
);
Expand Down
11 changes: 9 additions & 2 deletions src/components/Filters/DimensionFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ const DimensionFilter: FC<DimensionFilterProps> = ({
const [selectedKeys, setSelectedKeys] = useState<string[]>(
appFilter[property]?.values || []
);
const [selectedPanelKeys, setSelectedPanelkeys] = useState<{[property: string]: string[]}>({})

const initialSelectedPanelKeys = () => {
let panelKeyObj: {[key: string]: string[]} = {}
for (const key in appFilter) {
panelKeyObj[key] = appFilter[key].values
}
return panelKeyObj
}
const [selectedPanelKeys, setSelectedPanelkeys] = useState<{[property: string]: string[]}>(initialSelectedPanelKeys())

const toggleDimensionForPanel = (dimension: string, panel_property: string) => {
let newSelectedPanelKeys
if (selectedPanelKeys[panel_property]) {
Expand Down
22 changes: 15 additions & 7 deletions src/components/SidePanelControlBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ const SearchBarComponent: FC<SidePanelControlBarProps> = ({
const savedRef = useRef<HTMLButtonElement | null>(null);
const { dispatch, appFilter } = useFilter();

let filterCount = Object.keys(appFilter).length;

if (shouldFilterSavedProperties) {
// Exclude opa_id from filterCount, which counts opa_id as a filter by default
filterCount--;
const filterCount = () => {
CodeWritingCow marked this conversation as resolved.
Show resolved Hide resolved
let count = 0
for (let property of Object.keys(appFilter)) {
if (property === "access_process") {
count = count + appFilter[property].values.length
CodeWritingCow marked this conversation as resolved.
Show resolved Hide resolved
} else {
count++
}
}
if (shouldFilterSavedProperties) {
count--
}
return count
}

const onClickSavedButton = () => {
Expand Down Expand Up @@ -107,7 +115,7 @@ const SearchBarComponent: FC<SidePanelControlBarProps> = ({
label={
<div className="lg:space-x-1 body-md">
<span className="max-lg:hidden">Filter</span>
{filterCount !== 0 && <span>({filterCount})</span>}
{filterCount() !== 0 && <span>({filterCount()})</span>}
</div>
}
onPress={() => {
Expand All @@ -117,7 +125,7 @@ const SearchBarComponent: FC<SidePanelControlBarProps> = ({

updateCurrentView("filter");
}}
isSelected={currentView === "filter" || filterCount !== 0}
isSelected={currentView === "filter" || filterCount() !== 0}
startContent={<Funnel />}
className="max-lg:min-w-[4rem]"
data-hover={false}
Expand Down