-
Notifications
You must be signed in to change notification settings - Fork 35
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
The Reel Thing #14
base: master
Are you sure you want to change the base?
The Reel Thing #14
Conversation
src/components/App.js
Outdated
this.setState({ | ||
filmDetails: body, | ||
hints: [] | ||
}, () => this.toggleVisible()) |
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 would probably use isClosed: !this.state.isClosed
in setState to avoid having to use a callback
src/components/App.js
Outdated
query: query, | ||
currentPage: 1, | ||
filmDetails: {} | ||
}, () => this.searchByTitle(query, this.state.currentPage)); |
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 would take the search function out of the callback and pass in a hardcoded page number. Since searchByTitle
only uses params and not state inside it, it should be fine
src/components/App.js
Outdated
receiveSearchHint(string) { | ||
this.setState({ | ||
query: string, | ||
}, () => this.searchHint(this.state.query)); |
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.
As above, I would take searchHint out of the callback and use this.searchHint(string)
. It avoids having to use the callback
src/components/App.js
Outdated
}, () => this.searchByTitle(this.state.query, this.state.currentPage)); | ||
} | ||
|
||
receiveFavListState(boolean) { |
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.
boolean is a bit ambiguous. I would give the param a more specific name
src/components/App.js
Outdated
favourites.unshift(obj); | ||
this.setState({ | ||
favourites: favourites | ||
}, () => window.localStorage.setItem("favourites", JSON.stringify(this.state.favourites))); |
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 would take window.localStorage.setItem("favourites", JSON.stringify(this.state.favourites))
out of callback and use window.localStorage.setItem("favourites", JSON.stringify(favourites))
src/components/App.js
Outdated
favourites.splice(index, 1); | ||
this.setState({ | ||
favourites: favourites | ||
}, () => window.localStorage.setItem("favourites", JSON.stringify(this.state.favourites))); |
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.
As above
this.handleClick = this.handleClick.bind(this); | ||
} | ||
|
||
handleClick(e) { |
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 would probably create two separate click handlers, one for each action rather than checking classes. It would make the code a tiny bit easier to read
handleClick(e) { | ||
this.setState({ | ||
showFavs: !this.state.showFavs | ||
}, () => this.props.receiveFavListState(this.state.showFavs)) |
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 would take the receiver call out of callback and pass to it a pre-calcualated value
src/components/Pagination.js
Outdated
handleClick(e) { | ||
const totalPages = Math.ceil(this.props.totalFilms / this.props.filmsPerPage) | ||
|
||
if (e.target.className.includes("btn__next") && this.state.currentPage < totalPages) { |
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.
As before, I would suggest separate click handlers and not using setState callbacks
} | ||
|
||
handleClick(e) { | ||
this.props.receiveFilmID(e.target.parentNode.dataset.id); |
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.
It's better practice not use data attributes in React and instead work with data from props
Good work, but I would recommend avoiding setState callbacks where possible. Also, using more click handlers will save having to write logic which checks classes |
I seem to be passing a lot of functions and states around, and I feel that it could be more straight-forward.
Especially with toggling styles and getting the search form to minimise only on the first user interaction.