From f1189d252fe175449b0b7c6acb168d80fe9f0696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Mon, 30 Oct 2023 13:31:19 +0100 Subject: [PATCH] Add direct mode and transit mode selects --- .../src/components/SearchBar/AccessSelect.tsx | 1 + .../components/SearchBar/DirectModeSelect.tsx | 54 +++++++++++++++ .../src/components/SearchBar/EgressSelect.tsx | 1 + .../SearchBar/MultiSelectDropdown.tsx | 65 +++++++++++++++++++ .../src/components/SearchBar/SearchBar.tsx | 4 ++ .../SearchBar/TransitModeSelect.tsx | 60 +++++++++++++++++ 6 files changed, 185 insertions(+) create mode 100644 client-next/src/components/SearchBar/DirectModeSelect.tsx create mode 100644 client-next/src/components/SearchBar/MultiSelectDropdown.tsx create mode 100644 client-next/src/components/SearchBar/TransitModeSelect.tsx diff --git a/client-next/src/components/SearchBar/AccessSelect.tsx b/client-next/src/components/SearchBar/AccessSelect.tsx index c5904f54957..a2b3e174bd5 100644 --- a/client-next/src/components/SearchBar/AccessSelect.tsx +++ b/client-next/src/components/SearchBar/AccessSelect.tsx @@ -14,6 +14,7 @@ export function AccessSelect({ Access { if (e.target.value !== 'not_selected') { diff --git a/client-next/src/components/SearchBar/DirectModeSelect.tsx b/client-next/src/components/SearchBar/DirectModeSelect.tsx new file mode 100644 index 00000000000..459cb2e4d47 --- /dev/null +++ b/client-next/src/components/SearchBar/DirectModeSelect.tsx @@ -0,0 +1,54 @@ +import { Form } from 'react-bootstrap'; +import { StreetMode, TripQueryVariables } from '../../gql/graphql.ts'; + +export function DirectModeSelect({ + tripQueryVariables, + setTripQueryVariables, +}: { + tripQueryVariables: TripQueryVariables; + setTripQueryVariables: (tripQueryVariables: TripQueryVariables) => void; +}) { + return ( + + + Direct mode + + { + if (e.target.value !== 'not_selected') { + setTripQueryVariables({ + ...tripQueryVariables, + modes: { + ...tripQueryVariables.modes, + directMode: e.target.value as StreetMode, + }, + }); + } else { + setTripQueryVariables({ + ...tripQueryVariables, + modes: + tripQueryVariables.modes?.accessMode || + tripQueryVariables.modes?.egressMode || + tripQueryVariables.modes?.transportModes + ? { + ...tripQueryVariables.modes, + directMode: undefined, + } + : undefined, + }); + } + }} + value={tripQueryVariables.modes?.directMode || 'not_selected'} + > + + {Object.values(StreetMode).map((mode) => ( + + ))} + + + ); +} diff --git a/client-next/src/components/SearchBar/EgressSelect.tsx b/client-next/src/components/SearchBar/EgressSelect.tsx index ab575a1b322..214e5030a66 100644 --- a/client-next/src/components/SearchBar/EgressSelect.tsx +++ b/client-next/src/components/SearchBar/EgressSelect.tsx @@ -14,6 +14,7 @@ export function EgressSelect({ Egress { if (e.target.value !== 'not_selected') { diff --git a/client-next/src/components/SearchBar/MultiSelectDropdown.tsx b/client-next/src/components/SearchBar/MultiSelectDropdown.tsx new file mode 100644 index 00000000000..dd70c579765 --- /dev/null +++ b/client-next/src/components/SearchBar/MultiSelectDropdown.tsx @@ -0,0 +1,65 @@ +import { ChangeEvent, useState } from 'react'; +import { Form } from 'react-bootstrap'; + +type MultiSelectDropdownOption = { + id: T; + label: string; +}; + +type MultiSelectDropdownProps = { + label: string; + options: MultiSelectDropdownOption[]; + values: T[]; + onChange: (value: T[]) => void; +}; + +const MultiSelectDropdown = ({ label, options, values, onChange }: MultiSelectDropdownProps) => { + const [isOpen, setIsOpen] = useState(false); + + const toggleDropdown = () => { + setIsOpen(!isOpen); + }; + + const handleOptionChange = (event: ChangeEvent) => { + const optionId = event.target.value as T; + const isChecked = event.target.checked; + + if (isChecked) { + onChange([...values, optionId]); + } else { + onChange(values.filter((id) => id !== optionId)); + } + }; + + return ( +
+ + {label} + + {}} + /> +
+ {options.map((option) => ( + + ))} +
+
+ ); +}; + +export default MultiSelectDropdown; diff --git a/client-next/src/components/SearchBar/SearchBar.tsx b/client-next/src/components/SearchBar/SearchBar.tsx index 1382a448dcb..3ac07e83b9e 100644 --- a/client-next/src/components/SearchBar/SearchBar.tsx +++ b/client-next/src/components/SearchBar/SearchBar.tsx @@ -7,6 +7,8 @@ import { DateInputField } from './DateInputField.tsx'; import { SearchWindowInput } from './SearchWindowInput.tsx'; import { AccessSelect } from './AccessSelect.tsx'; import { EgressSelect } from './EgressSelect.tsx'; +import { DirectModeSelect } from './DirectModeSelect.tsx'; +import { TransitModeSelect } from './TransitModeSelect.tsx'; export function SearchBar({ onRoute, @@ -27,7 +29,9 @@ export function SearchBar({ + +