-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
392 additions
and
23 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
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,92 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withRouter } from 'react-router'; | ||
import Breadcrumbs from '@material-ui/core/Breadcrumbs'; | ||
import Link from '@material-ui/core/Link'; | ||
import { HOME_PATH } from '../../config/paths'; | ||
import { ItemContext } from '../context/item'; | ||
|
||
function handleClick(event) { | ||
event.preventDefault(); | ||
} | ||
|
||
class Navigation extends Component { | ||
static contextType = ItemContext; | ||
|
||
static propTypes = { | ||
history: PropTypes.shape({ | ||
push: PropTypes.func.isRequired, | ||
}).isRequired, | ||
match: PropTypes.shape({ | ||
params: PropTypes.shape({ | ||
itemId: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
state = { | ||
navigation: [], | ||
}; | ||
|
||
async componentDidMount() { | ||
this.updateNavigation(); | ||
} | ||
|
||
async componentDidUpdate({ | ||
match: { | ||
params: { itemId: prevItemId }, | ||
}, | ||
}) { | ||
const { | ||
match: { | ||
params: { itemId }, | ||
}, | ||
} = this.props; | ||
|
||
if (prevItemId !== itemId) { | ||
this.updateNavigation(); | ||
} | ||
} | ||
|
||
updateNavigation = async () => { | ||
const { getNavigation } = this.context; | ||
const { | ||
match: { | ||
params: { itemId }, | ||
}, | ||
} = this.props; | ||
|
||
this.setState({ navigation: await getNavigation(itemId) }); | ||
}; | ||
|
||
goHome = (event) => { | ||
const { | ||
history: { push }, | ||
} = this.props; | ||
event.preventDefault(); | ||
push(HOME_PATH); | ||
}; | ||
|
||
render() { | ||
const { navigation } = this.state; | ||
return ( | ||
<Breadcrumbs aria-label="breadcrumb"> | ||
<Link color="inherit" href="/" onClick={this.goHome}> | ||
Owned Items | ||
</Link> | ||
{navigation.map(({ name, id }) => ( | ||
<Link | ||
key={id} | ||
color="inherit" | ||
href="/getting-started/installation/" | ||
onClick={handleClick} | ||
> | ||
{name} | ||
</Link> | ||
))} | ||
</Breadcrumbs> | ||
); | ||
} | ||
} | ||
|
||
export default withRouter(Navigation); |
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,51 @@ | ||
import React from 'react'; | ||
import Menu from '@material-ui/core/Menu'; | ||
import MenuItem from '@material-ui/core/MenuItem'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import MoreVertIcon from '@material-ui/icons/MoreVert'; | ||
import MoveItemModal from './MoveItemModal'; | ||
|
||
const ItemMenu = () => { | ||
const [anchorEl, setAnchorEl] = React.useState(null); | ||
const [isMoveModalOpen, setIsMoveModalOpen] = React.useState(false); | ||
|
||
const handleClick = (event) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
const handleMove = () => { | ||
setIsMoveModalOpen(true); | ||
handleClose(); | ||
}; | ||
|
||
const onModalClose = () => { | ||
setIsMoveModalOpen(false); | ||
}; | ||
|
||
// todo: only display one modal for the whole page | ||
|
||
return ( | ||
<div> | ||
<IconButton onClick={handleClick}> | ||
<MoreVertIcon /> | ||
</IconButton> | ||
<Menu | ||
id="simple-menu" | ||
anchorEl={anchorEl} | ||
keepMounted | ||
open={Boolean(anchorEl)} | ||
onClose={handleClose} | ||
> | ||
<MenuItem onClick={handleMove}>Move</MenuItem> | ||
<MenuItem onClick={handleClose}>Some action...</MenuItem> | ||
</Menu> | ||
<MoveItemModal onClose={onModalClose} open={isMoveModalOpen} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ItemMenu; |
Oops, something went wrong.