-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
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.
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
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.
found a bug, will review the rest later
web/components/navbar/index.js
Outdated
<nav> | ||
<div> | ||
<div>{getLogo()}</div> | ||
class Navbar extends React.Component { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't repro anymore after f66d3b0 - let me know if it works when you get the chance!
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I’ll have a closer look at this tonight
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just do one last sanity check
a13c8e1
to
ca0bf1a
Compare
ca0bf1a
to
34b6748
Compare
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.
minor comments - looks good!
@@ -1,43 +1,21 @@ | |||
nav | |||
display: flex | |||
z-index: 500 |
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.
curious, why is this needed?
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.
This keeps the navbar above all other elements, so long as we avoid using z-index elsewhere
web/components/navbar/Navbar.sass
Outdated
img | ||
margin-top: 3px |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a hack because the logo looked slightly off :(
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.
4px looks fine too though - I'll make this change
web/components/navbar/index.js
Outdated
<nav> | ||
<div> | ||
<div>{getLogo()}</div> | ||
class Navbar extends React.Component { |
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 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.
web/components/navbar/index.js
Outdated
|
||
// Calculate position | ||
const offset = window.pageYOffset || document.documentElement.scrollTop; | ||
const atTop = offset < 96; |
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.
Can we store 96
into some kind of variable?
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.
Sure - 96 is in the CSS as navbar height, but I’ll replicate it here
web/components/navbar/index.js
Outdated
const atTop = offset < 96; | ||
|
||
// Calculate transparency | ||
const transparent = offset < 256; |
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.
same here
web/components/navbar/index.js
Outdated
const { hidden, transparent } = this.state; | ||
const { displayType, buttonType } = this.props; | ||
const button = getButton(buttonType); | ||
const links = [ |
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.
cleaann but can we name this something like linksAndButton
? it doesn't just have links
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.
True!
|
||
// repeating horizontal elements | ||
&-horizontal | ||
&-divs |
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.
nice
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.
Looks good, and thanks for correcting my misunderstanding on component rendering!
Closes #35
👷 Changes
navbar
styles based on Web/flexbox utils, login style rework #39navbar
logic💭 Notes
Targeted at #39 for now for a clearer diff, do not merge! Will point to
master
once that is in.🔦 Testing Instructions
make web
go to/ui_demo
To Do