Skip to content

Commit 3685817

Browse files
committed
frontend map handling
1 parent 51a10a5 commit 3685817

File tree

1 file changed

+62
-8
lines changed

1 file changed

+62
-8
lines changed

src/pages/organizations/[id]/index.js

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ import {
77
removeManager,
88
addOwner,
99
removeOwner,
10-
getOrgTeams,
10+
getOrgLocations,
1111
getOrgStaff,
1212
} from '../../../lib/org-api'
1313
import { getUserOrgProfile } from '../../../lib/profiles-api'
14-
import { Box, Container, Heading, Button, Flex } from '@chakra-ui/react'
14+
import {
15+
Box,
16+
Checkbox,
17+
Container,
18+
Heading,
19+
Button,
20+
Flex,
21+
} from '@chakra-ui/react'
1522
import Table from '../../../components/tables/table'
1623
import { AddMemberByIdForm } from '../../../components/add-member-form'
1724
import ProfileModal from '../../../components/profile-modal'
@@ -66,6 +73,8 @@ class Organization extends Component {
6673
profileInfo: [],
6774
profileUserId: '',
6875
teams: [],
76+
searchOnMapMove: false,
77+
mapBounds: undefined,
6978
managers: [],
7079
owners: [],
7180
page: 0,
@@ -82,7 +91,7 @@ class Organization extends Component {
8291
await this.getOrg()
8392
await this.getOrgStaff()
8493
await this.getBadges()
85-
await this.getOrgTeams()
94+
await this.getOrgLocations()
8695
}
8796

8897
async openProfileModal(user) {
@@ -165,10 +174,10 @@ class Organization extends Component {
165174
}
166175
}
167176

168-
async getOrgTeams() {
177+
async getOrgLocations() {
169178
const { id } = this.props
170179
try {
171-
let teams = await getOrgTeams(id)
180+
let teams = await getOrgLocations(id)
172181
this.setState({
173182
teams,
174183
})
@@ -258,6 +267,28 @@ class Organization extends Component {
258267
) : null
259268
}
260269

270+
/**
271+
* Bounds is a WESN box, refresh teams
272+
*/
273+
onMapBoundsChange(bounds) {
274+
if (this.state.searchOnMapMove) {
275+
this.setState({
276+
mapBounds: bounds,
277+
})
278+
} else {
279+
this.setState({ mapBounds: null })
280+
}
281+
}
282+
283+
setSearchOnMapMove(e) {
284+
this.setState(
285+
{
286+
searchOnMapMove: e.target.checked,
287+
},
288+
() => this.getOrgLocations()
289+
)
290+
}
291+
261292
renderMap(teams) {
262293
const { data } = teams
263294

@@ -282,13 +313,14 @@ class Organization extends Component {
282313
zIndex: '10',
283314
marginBottom: '1rem',
284315
}}
285-
onBoundsChange={() => {}}
316+
onBoundsChange={this.onMapBoundsChange.bind(this)}
286317
/>
287318
)
288319
}
289320

290321
render() {
291-
const { org, managers, owners, error, teams } = this.state
322+
const { org, managers, owners, error, teams, searchOnMapMove, mapBounds } =
323+
this.state
292324
const userId = parseInt(this.state?.session?.user_id)
293325

294326
// Handle org loading errors
@@ -367,7 +399,29 @@ class Organization extends Component {
367399
<Box layerStyle={'shadowed'} as='section'>
368400
<Heading variant='sectionHead'>Teams</Heading>
369401
{this.renderMap(teams)}
370-
<TeamsTable type='org-teams' orgId={org.data.id} />
402+
<Checkbox
403+
border={'2px'}
404+
marginTop={'-4rem'}
405+
marginLeft={'1rem'}
406+
position='absolute'
407+
zIndex='2000'
408+
borderColor='brand.600'
409+
p={2}
410+
bg='white'
411+
name='map-bounds-filter'
412+
id='map-bounds-filter'
413+
type='checkbox'
414+
colorScheme={'brand'}
415+
isChecked={searchOnMapMove}
416+
onChange={(e) => this.setSearchOnMapMove(e)}
417+
>
418+
Filter teams by map
419+
</Checkbox>
420+
<TeamsTable
421+
type='org-teams'
422+
orgId={org.data.id}
423+
bbox={searchOnMapMove ? mapBounds : null}
424+
/>
371425
</Box>
372426

373427
{isStaff ? (

0 commit comments

Comments
 (0)