Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Rewrite in React + Refactor #333

Merged
merged 34 commits into from
Oct 29, 2018
Merged

Rewrite in React + Refactor #333

merged 34 commits into from
Oct 29, 2018

Conversation

rafaelklaessen
Copy link
Contributor

This is a refactor of the hacktoberfest-checker in React. The backend is now a very light API, separate from the frontend, which is a React app (managed by create-react-app).

The next step would be to figure out what the best way to run the frontend is...Maybe served by the backend, or ran on a different server. Shouldn't be difficult.

Run the frontend with yarn start and the backend with yarn server.

I look forward to your reply! I know this certainly isn't done but would love to eventually see it up and running on your server.

As per screenshot...Everything still looks exactly the same 😄

@rafaelklaessen
Copy link
Contributor Author

Note how the _public folder is the unused one

@jenkoian
Copy link
Owner

Reviewing this now @rafaelklaessen first thoughts... WOW

The next step would be to figure out what the best way to run the frontend is...Maybe served by the backend, or ran on a different server. Shouldn't be difficult.

Outside of simply yarn server && yarn start something like https://www.npmjs.com/package/parallelshell ?

@@ -0,0 +1,51 @@
'use strict';

const _ = require('lodash');
Copy link
Owner

Choose a reason for hiding this comment

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

This doesn't appears to be used so can be removed.

@rafaelklaessen
Copy link
Contributor Author

That would be fine for development, but I meant the actual deployment. Originally you had 1 server, now you'll need 2 (static file server for React and a server for the backend).
Don't know if that's a problem for you 😄

const github = req.app.get('github');
const username = req.query.username;

var hostname = process.env.APP_URL || `${req.protocol}://${req.headers.host}`;
Copy link
Owner

Choose a reason for hiding this comment

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

Not used can be removed.

"not dead",
"not ie <= 11",
"not op_mini all"
]
Copy link
Owner

Choose a reason for hiding this comment

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

I didn't know about browserslist before, nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comes with react-scripts 😄

<a
target="_blank"
className="fb-xfbml-parse-ignore bg-blue-dark text-white rounded px-2 py-1 pointer text-white no-underline text-sm"
href={`https://www.facebook.com/sharer/sharer.php?u=${window.location.origin}/username/${username}`}
Copy link
Owner

Choose a reason for hiding this comment

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

Shall we use the hostname in place of window.location.origin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the benefit of that? It's more difficult to use such a variable, and it isn't available to the frontend.

Copy link
Owner

Choose a reason for hiding this comment

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

Consistency I guess 🤷‍♂️ it's no biggie. You'll have to excuse my lack of react knowledge here so apologies if this is a bad question, but we're using it here https://github.com/jenkoian/hacktoberfest-checker/pull/333/files#diff-af68e82a3010f5e2e3da304e5fe5caffR45 so could we not pass it through as a prop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need for passing it through as a prop, it's available everywhere through process.env.REACT_APP_HOSTNAME. Will change it 😄

@jenkoian
Copy link
Owner

I pushed some spacing fixes which ESLint as well as my IDE were reporting.

Generally, STUNNING WORK. I had started a react refactor as per #319 but got nowhere near as far as you have here.

A few questions (mostly ESLint things) but this is really really close to merge. THANK YOU for submitting 😃

@rafaelklaessen
Copy link
Contributor Author

Some other food for thought, what about 2 spaces rather than 4?

Seems to be the default for the vast majority of React apps, and with 4 spaces everything gets shifted to the right a lot, thereby making code (particularly JSX) more difficult to read. I think...:smile:

@jenkoian
Copy link
Owner

@rafaelklaessen yeah thought you might pushback on that 😄 I tend to prefer 4 spaces as I struggle to see the indentation of just 2 😄 perhaps just me or my IDE though and you're right in JS world it does seem that 2 spaces is the norm. If you're happy to update (including .editorconfig and eslint stuff) then happy to go with 2.

@rafaelklaessen
Copy link
Contributor Author

Moved from ESLint to Prettier because it's just so much more simple, and, opposed to ESLint, it just works(TM) with the latest babel presets.
Old eslint commands still work.

@jenkoian
Copy link
Owner

Thanks! Almost there. Could you update the 'Running the app' section of the README? If you could do the docker stuff that'd be great but no worries if not.

@rafaelklaessen
Copy link
Contributor Author

Done! 😄 Start command is still the same, but it now uses parallelshell.

(Didn't update the docker stuff - I'm not familiar with it.)

@jenkoian
Copy link
Owner

@rafaelklaessen thanks! Gonna give it another look later before merge, but probably the greatest thing I've ever seen 👏

@jenkoian
Copy link
Owner

jenkoian commented Oct 25, 2018

Hey sorry this is taking so long, need to find time to try this out with deployment but time is something in short supply for me right now. Hopefully soon!

@jenkoian
Copy link
Owner

Sorry got no time at mo to run this myself but doing some reading https://facebook.github.io/create-react-app/docs/deployment#other-solutions seems like what we need? Are you able to try this out locally your end and if it works make the required updates?

@rafaelklaessen
Copy link
Contributor Author

So you do want to combine the React and Express server?
I'm sure it will work...I've run create-react-app on Apache 😛

@jenkoian
Copy link
Owner

jenkoian commented Oct 25, 2018 via email

@jenkoian
Copy link
Owner

@rafaelklaessen just to expand on that, it doesn't make sense to me to run the front end through a server as well as the back end, I mean it makes sense for development but not for production. I'm very very new to react though so perhaps it's just me 🤷‍♂️

@rafaelklaessen
Copy link
Contributor Author

Well, it isn't uncommon to have 2 servers. People use 2 servers to maintain separation of concerns, especially for larger apps.

For hacktoberfest-checker, especially since frontend and backend are using the same configs, using one server indeed makes more sense.

@jenkoian
Copy link
Owner

I've pushed a commit which works for me locally. Let me know if you're happy and i'll update the deployment scripts and merge!

@rafaelklaessen
Copy link
Contributor Author

rafaelklaessen commented Oct 27, 2018

Fixed some tiny issues...There was a space missing in the footer, the build folder wasn't in .gitignore and the static serving didn't use an arrow function.

Running both frontend and backend on one server works great 😄

@jenkoian
Copy link
Owner

jenkoian commented Oct 27, 2018 via email

@rafaelklaessen
Copy link
Contributor Author

rafaelklaessen commented Oct 27, 2018

I updated .env.example 😄

Let me know if you're OK with this phrasing.

@jenkoian jenkoian merged commit 7d66365 into jenkoian:master Oct 29, 2018
@jenkoian
Copy link
Owner

Merged! Thanks so much 👍

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

Successfully merging this pull request may close these issues.

2 participants