forked from BinaryStudioAcademy/bsa-2023-towhub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
th-216: Truck filters functionality (BinaryStudioAcademy#380)
* th-216: * moves the interval in a separate function * th-216: * updates getAllOpenedWithTrucks method to return only active trucks * th-216: * updated towTruckCard and adds helpers * th-216: * adds the ability to add truck markers and user location to the hook * th-216: * adds libraries and methods for autocomplete and zoom control * th-216: + hooks and helpers for homepage * th-216: + map component for homepage * th-216: + autocomplete component * th-216: + adds functionality to the filter * th-216: + adds the ability to control the display of dropdown value * th-216: + adds filters to homepage * th-216: * updates map component * th-216: * updates createIcon helper * th-216: * updates types for choosenTruck * th-216: + adds possibility to set location from navigator * th-216: + custom autocomplete * th-216: + autocomplete component * th-216: * updates truck filter * th-216: * updates homepage * th-216: * updates imports * th-216: * moves setZoom to a separate useEffect * th-216: - removed @react-google-maps/api package * th-216: - removes unused types * th-216: * updates type name --------- Co-authored-by: Alina Kupchyk <[email protected]>
- Loading branch information
1 parent
4e85f4f
commit 217e07f
Showing
48 changed files
with
595 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
frontend/src/libs/components/autocomplete/autocomplete.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { type FieldValues } from 'react-hook-form/dist/types'; | ||
|
||
import { getValidClassNames } from '~/libs/helpers/helpers.js'; | ||
import { useCallback, useEffect, useRef } from '~/libs/hooks/hooks.js'; | ||
import { type MapService } from '~/libs/packages/map/map.js'; | ||
import { MapConnector } from '~/libs/packages/map/map-connector.package.js'; | ||
import { type LocationChangeHandler } from '~/libs/types/types.js'; | ||
|
||
type Properties = { | ||
placeholder?: string; | ||
field?: FieldValues; | ||
isDisabled?: boolean; | ||
inputStyles?: string | string[]; | ||
onPlaceChanged: LocationChangeHandler; | ||
}; | ||
|
||
const PLACE_CHANGED_EVENT = 'place_changed'; | ||
|
||
const Autocomplete = ({ | ||
placeholder, | ||
field, | ||
isDisabled = false, | ||
inputStyles = [], | ||
onPlaceChanged, | ||
}: Properties): JSX.Element => { | ||
const inputReference = useRef<HTMLInputElement>(null); | ||
const mapService = useRef<MapService | null>(null); | ||
const autocomplete = useRef<google.maps.places.Autocomplete | null>(null); | ||
|
||
const onPlaceChange = useCallback(() => { | ||
const place = autocomplete.current?.getPlace(); | ||
|
||
if (place?.geometry?.location) { | ||
onPlaceChanged( | ||
{ | ||
lat: place.geometry.location.lat(), | ||
lng: place.geometry.location.lng(), | ||
}, | ||
place.formatted_address as string, | ||
); | ||
} | ||
}, [onPlaceChanged]); | ||
|
||
useEffect(() => { | ||
const getMapService = async (): Promise<void> => { | ||
if (inputReference.current) { | ||
await MapConnector.getInstance(); | ||
|
||
mapService.current = new MapConnector().getMapService({ | ||
mapElement: null, | ||
}); | ||
|
||
autocomplete.current = mapService.current.createAutocomplete( | ||
inputReference.current, | ||
); | ||
|
||
autocomplete.current.addListener(PLACE_CHANGED_EVENT, onPlaceChange); | ||
} | ||
}; | ||
void getMapService(); | ||
}, [onPlaceChange]); | ||
|
||
return ( | ||
<input | ||
{...field} | ||
type="text" | ||
placeholder={placeholder} | ||
className={getValidClassNames(inputStyles)} | ||
disabled={isDisabled} | ||
ref={inputReference} | ||
/> | ||
); | ||
}; | ||
|
||
export { Autocomplete }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
frontend/src/libs/components/tow-truck-card/libs/constants/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const METERS_IN_KILOMETER = 1000; | ||
const DECIMAL_POINTS = 1; | ||
|
||
export { DECIMAL_POINTS, METERS_IN_KILOMETER }; |
7 changes: 7 additions & 0 deletions
7
...src/libs/components/tow-truck-card/libs/helpers/format-distance-into-kilometers.helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { DECIMAL_POINTS, METERS_IN_KILOMETER } from '../constants/constants.js'; | ||
|
||
const formatDistanceIntoKilometers = (distance: number): string => { | ||
return (distance / METERS_IN_KILOMETER).toFixed(DECIMAL_POINTS); | ||
}; | ||
|
||
export { formatDistanceIntoKilometers }; |
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
frontend/src/libs/components/tow-truck-card/libs/helpers/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { formatDistanceIntoKilometers } from './format-distance-into-kilometers.helper.js'; | ||
export { getTowTruckImage } from './get-tow-truck-image.helper.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
frontend/src/libs/components/truck-filter/libs/enums/enums.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { FilterOption } from './filter-option.enum.js'; | ||
export { FilterValue } from './filter-value.enum.js'; |
6 changes: 6 additions & 0 deletions
6
frontend/src/libs/components/truck-filter/libs/enums/filter-option.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const FilterOption = { | ||
LOW_TO_HIGH: 'Low to High', | ||
HIGH_TO_LOW: 'High to Low', | ||
} as const; | ||
|
||
export { FilterOption }; |
6 changes: 6 additions & 0 deletions
6
frontend/src/libs/components/truck-filter/libs/enums/filter-value.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const FilterValue = { | ||
ASC: 'asc', | ||
DESC: 'desc', | ||
} as const; | ||
|
||
export { FilterValue }; |
1 change: 1 addition & 0 deletions
1
frontend/src/libs/components/truck-filter/libs/fields/fields.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Fields } from './filter-fields.js'; |
Oops, something went wrong.