-
Notifications
You must be signed in to change notification settings - Fork 5
Core 1060 port separatemap page to ts #2766
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File diffs are in the first commit |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| import React from 'react'; | ||
| import buildContext from '~/components/jsx-helpers/build-context'; | ||
| import Map from './map-api'; | ||
| import createMap from './map-api'; | ||
| import {isMobileDisplay} from '~/helpers/device'; | ||
| import {queryById} from '~/models/query-schools'; | ||
| import {AugmentedInfo, queryById} from '~/models/query-schools'; | ||
| import {assertNotNull} from '~/helpers/data'; | ||
|
|
||
| function useMap(id) { | ||
| function useMap(id: string) { | ||
| const mapZoom = isMobileDisplay() ? 2 : 3; | ||
| const map = React.useMemo( | ||
| () => new Map({ | ||
| () => createMap({ | ||
|
||
| container: id, | ||
| center: [-95.712891, 37.090240], | ||
| zoom: mapZoom, | ||
|
|
@@ -19,9 +20,9 @@ function useMap(id) { | |
| ); | ||
|
|
||
| React.useEffect(() => { | ||
| const container = document.getElementById('mapd'); | ||
| const clickHandler = (event) => { | ||
| const delegateTarget = event.target.closest('.mapboxgl-popup-content .put-away'); | ||
| const container = assertNotNull(document.getElementById('mapd')); | ||
| const clickHandler = (event: MouseEvent) => { | ||
| const delegateTarget = (event.target as Element).closest('.mapboxgl-popup-content .put-away'); | ||
|
|
||
| if (delegateTarget) { | ||
| map.tooltip.remove(); | ||
|
|
@@ -35,30 +36,34 @@ function useMap(id) { | |
| return map; | ||
| } | ||
|
|
||
| function useSelectedSchool(map) { | ||
| const [selectedSchool, setSelectedSchool] = React.useState(); | ||
| type Map = ReturnType<typeof createMap>; | ||
|
|
||
| function useSelectedSchool(map: Map) { | ||
| const [selectedSchool, setSelectedSchool] = React.useState<AugmentedInfo | null>(null); | ||
| const selectSchool = React.useCallback( | ||
| (id) => queryById(id).then( | ||
| (id: string) => queryById(id).then( | ||
| (schoolInfo) => setSelectedSchool(schoolInfo) | ||
| ), | ||
| [] | ||
| ); | ||
|
|
||
| React.useEffect( | ||
| () => map.loaded.then((glMap) => { | ||
| glMap.on( | ||
| 'click', | ||
| 'os-schools', | ||
| (el) => selectSchool(el.features[0].properties.id) | ||
| ); | ||
| }), | ||
| () => { | ||
| map.loaded.then((glMap) => { | ||
| glMap.on( | ||
| 'click', | ||
| 'os-schools', | ||
| (el) => selectSchool(el.features?.[0].properties?.id) | ||
| ); | ||
| }); | ||
| }, | ||
| [map.loaded, selectSchool] | ||
| ); | ||
|
|
||
| return selectedSchool; | ||
| } | ||
|
|
||
| function useContextValue({id}) { | ||
| function useContextValue({id}: {id: string}) { | ||
| const map = useMap(id); | ||
| const selectedSchool = useSelectedSchool(map); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,34 @@ | ||
| import React from 'react'; | ||
| import React, { ChangeEvent } from 'react'; | ||
| import FormSelect from '~/components/form-select/form-select'; | ||
| import type {SetHandle} from '~/helpers/data'; | ||
| import './filters.scss'; | ||
|
|
||
| function InstitutionSelector({setInstitution}) { | ||
| const options = [ | ||
| {label: 'Any', value: '', selected: true}, | ||
| {label: 'College/University', value: 'College/University'}, | ||
| {label: 'Technical/Community College', value: 'Technical/Community College'}, | ||
| {label: 'High School', value: 'High School'} | ||
| ]; | ||
| const onChange = React.useCallback( | ||
| (event) => setInstitution(event.target.value), | ||
| [setInstitution] | ||
| ); | ||
| const options = [ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having this defined inside the function was causing rerenders. This file is shown as changes in the first commit. |
||
| {label: 'Any', value: '', selected: true}, | ||
| {label: 'College/University', value: 'College/University'}, | ||
| {label: 'Technical/Community College', value: 'Technical/Community College'}, | ||
| {label: 'High School', value: 'High School'} | ||
| ]; | ||
|
|
||
| function InstitutionSelector({setInstitution}: {setInstitution: React.Dispatch<React.SetStateAction<string>>}) { | ||
| return ( | ||
| <FormSelect | ||
| name='institution-type' | ||
| selectAttributes={{onChange}} | ||
| label="Type of institution" | ||
| options={options} | ||
| onValueUpdate={setInstitution} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| function ForCheckbox({name, label, selected}) { | ||
| function ForCheckbox({name, label, selected}: { | ||
| name: string; | ||
| label: string; | ||
| selected: SetHandle; | ||
| }) { | ||
| const onChange = React.useCallback( | ||
| (event) => { | ||
| const {checked} = event.target; | ||
| (event: ChangeEvent) => { | ||
| const {checked} = event.target as HTMLInputElement; | ||
|
|
||
| if (checked) { | ||
| selected.add(name); | ||
|
|
@@ -46,7 +47,10 @@ function ForCheckbox({name, label, selected}) { | |
| ); | ||
| } | ||
|
|
||
| export default function Filters({selected, setInstitution}) { | ||
| export default function Filters({selected, setInstitution}: { | ||
| selected: SetHandle; | ||
| setInstitution: React.Dispatch<React.SetStateAction<string>>; | ||
| }) { | ||
| return ( | ||
| <div className="filters"> | ||
| <div className="institution-region"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,10 @@ | |
| } | ||
|
|
||
| .search-clear { | ||
| cursor: pointer; | ||
| appearance: none; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it from a clickable icon with role="button" to a button element. |
||
| border: 0; | ||
| box-shadow: none; | ||
| padding: 0; | ||
|
|
||
| &[hidden] { | ||
| display: none; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing was using flyThere