-
Notifications
You must be signed in to change notification settings - Fork 0
PR for Video Library [FE] #1
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
base: master
Are you sure you want to change the base?
Conversation
|
Hey Purva, I totally loved your app. The code is very clean too. Also for the functions, in few places, the arrow function is used and in few places, regular function syntax is used. You can change all to arrow functions so that your app will only have Es6 syntax and it will be consistent. |
| const { _id, name, videos, defaultPlaylist } = playlist; | ||
| return ( | ||
| <Fragment key={_id}> | ||
| <PlaylistHeader |
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.
You can create a playlist card component and extract this out. The main page structure would look more cleaner.
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.
A playlist is a group of videos and does not have a card as such. So, I made the code readable by breaking it into more components. Thanks for noticing this.
| navigate("/page-not-found"); | ||
| } | ||
| })(); | ||
| return () => { |
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 nice that you have cleaned up the useEffect.I should do it too
src/pages/Videos/VideoDetail.js
Outdated
| useEffect(() => { | ||
| if (mongooseVideoId) { | ||
| if (history.length === 0) { | ||
| (async () => { |
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 feel it is getting a bit verbose here. Try extracting it to a separate function.
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.
Good Idea. Created multiple functions for this
src/pages/Videos/VideoListing.js
Outdated
| export function ToggleIconGroup({ video, likedVideos, watchLater }) { | ||
| return ( | ||
| <> | ||
| <ToggleIcon playlist={likedVideos || defaultPlaylist} video={video} /> |
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 || thing is so cool. I will use it in mine also. I used to pass an additional prop for this
src/custom hooks/useToggleVideo.js
Outdated
| } | ||
| } else { | ||
| const success = await removeVideoFromPlaylist(video._id); | ||
| if (success) { |
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.
You can extract these also to a separate function. It would be easier to understand.
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.
Again a great suggestion. Updated this
Thanks a lot for your Review. All your suggestions are great!
|
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.
- Great work @purvasheth, Very nice and consistent UI
- The code is very well maintained and the naming of the components is also perfect.
Here are my few suggestions
- You can use
index.jsat the root folder wherever you feel it is required while using nested imports. - Use ternary operator where you are using if-else for small code
- Just a suggestion, single file going over 100 lines, you can extract the components to separate files and import them
| import { VideoListing } from "./pages/Videos/VideoListing"; | ||
| import { Playlists } from "./pages/Playlists/Playlists"; | ||
| import { PlaylistDetail } from "./pages/Playlists/PlaylistDetail"; | ||
| import { Routes, Route } from "react-router-dom"; | ||
| import { NavigationBar } from "./components/NavigationBar"; | ||
| import { VideoDetail } from "./pages/Videos/VideoDetail"; | ||
| import { PageNotFound } from "./pages/PageNotFound"; | ||
| import { History } from "./pages/History/History"; | ||
| import { SearchResults } from "./pages/SearchResults"; | ||
| import { ToastContainer } from "react-toastify"; |
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.
Instead of doing separate imports for the same folder, you can use index.js inside page folder and re-export all nested components inside pages folder
e.g.
| import { VideoListing } from "./pages/Videos/VideoListing"; | |
| import { Playlists } from "./pages/Playlists/Playlists"; | |
| import { PlaylistDetail } from "./pages/Playlists/PlaylistDetail"; | |
| import { Routes, Route } from "react-router-dom"; | |
| import { NavigationBar } from "./components/NavigationBar"; | |
| import { VideoDetail } from "./pages/Videos/VideoDetail"; | |
| import { PageNotFound } from "./pages/PageNotFound"; | |
| import { History } from "./pages/History/History"; | |
| import { SearchResults } from "./pages/SearchResults"; | |
| import { ToastContainer } from "react-toastify"; | |
| import { VideoListing, Playlists, PlaylistDetail,... } from "./pages"; |
| <Routes> | ||
| <Route path="/" element={<VideoListing />} /> | ||
| <Route path="/playlists" element={<Playlists />} /> | ||
| <Route path="/playlists/:playlistId" element={<PlaylistDetail />} /> | ||
| <Route path="/video/:videoId" element={<VideoDetail />} /> | ||
| <Route path="/history" element={<History />} /> | ||
| <Route path="/search" element={<SearchResults />} />s | ||
| <Route path="*" element={<PageNotFound />} /> | ||
| </Routes> |
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.
Extract this to a router.js file
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.
Since the number of routes is less, I think it's ok to keep them in this file.
| import { NavLink } from "react-router-dom"; | ||
| import { usePlaylists } from "../pages/Playlists/playlists-context"; | ||
| import { SET_VIDEOS } from "../pages/Videos/videos-reducer"; | ||
| import { useAxios } from "../custom hooks/useAxios"; |
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.
use consistent naming convention custom hooks rename to custom-hooks
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.
Good catch. Will update this.
| (!isLikedVideosIdSet || !isWatchLaterIdSet) && | ||
| i < playlists.length | ||
| ) { |
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.
You could extract this logic out to function to improve readability
| </label> | ||
| ); | ||
| } | ||
| function CreatePlaylist({ |
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.
You could extract out CreatePlaylist and it's related components to new file
| <h1>{name}</h1> | ||
| <div className="flex"> | ||
| {videos.map((video) => { | ||
| return ( |
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.
Again, here you can remove return same as before
| ); | ||
| } | ||
|
|
||
| function PlaylistHeader({ name, _id, defaultPlaylist }) { |
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.
Extract this component and below component to different file
| playlists: playlists.map((playlist) => | ||
| playlist._id !== playlistId | ||
| ? playlist | ||
| : { ...playlist, videos: playlist.videos.concat(video) } | ||
| ), | ||
| }; |
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.
Extract this and similar reducer actions to another function and use them,
And you can refactor it to this in ADD_VIDEO_ && REMOVE_VIDEO_
| playlists: playlists.map((playlist) => | |
| playlist._id !== playlistId | |
| ? playlist | |
| : { ...playlist, videos: playlist.videos.concat(video) } | |
| ), | |
| }; | |
| playlists: playlists.map((playlist) => | |
| playlist._id === playlistId | |
| ? { ...playlist, videos: playlist.videos.concat(video) } : playlist | |
| ), | |
| }; |
|
|
||
| return ( | ||
| <div key={id} className="card card--shadow m-1"> | ||
| <Thumbnail onClick={openVideo} id={id} className="clickable" /> |
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 onClick={openVideo} function should be on the upper div and not on Thumbnail, due to which clicking on an avatar or video title, the video is not opening up.
| const [activeCategory, setActiveCategory] = useState("All"); | ||
| return ( | ||
| <div className="container"> | ||
| <h1>Video Listing</h1> |
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.
Instead of VideoListing, you can rename it to Explore Videos or anything else
All your suggestions were great! |
No description provided.