Cloning Front-end of Netflix using React/Redux along with Firebase, Also utilising Open AI GPT for empowering various features.
π NetflixGPT Project Live Link π
-
boilerPlate setup using create-react-app β
-
cleanedUp the boilerPlate code to kickStart the project β
-
added tailwindCSS config β
-
creating components & utils folder β
-
Login Component β
- App > Body (body is Home page) β
- Body > Login + Browse β
- Create routing in Body (Revise routing first) - β
- for / login
- for /browse browse
- added a errorPage also for unhandled routes β
- Login > Header(comman) β
- Developing Header β
- Login > Form(login/ignup) β
- Form validation β
- useRef Hook instead of local state for holding form states β
- creating utility validate.js for validating form, validating for name, email, password β
- showing error messages in UI as per validation β
-
Adding Firebase as Backend & deploying it on Prod β
- create firebase project in firebase console, enable hosting also β
- set up as instructed, copy project config β
- you must enable authentication, enable it β
- host the project via firebase hosting β
- name your deployment folder as : build
- rewrite all urls to index.html : no
- set auto builds : no
-
Creating Sign UP user account in Firebase β
- in firebase docs find registering users β
- password based account > web modular api β
- getting get auth from a central place β
- write sign in and sign up logic following firebase docs β
- check if firebase is registering users β
- play with details returned after sign in/up β
-
Setting up redux tool kit + Sign in/up/out functionlity via Firebase Auth β
- revise redux tool kit first β
- once the user in sign in / up, firebase returns a user object with access token β
- we will store that user into the redux store, to keep track of session β
- 2 actions, in user slice, adduser, and removeuser β
- then we will navigate the user to browse page
- when user sign up/sign in : adduser, when sign out : removeuser β
- after sign in/up : navigate user to browser page β
- after sign out : navigate user to login page / β
- useNavigate() hook of react router dom β
- once the user logged in then only, browse page will be shown, otherwise make browse page protected β
- once user logs in / or sign up then only show & actigvate sign out button/functionlity in header β
- update profile via update api, once sign in/up with userName β
- display the user name + photo URL(s) [dummy as of now], in header once logged in β
- Fixed the bug > made login and browse protected via adding onAuthChange api from firebase, and navigation is handled by it only β
- Fixed another bug, added 2 users, 1 from redux store, 1 from firebase auth, to fix name collapsing issue β
- adding loader while signing up and siginig in for better and smooth UX β
- unsubscribed the onAuthChange subscription β
- constant file added for dummy strings and constant data β
-
Creating Browse Page β
- registered and logged in on TMDB to use their API's [got access token and api key] β
- Copy NOW_PLAYING_MOVIES_API_OPTIONS into your constant file β
- in Browse page make the API call to get Now playing movies β
- creating a moviesSlice, and storing all our data into the moviesSlice β
- movieSlice will have initialState as: β
- nowPlayingMovies β
- trailerVideo β
- movieSlice will have initialState as: β
- initailly do all these stuff -> fetch data from tmdb and then store it into redux in browser page β
- then create a custom hook to do so to keep browse component clean β
- create useNowPLayingMovies hook, in hooks folder β
- create browse page UI β
- plannning how to create the UI β
- Browse page UI (2 parts) β
- Maincontainer β
- Video BG of Movie β
- Video title & info β
- SecondaryContainer β
- MoviesCategories*n β
- MovieCards*n β
- MoviesCategories*n β
- Maincontainer β
- as planned make 2 components, MainContainer + SecondaryContainer β
- MainContainer β
- fetch movies using useSelector from store β
- create 2 components β
- VideoTitle β
- VideoBackground β
- early retrurn is movies are not loaded β
- else first movie will be main movie for which title and video will be shown β
- destructure relevant info from object and passed it to videoTitle component as props β
- Now for videoBackground, nowplaying movies api won't have the trailer β
- We will use another API from tmdb, video api, which will take movie id and give video for that β
- pass movie id as a prop to video BG comp β
- in VideoBG comp make api call with movie id to get movie videos β
- out of all the clips returned, use type="trailer" as bg β
- in trailer is not there use any first video as bg (write logic) β
- trailer object contains youtube id, from youtube take the embedded code , handle the id dynamically
- for storing trailer id, make use of redux not local state, put entire object into redux, and use from there only β
- make useMovieTrailer, to fetch trailer and store it in redux, make a custom hook for it, to make component cleaner β
- css to make video bg and title look like how fateflix does β
- building secondary container β
- planning building secondary conatiner β
- MovieList - Popular β
- moviescards*n β
- MovieList - nowPLaying β
- MovieList - Horror β
- MovieList - Popular β
- Make 2 components, MovieList & MovieCard β
- pass movie list title from secondary container to movielist β
- looppver movieCards into movieLIst β
- use css to make it look like fateflix β
- create differetnt hooks for getting different categories, i.e popular, trending, etc β
- call those hooks also to browse page only > done via single hook only β
- accordingly different lists would be there β
-
Creating GptSearchPage component Feature β
- in header > gpt search btn (only for signned in users) β
- on click of the btn > GptSearchPage component β
- GptSearchPage component > in browse component > accessble only on header btn click (build toggle functionilty) β
- to make the toggle functionlity work, store the reducer to toggle into redux store, create gptSlice in slices folder β
- create action toggleGptSearchView β
- GPT Search component planning
- bg image same as of /login screen β
- GptSearchBar β
- form > search bar + btn β
- note : onSubmit > preventDefault behaviour β
- form > search bar + btn β
- GptMoviesSuggestions β
- put bg image in constants if already not coming β
- translation into other languages using a constant file
- create a constant file lang, store object of 2 languages hindi, english in the contant file, each word on your app/site must be in these languages hardcoaded here β
- then on header give an option to toggle from select options β
- on select handler change the language as should be coming dynamically from contant file β
- even options in the select option also should come from constant file β
- do it only in the GptSearchComponent β
- when clicking on GptSearchComponent should toggle name from GptSearch to homepage β
- in homepage option for language change should not come β
- before moving ahead clean up all the componentnts β
- bug fixes regarding multilang feature β
-
Starting GptSearch Feature β
- register on open ai β
- from platform.openai β
- get your api key β
- keep your key secret [paid api] β
- install open ai npm library, go through its docs, readme on github β
- make seprate util file to initialse open ai, export it β
- on click of search btn > submitHandler
- preventDefault behaviour β
- import open ai β
- call the open ai function with the search term
- dangerously allow error by openAi set it to allowed β
- be specific about passing the query, query , form one,β
- query : act as a movie recommendation system and recommend some movies to me for the specific query, query : {dynamic input} , give me comma separated values as result in an array format contains 5 movie titles only, such as for query : indian old is gold movies, result : [gadar, sholey, don, golmaal, kabhi khushi kabhi gam]
- Flow β
- after query like this, openAI will give result for 5 movies β
- search these 5 titles using TMDB seach movie api's β
- movie details will comes to us, then simply display those movies to user in UI β
- in case open AI gpt does not give result, handle that error gracefully β
- create array of movies from resultβ
- now for all 5 movie names, we must call TMDB's search api, 5 movies - 5 api calls, create a utility function for the same β
- using map call that utility funciton -> func will be called 5 times -> won't give result -> async code, will return unresolved promises array β
- use promise.all to resolve promise and get the results β
- multiple movies will come as result β
- store those movies in redux store, in gpt slice itself β
- search results which are coming from open ai, after entering query store those also in redux store β
- movies extraction logic can be extracted into hooks β
-
Chat GPT Search result UI β
- GetMoviesSuggestions β
- in this compoennt, get movies name, and movies from redux store β
- use the same already used > movieList component for display movie cards β
- map over movie names and multiple movieList components with movies β
- GetMoviesSuggestions β
-
Securing API Keys β
- create .env file in root β
- append REACT_APP_API_KEY_NAME to keys to append it, no strings directly content β
- when need to use it use process.env.REACT_APP_API_KEY_NAME β
- add .env file to gitIgnore β
- store all firebase config also in env β
-
Memoization β
- for avoiding unnecessry api calls we can memoize, hooks fetching ones β
- if redux store has data for example moveis, then don't make api call for fetching moveis β
- do the same for all fetching logics β
- no need to use useMemo β
- simply check if store has it, don't call fetch function in useEffect β
-
Make the site mobile responsive β
- using tailwind β
- default sm:(tablet min-width:640px) md:(desktop min-width:768px) β
- mobile first approch, β
- sm : for tablets β
- md/lg : for desktop β
- by default : whatever styling is there would be for mobile β
- using tailwind β
-
Bug fixes + making the project stable as much as possible β
- plan once the above points are done ...
- whever calling tmdb api(s) store hardcode that data, as TMDB is not working β
- work on the stability of site, without using TMDB make everything working, use hardcoded data whever possible β
- hero movie text if more then 2 lines, append it with ... β
- when not connected to vpn taking a lot of time if takes more then 3 seconds display harcoded data β
- find an alternative for suggested video tmdb issue β
- api issue, gave alter and warning for the same β
- fix reload issue on firebase live β
-
additional features
-
on click on movie cards take them to movie trailer on youtube β
- for bgVideo β
- for other movies cards β
- plan β
- give 2 options (btns) β
- view details β
- whatever we have in redux store, title, overview etc etc, make use of it and make a opo up card β
- watch trailer β
- query youtube with title and sent them to trailer search page, on youtube
- view details β
- make all things mobile responsive β
- give 2 options (btns) β
- plan β
-
add footer in site β
-
bug fix, after clicking on search only, if can't fetch gptsearch then only show then JIO network issue β
-
show hide password option on login form
-
fix login page styling β
-
validation on chatGPT search bar β
-
add buttons for scroll, impplement scroll feature β
-
add google auth also β
-
make google sign in looking good + make feature mobile responsive β
-
-
Self-branding β -- write a linkedin Post Appreaciating sir Akshay Saini, your own efforts, Additional features, Job fetching post
-
NetFlix Home Page
- Login / SignUp Form
- Once logged in redirects to Broswe page
-
Browse Page (After Authentication)
- Header
- Hero Movie
- Trailer in backgorund
- Title & descirption
- Movie suggestions
- Movie list carousel * n
- Movie * n
- Movie list carousel * n
-
Netflix GPT
- Search bar
- Movie suggestion via AI on search