Skip to content
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

Creating the countdown in the header #53

Merged
merged 6 commits into from
Mar 5, 2018
Merged

Conversation

Scoombe
Copy link
Contributor

@Scoombe Scoombe commented Feb 27, 2018

I have had a go at addressing issue #26. I need some pointers on the style of the change, also this is my first time looking at react so any help there would be nice.

@bebraw
Copy link
Collaborator

bebraw commented Feb 27, 2018

Deploy preview for react-finland processing.

Built with commit f5bf913

https://app.netlify.com/sites/react-finland/deploys/5a9955e6fd0efa40570f3a64

@bebraw
Copy link
Collaborator

bebraw commented Feb 27, 2018

That's a great start!

Check pages/for-attendees.js on how to wrap the component to an Interactive container. After that the counter works also in the production version. This is a small limitation of the static site generator and I might fix this later. But for now we have to wrap it.

@manpenaloza @okonet Can you provide some guidance on the visual outlook? Preview here.

@bebraw
Copy link
Collaborator

bebraw commented Feb 27, 2018

Inspiration: https://dribbble.com/tags/countdown_timer . Something along https://dribbble.com/shots/3825256-Daily-UI-challenge-014-Countdown-timer would look cool perhaps. I would do it horizontal like that but with tuned style.

@manpenaloza
Copy link
Contributor

nice one!

Horizontal look could be a good choice, wireframed sth for further implementation. what do you think?
react-finl-countdown

@bebraw
Copy link
Collaborator

bebraw commented Feb 27, 2018

@manpenaloza That looks great to me! We can use the font we already have. The layout is just 👍 .

@Scoombe
Copy link
Contributor Author

Scoombe commented Feb 27, 2018

@manpenaloza Looks good! @bebraw What steps should be taken now?

@bebraw
Copy link
Collaborator

bebraw commented Feb 27, 2018

@Scoombe Would you be comfortable porting to the proposed layout? You can also try Interactive. Let me know if you get stuck and I can manage the rest. 👍

@Scoombe
Copy link
Contributor Author

Scoombe commented Feb 27, 2018

@bebraw I would be, what's the best way to do this? Inline css in the react component or adding to the existing css files? I might not get time to do this until Friday if that's ok.

@bebraw
Copy link
Collaborator

bebraw commented Feb 27, 2018

@Scoombe No rush. Maybe separate CSS like for now. I might integrate a css-in-js solution (Emotion) later.

@@ -0,0 +1,39 @@
var React = require("react");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use Import here?

super(props);
this.tick = this.tick.bind(this);
this.state = { date: props.initialDate, now: Date.now() };
this.TimeDiff = this.timeDiff();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these 2 be renamed into something more destinguishable and readable. Also, please don’t use CamelCase for instance variables.

}
tick() {
this.setState({ now: Date.now() });
this.TimeDiff = this.timeDiff();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it needs to be stored in the instance variable BTW? It looks like a state since you’re rendering those values.

@@ -4,7 +4,7 @@ import Link from "./Link";
import Navigation from "./Navigation";
import logo from "assets/img/logo.svg";
import navigationPages from "./navigation-pages";

import Countdown from "./Countdown";
const Header = ({ pathname, title }) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new line is missing afaik

return (
<div>
<p>
{this.TimeDiff.days} Days&#160;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing deriving values is an anti-pattern. You could just call the timediff in the render method instead.

@okonet
Copy link

okonet commented Feb 27, 2018

Can we move the counter below the tagline?

@Scoombe
Copy link
Contributor Author

Scoombe commented Mar 2, 2018

@bebraw @manpenaloza I have made some changes, but I need some help with the css. Could you help with this. Thanks.

this.updateCountdown = this.updateCountdown.bind(this);
this.dateToCountDownTo = props.initialDate;
this.currentDate = Date.now();
this.Difference = this.getDifferenceInDates();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point for storing those values as an instance variable? Let's simplify a bit by moving getting all derived values in the render method:

render() {
  const { days, hours, minutes, seconds } = timediff(this.state.currentDate, this.props.initialDate, "D:H:m:S");
  ...
}

and remove all instance variables. The only thing you'll need to store in the state is the currentDate:

constructor(super) {
  super();
  this.state = {
    currentDate: Date.now()
  };
}

}

componentDidMount() {
setInterval(this.updateCountdown, 1000);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to clean up the interval in the componentWillUnmount. This will cause a memory leak...

updateCountdown() {
this.currentDate = Date.now();
this.Difference = this.getDifferenceInDates();
this.updateState();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, here, instead of all this you could just this.setState({ currentDate: Date.now() }). This would trigger re-render.

this.updateState();
}

updateState() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole method is then not needed.

});
}

getDifferenceInDates() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one, too, can be removed.

}
}
Countdown.propTypes = {
initialDate: PropTypes.string,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call the initialDate as toDate since it's the countdown and it counts to some specific date.

@okonet
Copy link

okonet commented Mar 2, 2018

I can help you with CSS after you resolve the comments.

@Scoombe
Copy link
Contributor Author

Scoombe commented Mar 2, 2018

@okonet I have made the changes you have requested. Thanks, for pointing me in the right direction, I was having problems with the concept of when react was calling the reload.

@bebraw bebraw merged commit 89a2bf3 into ReactFinland:master Mar 5, 2018
@bebraw
Copy link
Collaborator

bebraw commented Mar 5, 2018

Merged! Thanks a lot for your contribution @Scoombe. Are you coming to the conference?

@okonet
Copy link

okonet commented Mar 5, 2018

Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants