Web/navbar hide#41
Conversation
sherryyx
left a comment
There was a problem hiding this comment.
The transition from the background-fill state to the transparent background state looks rlly good!
After looking at it some more, I think we should just make the background fill 100% opaque. The transparency doesn't really add anything & makes it kind of distracting to read the nav bar. I've updated it in the figma document just now.
Other than that, it looks good to go 💯
Thanks!
…web/navbar-hide
mingyokim
left a comment
There was a problem hiding this comment.
found a bug, will review the rest later
| <nav> | ||
| <div> | ||
| <div>{getLogo()}</div> | ||
| class Navbar extends React.Component { |
There was a problem hiding this comment.
I believe you need to add a componentShouldUpdate lifecycle method to update the state when new props are passed into this component.
Right now the component is not updating based on incoming props. Reproduction steps:
- Make sure you're logged out
- Go to /
- Refresh and it should have logo, links, and login button
- Click "login" button
- The navbar still has logo, links, and login button
- Refresh
- The navbar is updated to just have logo
There was a problem hiding this comment.
Can't repro anymore after f66d3b0 - let me know if it works when you get the chance!
There was a problem hiding this comment.
Yeah I can't reproduce it anymore. But wouldn't it be better to have displayType and buttonType in the state? The only reason why this component re-renders properly is because its container is re-rendering itself. If for some reason the container does not re-render itself, but the props change, then this component wouldn't re-render.
There was a problem hiding this comment.
Hm, I’ll have a closer look at this tonight
There was a problem hiding this comment.
@mingyokim sorry, I'm not sure I understand - doesn't a prop change force the container to re-render? From what I understand, displayType and buttonType are only manipulated from here, and the navbar itself does not change them:
https://github.com/nwhacks/nwhacks2019/blob/master/web/containers/navbar/index.js#L57
It also seems like setting props that a component doesn't manipulate into state is somewhat bad practice (https://stackoverflow.com/a/47341539), but there also seems to be some other APIs for doing this kind of stuff (https://stackoverflow.com/a/49839457, https://stackoverflow.com/a/32414771)... though to be honest this seems to be kind of murky territory, since from what I understand, this type of stuff should just be kept in props (https://stackoverflow.com/a/40330195). I could be missing something though...
There was a problem hiding this comment.
Officially, react only distinguishes between class and function (potentially stateful and stateless respectively), and:
The above two components are equivalent from React’s point of view.
https://reactjs.org/docs/components-and-props.html#functional-and-class-components
There was a problem hiding this comment.
so props do cause a render on stateful components? oops i was mistaken, it's all good then
There was a problem hiding this comment.
Similar question: https://www.reddit.com/r/reactjs/comments/7tn79g/state_and_componentwillreceiveprops/
class Foo extends Component {
state = { value: this.props.value }
// If the props change, update state
componentWillReceiveProps (nextProps) {
if (nextProps.value !== this.props.value) {
this.setState({ value: nextProps.value })
}
}
render () {
// render based on state.value
}
}Top response:
Why you don't render props directly?
There was a problem hiding this comment.
An update can be caused by changes to props or state.
https://reactjs.org/docs/react-component.html
Okay, so clearly change in props cause a re-render, reactjs says so. My bad lol
If this is the case, definitely use props rather than state because the component is not modifying the buttonType or displayType, they're just displaying it.
Approving
There was a problem hiding this comment.
I'll just do one last sanity check
a13c8e1 to
ca0bf1a
Compare
ca0bf1a to
34b6748
Compare
mingyokim
left a comment
There was a problem hiding this comment.
minor comments - looks good!
| @@ -1,43 +1,21 @@ | |||
| nav | |||
| display: flex | |||
| z-index: 500 | |||
There was a problem hiding this comment.
curious, why is this needed?
There was a problem hiding this comment.
This keeps the navbar above all other elements, so long as we avoid using z-index elsewhere
| a:hover | ||
| color: #00D5D5 | ||
| img | ||
| margin-top: 3px |
There was a problem hiding this comment.
spaces should always be multiples of 4 - can you change this to 4px? If the design said 3px that should be an error in design. @sherryyx can you confirm?
There was a problem hiding this comment.
This is a hack because the logo looked slightly off :(
There was a problem hiding this comment.
4px looks fine too though - I'll make this change
| <nav> | ||
| <div> | ||
| <div>{getLogo()}</div> | ||
| class Navbar extends React.Component { |
There was a problem hiding this comment.
Yeah I can't reproduce it anymore. But wouldn't it be better to have displayType and buttonType in the state? The only reason why this component re-renders properly is because its container is re-rendering itself. If for some reason the container does not re-render itself, but the props change, then this component wouldn't re-render.
|
|
||
| // Calculate position | ||
| const offset = window.pageYOffset || document.documentElement.scrollTop; | ||
| const atTop = offset < 96; |
There was a problem hiding this comment.
Can we store 96 into some kind of variable?
There was a problem hiding this comment.
Sure - 96 is in the CSS as navbar height, but I’ll replicate it here
| const atTop = offset < 96; | ||
|
|
||
| // Calculate transparency | ||
| const transparent = offset < 256; |
| const { hidden, transparent } = this.state; | ||
| const { displayType, buttonType } = this.props; | ||
| const button = getButton(buttonType); | ||
| const links = [ |
There was a problem hiding this comment.
cleaann but can we name this something like linksAndButton? it doesn't just have links
|
|
||
| // repeating horizontal elements | ||
| &-horizontal | ||
| &-divs |
mingyokim
left a comment
There was a problem hiding this comment.
Looks good, and thanks for correcting my misunderstanding on component rendering!
Closes #35
👷 Changes
navbarstyles based on Web/flexbox utils, login style rework #39navbarlogic💭 Notes
Targeted at #39 for now for a clearer diff, do not merge! Will point to
masteronce that is in.🔦 Testing Instructions
make webgo to/ui_demoTo Do