-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add navigation bar and logout #109
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { | ||
Button, | ||
Flex, | ||
SimpleGrid, | ||
Heading, | ||
Icon, | ||
IconButton, | ||
Select, | ||
Spacer, | ||
Text, | ||
} from '@chakra-ui/react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useLocation, useNavigate } from 'react-router-dom'; | ||
import { ArrowLeftIcon, CogIcon, LogoutIcon } from '@heroicons/react/outline'; | ||
import apiClient from '../api/client'; | ||
import { API_URLS, NAVBAR_HEIGHT } from '../constants'; | ||
import { logout, setSelectedUtility } from '../store/authSlice'; | ||
|
||
const NAVBAR_VARIANTS = { | ||
DRAW: 'draw', | ||
SUBMISSION: 'submission', | ||
}; | ||
|
||
export default function NavBar() { | ||
const location = useLocation(); | ||
|
||
let variant = NAVBAR_VARIANTS.SUBMISSION; | ||
if (location.pathname.startsWith('/draw')) { | ||
variant = NAVBAR_VARIANTS.DRAW; | ||
} | ||
|
||
return ( | ||
<SimpleGrid | ||
columns={3} | ||
paddingLeft={10} | ||
paddingRight={10} | ||
w='100%' | ||
h={NAVBAR_HEIGHT} | ||
bg='gray.700' | ||
> | ||
<Flex align='center'> | ||
<UtilityControl variant={variant} /> | ||
</Flex> | ||
|
||
<Flex align='center' justify='center'> | ||
<Heading size='md' color='white' ml={6}> | ||
Boundary Sync | ||
</Heading> | ||
</Flex> | ||
|
||
<Flex align='center' gap={4}> | ||
<Spacer /> | ||
<SettingsButton variant={variant} /> | ||
<ExitButton variant={variant} /> | ||
</Flex> | ||
</SimpleGrid> | ||
); | ||
} | ||
|
||
function SettingsButton({ variant }) { | ||
const navigate = useNavigate(); | ||
|
||
return variant === NAVBAR_VARIANTS.SUBMISSION ? ( | ||
<IconButton | ||
icon={<Icon as={CogIcon} />} | ||
aria-label='Settings' | ||
onClick={() => { | ||
navigate('/settings'); | ||
}} | ||
/> | ||
) : null; | ||
} | ||
|
||
function ExitButton({ variant }) { | ||
const navigate = useNavigate(); | ||
const dispatch = useDispatch(); | ||
|
||
return variant === NAVBAR_VARIANTS.SUBMISSION ? ( | ||
<Button | ||
onClick={() => { | ||
apiClient.post(API_URLS.LOGOUT, {}).then(() => { | ||
dispatch(logout()); | ||
navigate('/login'); | ||
}); | ||
}} | ||
rightIcon={<Icon as={LogoutIcon} />} | ||
> | ||
Log out | ||
</Button> | ||
) : ( | ||
<Button | ||
onClick={() => { | ||
navigate('/submissions'); | ||
}} | ||
rightIcon={<Icon as={ArrowLeftIcon} />} | ||
> | ||
Save and back | ||
</Button> | ||
); | ||
} | ||
|
||
function UtilityControl({ variant }) { | ||
const dispatch = useDispatch(); | ||
|
||
// placeholders | ||
const utilities = ['Raleigh City of', 'Azavea Test Utility']; | ||
const selectedUtility = | ||
useSelector(state => state.auth.selectedUtility) || utilities[0]; | ||
|
||
return variant === NAVBAR_VARIANTS.SUBMISSION && utilities.length > 1 ? ( | ||
<Select | ||
variant='filled' | ||
h='40px' | ||
w='250px' | ||
value={selectedUtility} | ||
onChange={e => { | ||
dispatch(setSelectedUtility(e.target.value)); | ||
}} | ||
_focus={{ background: 'white' }} | ||
> | ||
{utilities.map(u => { | ||
return ( | ||
<option key={u} value={u}> | ||
{u} | ||
</option> | ||
); | ||
})} | ||
</Select> | ||
) : ( | ||
<Text textStyle='selectedUtility'>{selectedUtility}</Text> | ||
); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🆒
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.
Yeah, I found that this was the way to suppress warnings about "are you sure you want to render nothing".