├── client ├── .dockerignore ├── public │ ├── _redirects │ ├── logo.jpeg │ ├── logo.png │ └── index.html ├── src │ ├── img │ │ └── logo.png │ ├── assests │ │ └── images │ │ │ └── Avatar.png │ ├── utils │ │ ├── spinsearch.jsx │ │ ├── Theme.js │ │ ├── spinsearch2.css │ │ ├── useNetworkStatus.js │ │ ├── spinner.jsx │ │ └── errorMessage.jsx │ ├── index.css │ ├── index.js │ ├── components │ │ ├── Recommendation.jsx │ │ ├── Comment.jsx │ │ ├── ReportModal.jsx │ │ ├── Comments.jsx │ │ ├── Model.jsx │ │ ├── Card.jsx │ │ ├── Upload.jsx │ │ ├── Menu.jsx │ │ └── Navbar.jsx │ ├── redux │ │ ├── savedVideosSlice.js │ │ ├── store.js │ │ ├── videoSlice.js │ │ └── userSlice.js │ ├── pages │ │ ├── Search.jsx │ │ ├── SavedVideos.jsx │ │ ├── Home.jsx │ │ ├── Profile.jsx │ │ ├── SignIn.jsx │ │ └── Video.jsx │ ├── firebase.js │ ├── config.js │ └── App.js ├── Dockerfile ├── .gitignore ├── package.json └── README.md ├── server ├── .Procfile ├── error.js ├── routes │ ├── auth.js │ ├── reports.js │ ├── comments.js │ ├── videos.js │ └── users.js ├── Dockerfile ├── models │ ├── Report.js │ ├── Comment.js │ ├── User.js │ └── Video.js ├── .gitignore ├── controllers │ ├── report.js │ ├── comment.js │ ├── auth.js │ ├── user.js │ └── video.js ├── package.json ├── verifyToken.js └── index.js ├── Makefile ├── .github ├── ISSUE_TEMPLATE │ ├── feature_request.md │ ├── doc_report.yml │ ├── feature_request.yml │ └── bug_report.yml └── pull_request_template.md ├── LICENSE ├── docker-compose.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── README.md /client/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /server/.Procfile: -------------------------------------------------------------------------------- 1 | web: npm run start -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | run-local: 2 | docker-compose up -------------------------------------------------------------------------------- /client/public/_redirects: -------------------------------------------------------------------------------- 1 | /* /index.html 200 -------------------------------------------------------------------------------- /client/public/logo.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mnnkhndlwl/mern_youtube_clone/HEAD/client/public/logo.jpeg -------------------------------------------------------------------------------- /client/public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mnnkhndlwl/mern_youtube_clone/HEAD/client/public/logo.png -------------------------------------------------------------------------------- /client/src/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mnnkhndlwl/mern_youtube_clone/HEAD/client/src/img/logo.png -------------------------------------------------------------------------------- /client/src/assests/images/Avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mnnkhndlwl/mern_youtube_clone/HEAD/client/src/assests/images/Avatar.png -------------------------------------------------------------------------------- /server/error.js: -------------------------------------------------------------------------------- 1 | export const createError = (status, message)=>{ 2 | const err = new Error() 3 | err.status= status 4 | err.message= message 5 | return err 6 | } -------------------------------------------------------------------------------- /client/src/utils/spinsearch.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import "./spinsearch2.css"; 3 | 4 | export default function LoadingSpinner() { 5 | return ( 6 |
7 |
8 |
9 |
10 | ); 11 | } -------------------------------------------------------------------------------- /client/src/index.css: -------------------------------------------------------------------------------- 1 | .material-symbols-rounded{ 2 | color: "#000000"; 3 | font-weight: 200; 4 | } 5 | 6 | .material-symbols-rounded.active{ 7 | font-variation-settings: 8 | 'FILL' 1, 9 | 'wght' 300, 10 | 'GRAD' 0, 11 | 'opsz' 48; 12 | } 13 | 14 | body{ 15 | overflow-x: hidden; 16 | } 17 | -------------------------------------------------------------------------------- /client/Dockerfile: -------------------------------------------------------------------------------- 1 | # Dockerfile for React client 2 | 3 | # Build react client 4 | FROM node:16 5 | 6 | # Working directory be app 7 | WORKDIR /usr/src/app 8 | 9 | COPY package*.json ./ 10 | 11 | ### Installing dependencies 12 | 13 | RUN npm install --silent 14 | 15 | # copy local files to app folder 16 | COPY . . 17 | 18 | EXPOSE 3000 19 | 20 | CMD ["npm","start"] -------------------------------------------------------------------------------- /server/routes/auth.js: -------------------------------------------------------------------------------- 1 | import express from "express"; 2 | import { googleAuth, signin, signup } from "../controllers/auth.js"; 3 | 4 | const router = express.Router(); 5 | 6 | //CREATE A USER 7 | router.post("/signup", signup) 8 | 9 | //SIGN IN 10 | router.post("/signin", signin) 11 | 12 | //GOOGLE AUTH 13 | router.post("/google", googleAuth) 14 | 15 | export default router; -------------------------------------------------------------------------------- /server/Dockerfile: -------------------------------------------------------------------------------- 1 | # Dockerfile for Node Express Backend 2 | 3 | FROM node:16 4 | 5 | # Create App Directory 6 | RUN mkdir -p /usr/src/app 7 | WORKDIR /usr/src/app 8 | 9 | # Install Dependencies 10 | COPY package*.json ./ 11 | 12 | RUN npm install 13 | 14 | # Copy app source code 15 | COPY . . 16 | 17 | # Exports 18 | EXPOSE 3001 19 | 20 | CMD ["npm","start"] 21 | 22 | 23 | -------------------------------------------------------------------------------- /server/models/Report.js: -------------------------------------------------------------------------------- 1 | import mongoose from "mongoose"; 2 | 3 | const ReportSchema = new mongoose.Schema( 4 | { 5 | userId: { 6 | type: String, 7 | required: true, 8 | }, 9 | issue: { 10 | type: String, 11 | required: true, 12 | }, 13 | }, 14 | { timestamps: true } 15 | ); 16 | 17 | export default mongoose.model("Report", ReportSchema); 18 | -------------------------------------------------------------------------------- /server/routes/reports.js: -------------------------------------------------------------------------------- 1 | import express from "express"; 2 | import { getAllIssues, reportIssue } from "../controllers/report.js"; 3 | import { verifyToken } from "../verifyToken.js"; 4 | 5 | const router = express.Router(); 6 | 7 | //GET ALL ISSUES 8 | router.get("/", getAllIssues); 9 | 10 | //REPORT ISSUE 11 | router.post("/new", verifyToken, reportIssue); 12 | 13 | export default router; 14 | -------------------------------------------------------------------------------- /server/routes/comments.js: -------------------------------------------------------------------------------- 1 | import express from "express"; 2 | import { addComment, deleteComment, getComments } from "../controllers/comment.js"; 3 | import {verifyToken} from "../verifyToken.js" 4 | const router = express.Router(); 5 | 6 | router.post("/", verifyToken, addComment); 7 | router.delete("/:id", verifyToken, deleteComment); 8 | router.get("/:videoId", getComments) 9 | 10 | export default router; -------------------------------------------------------------------------------- /client/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | .env 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | -------------------------------------------------------------------------------- /server/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | .env 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | -------------------------------------------------------------------------------- /client/src/utils/Theme.js: -------------------------------------------------------------------------------- 1 | export const darkTheme = { 2 | bg:"#181818", 3 | bgLighter:"#202020", 4 | text:"white", 5 | textSoft:"#aaaaaa", 6 | soft:"#373737", 7 | secondary_color:"#212121", 8 | secondary_light_color:"#e5e5e5", 9 | hover_text_color:"#dbdbdb" 10 | 11 | } 12 | export const lightTheme = { 13 | bg:"#f9f9f9", 14 | bgLighter:"white", 15 | text:"black", 16 | textSoft:"#606060", 17 | soft:"#f5f5f5" 18 | } -------------------------------------------------------------------------------- /server/models/Comment.js: -------------------------------------------------------------------------------- 1 | import mongoose from "mongoose"; 2 | 3 | const CommentSchema = new mongoose.Schema( 4 | { 5 | userId: { 6 | type: String, 7 | required: true, 8 | }, 9 | videoId: { 10 | type: String, 11 | required: true, 12 | }, 13 | desc: { 14 | type: String, 15 | required: true, 16 | }, 17 | }, 18 | { timestamps: true } 19 | ); 20 | 21 | export default mongoose.model("Comment", CommentSchema); -------------------------------------------------------------------------------- /client/src/utils/spinsearch2.css: -------------------------------------------------------------------------------- 1 | @keyframes spinner { 2 | 0% { 3 | transform: rotate(0deg); 4 | } 5 | 100% { 6 | transform: rotate(360deg); 7 | } 8 | } 9 | .loading-spinner { 10 | width: 50px; 11 | height: 50px; 12 | border: 10px solid #f3f3f3; /* Light grey */ 13 | border-top: 10px solid #383636; /* Black */ 14 | left: 50%; 15 | position: absolute; 16 | text-align: center; 17 | top: 50%; 18 | border-radius: 50%; 19 | animation: spinner 1.5s linear infinite; 20 | } -------------------------------------------------------------------------------- /server/controllers/report.js: -------------------------------------------------------------------------------- 1 | import Report from "../models/Report.js"; 2 | 3 | const getAllIssues = async (req, res, next) => { 4 | try { 5 | const resp = await Report.find({}); 6 | res.status(200).json(resp); 7 | } catch (err) { 8 | next(err); 9 | } 10 | }; 11 | 12 | const reportIssue = async (req, res, next) => { 13 | const newIssue = new Report({ ...req.body, userId: req.user.id }); 14 | try { 15 | const savedIssue = await newIssue.save(); 16 | res.status(200).send(savedIssue); 17 | } catch (err) { 18 | next(err); 19 | } 20 | }; 21 | 22 | export { getAllIssues, reportIssue }; 23 | -------------------------------------------------------------------------------- /server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "type": "module", 7 | "scripts": { 8 | "start": "nodemon index.js --ignore '../client/'" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "bcryptjs": "^2.4.3", 15 | "cookie-parser": "^1.4.6", 16 | "cors": "^2.8.5", 17 | "dotenv": "^16.0.1", 18 | "express": "^4.18.1", 19 | "index.js": "^0.0.3", 20 | "jsonwebtoken": "^8.5.1", 21 | "mongoose": "^6.5.0", 22 | "node": "^18.9.0", 23 | "nodemon": "^2.0.19" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /client/src/utils/useNetworkStatus.js: -------------------------------------------------------------------------------- 1 | import { useState, useEffect } from "react"; 2 | import isOnline from 'is-online'; 3 | 4 | const useNetworkStatus = () => { 5 | const [onlineStatus, setOnlineStatus] = useState(null); 6 | 7 | useEffect(() => { 8 | isOnline().then(status => { 9 | setOnlineStatus(status); 10 | }); 11 | 12 | const intervalId = setInterval(() => { 13 | isOnline().then(status => { 14 | setOnlineStatus(status); 15 | }); 16 | }, 5000); 17 | 18 | return () => clearInterval(intervalId); 19 | }, []); 20 | 21 | return onlineStatus 22 | }; 23 | 24 | export default useNetworkStatus; 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/doc_report.yml: -------------------------------------------------------------------------------- 1 | name: Documentation request 2 | description: Change regarding improvising the docs to be more accessible 3 | title: "[Doc]: " 4 | labels: [documentation, enhancement, good first issue] 5 | body: 6 | - type: checkboxes 7 | attributes: 8 | label: Describe the bug 9 | description: A clear and concise description of what the bug is 10 | options: 11 | - label: Information addition regarding the newest change through a PR. 12 | - label: Typo error. 13 | - label: New category addition. 14 | - label: Refractoring sentences that make more sense. 15 | - label: Fixing broken links. 16 | - label: Refractors / reformating of the document. 17 | -------------------------------------------------------------------------------- /server/routes/videos.js: -------------------------------------------------------------------------------- 1 | import express from "express"; 2 | import { addVideo, addView, getByTag, getVideo, random, search, sub, trend,set, deleteVideo } from "../controllers/video.js"; 3 | import { verifyToken } from "../verifyToken.js"; 4 | 5 | const router = express.Router(); 6 | 7 | //create a video 8 | router.post("/", verifyToken,addVideo) 9 | router.put("/:id", verifyToken,addVideo) 10 | router.delete("/:id", verifyToken, deleteVideo) 11 | router.get("/find/:id", getVideo) 12 | router.put("/view/:id", addView) 13 | router.get("/trend", trend) 14 | router.get("/random", random) 15 | router.get("/sub",verifyToken, sub) 16 | router.get("/settings",verifyToken, set) 17 | router.get("/tags", getByTag) 18 | router.get("/search", search) 19 | 20 | export default router; -------------------------------------------------------------------------------- /client/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import { Provider } from 'react-redux'; 4 | import App from './App'; 5 | import { persistor, store } from './redux/store'; 6 | import { PersistGate } from 'redux-persist/integration/react'; 7 | import "./index.css" 8 | import { SnackbarProvider } from 'notistack'; 9 | 10 | 11 | const root = ReactDOM.createRoot(document.getElementById('root')); 12 | root.render( 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | ); 23 | -------------------------------------------------------------------------------- /client/src/components/Recommendation.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import styled from "styled-components"; 3 | import { publicRequest } from "../config"; 4 | import Card from "./Card"; 5 | 6 | const Container = styled.div` 7 | flex: 2; 8 | `; 9 | 10 | const Recommendation = ({ tags }) => { 11 | const [videos, setVideos] = useState([]); 12 | 13 | useEffect(() => { 14 | const fetchVideos = async () => { 15 | const res = await publicRequest.get(`/api/videos/tags?tags=${tags}`); 16 | setVideos(res.data); 17 | }; 18 | fetchVideos(); 19 | }, [tags]); 20 | 21 | return ( 22 | 23 | {videos.map((video) => ( 24 | 25 | ))} 26 | 27 | ); 28 | }; 29 | 30 | export default Recommendation; -------------------------------------------------------------------------------- /client/src/utils/spinner.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import styled, { keyframes } from 'styled-components'; 3 | 4 | const rotate = keyframes` 5 | from { 6 | transform: rotate(0deg); 7 | } 8 | to { 9 | transform: rotate(360deg); 10 | } 11 | `; 12 | 13 | const StyledSpinner = styled.div` 14 | position :absolute; 15 | left: 50%; 16 | top: 50%; 17 | z-index: 1; 18 | &::before { 19 | content: ""; 20 | display: block; 21 | position: absolute; 22 | width: 64px; 23 | height: 64px; 24 | margin: 8px; 25 | border-radius: 50%; 26 | border: 6px solid #f3f3f3; 27 | border-top-color: #3498db; 28 | animation: ${rotate} 1s linear infinite; 29 | } 30 | `; 31 | 32 | const LoadingSpinner = () => { 33 | return ; 34 | }; 35 | 36 | export default LoadingSpinner; 37 | -------------------------------------------------------------------------------- /server/models/User.js: -------------------------------------------------------------------------------- 1 | import mongoose from "mongoose"; 2 | 3 | const UserSchema = new mongoose.Schema( 4 | { 5 | name: { 6 | type: String, 7 | required: true, 8 | unique: true, 9 | }, 10 | email: { 11 | type: String, 12 | required: true, 13 | unique: true, 14 | }, 15 | password: { 16 | type: String, 17 | }, 18 | img: { 19 | type: String, 20 | }, 21 | subscribers: { 22 | type: Number, 23 | default: 0, 24 | }, 25 | subscribedUsers: { 26 | type: [String], 27 | }, 28 | fromGoogle: { 29 | type: Boolean, 30 | default: false, 31 | }, 32 | isSuperUser: { 33 | type: Boolean, 34 | default: false, 35 | }, 36 | }, 37 | { timestamps: true } 38 | ); 39 | 40 | export default mongoose.model("User", UserSchema); 41 | -------------------------------------------------------------------------------- /server/verifyToken.js: -------------------------------------------------------------------------------- 1 | import jwt from "jsonwebtoken"; 2 | import { createError } from "./error.js"; 3 | 4 | export const verifyToken = (req, res, next) => { 5 | const authHeader = req.headers.token; 6 | console.log(authHeader); 7 | if (authHeader) { 8 | const token = authHeader.split(" ")[1]; 9 | jwt.verify(token, process.env.JWT, (err, user) => { 10 | if (err) res.status(403).json("Token is not valid!"); 11 | req.user = user; 12 | next(); 13 | }); 14 | } else { 15 | return res.status(401).json("You are not authenticated!"); 16 | } 17 | }; 18 | 19 | // import axios from "axios"; 20 | 21 | // //let axios = Axios.create({ withCredentials: true }); 22 | 23 | // // axios.defaults.withCredentials = true; 24 | 25 | // export const axiosInstance = axios.create({ 26 | // baseURL : "http://localhost:5000/" 27 | // }); 28 | 29 | 30 | -------------------------------------------------------------------------------- /server/models/Video.js: -------------------------------------------------------------------------------- 1 | import mongoose from "mongoose"; 2 | 3 | const VideoSchema = new mongoose.Schema( 4 | { 5 | userId: { 6 | type: String, 7 | required: true, 8 | }, 9 | title: { 10 | type: String, 11 | required: true, 12 | }, 13 | desc: { 14 | type: String, 15 | required: true, 16 | }, 17 | imgUrl: { 18 | type: String, 19 | required: true, 20 | }, 21 | videoUrl: { 22 | type: String, 23 | required: true, 24 | }, 25 | views: { 26 | type: Number, 27 | default: 0, 28 | }, 29 | tags: { 30 | type: [String], 31 | default: [], 32 | }, 33 | likes: { 34 | type: [String], 35 | default: [], 36 | }, 37 | dislikes: { 38 | type: [String], 39 | default: [], 40 | }, 41 | }, 42 | { timestamps: true } 43 | ); 44 | 45 | export default mongoose.model("Video", VideoSchema); -------------------------------------------------------------------------------- /client/src/redux/savedVideosSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | 3 | const initialState = { 4 | savedVideos: [], 5 | loading: false, 6 | error: false, 7 | }; 8 | 9 | export const savedVideosSlice = createSlice({ 10 | name: "savedVideos", 11 | initialState, 12 | reducers: { 13 | saveVideo: (state, action) => { 14 | if (!state.savedVideos.find(video => video._id === action.payload._id)) { 15 | state.savedVideos.push(action.payload); 16 | } 17 | }, 18 | unsaveVideo: (state, action) => { 19 | state.savedVideos = state.savedVideos.filter( 20 | video => video._id !== action.payload 21 | ); 22 | }, 23 | setSavedVideos: (state, action) => { 24 | state.savedVideos = action.payload; 25 | }, 26 | }, 27 | }); 28 | 29 | export const { saveVideo, unsaveVideo, setSavedVideos } = savedVideosSlice.actions; 30 | 31 | export default savedVideosSlice.reducer; -------------------------------------------------------------------------------- /server/routes/users.js: -------------------------------------------------------------------------------- 1 | import express from "express"; 2 | import { 3 | update, 4 | deleteUser, 5 | getUser, 6 | subscribe, 7 | unsubscribe, 8 | like, 9 | dislike, 10 | } from "../controllers/user.js"; 11 | import { verifyToken } from "../verifyToken.js"; 12 | 13 | const router = express.Router(); 14 | // we need to verify because we don't verify any user can upadte any user 15 | //update user 16 | router.put("/:id", verifyToken, update); 17 | 18 | //delete user 19 | router.delete("/:id", verifyToken, deleteUser); 20 | 21 | //get a user 22 | router.get("/find/:id", getUser); 23 | 24 | //subscribe a user 25 | router.put("/sub/:id", verifyToken, subscribe); 26 | 27 | //unsubscribe a user 28 | router.put("/unsub/:id", verifyToken, unsubscribe); 29 | 30 | //like a video 31 | router.put("/like/:videoId", verifyToken, like); 32 | 33 | //dislike a video 34 | router.put("/dislike/:videoId", verifyToken, dislike); 35 | 36 | export default router; -------------------------------------------------------------------------------- /client/src/utils/errorMessage.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import styled from 'styled-components'; 3 | 4 | const StyledDialog = styled.div` 5 | background-color: #fff3cd; 6 | position:relative; 7 | border: 1px solid #ffeeba; 8 | padding: 28px; 9 | text-align: center; 10 | border-radius: 10px; 11 | color: #856404; 12 | font-weight: bold; 13 | margin : 10px; 14 | /* Add an exclamation icon before the message */ 15 | &::before { 16 | content: "!"; 17 | font-size: 1em; 18 | margin-right: 10px; 19 | } 20 | `; 21 | 22 | const ErrorMessage = ({ message }) => { 23 | return 24 | 25 | 26 | 27 | {message} 28 | ; 29 | }; 30 | 31 | export default ErrorMessage; 32 | -------------------------------------------------------------------------------- /client/src/pages/Search.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import { useLocation } from "react-router-dom"; 3 | import styled from "styled-components"; 4 | import Card from "../components/Card"; 5 | import { publicRequest } from "../config"; 6 | import LoadingSpinner from "../utils/spinsearch"; 7 | const Container = styled.div` 8 | display: flex; 9 | flex-wrap: wrap; 10 | gap: 10px; 11 | `; 12 | 13 | const Search = () => { 14 | const [videos, setVideos] = useState([]); 15 | const query = useLocation().search; 16 | const [load,setload]=useState(true); 17 | useEffect(() => { 18 | const fetchVideos = async () => { 19 | const res = await publicRequest.get(`/api/videos/search${query}`); 20 | setVideos(res.data); 21 | setload(false); 22 | }; 23 | fetchVideos(); 24 | }, [query]); 25 | 26 | return 27 | {load && }; 28 | {videos.map(video=>( 29 | 30 | ))} 31 | ; 32 | }; 33 | 34 | export default Search; -------------------------------------------------------------------------------- /client/src/pages/SavedVideos.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import styled from "styled-components"; 3 | import { useSelector } from "react-redux"; 4 | import Card from "../components/Card"; 5 | 6 | const Container = styled.div` 7 | padding: 20px; 8 | display: flex; 9 | flex-wrap: wrap; 10 | gap: 20px; 11 | `; 12 | 13 | const Title = styled.h1` 14 | color: ${({ theme }) => theme.text}; 15 | margin-bottom: 20px; 16 | padding: 0 20px; 17 | `; 18 | 19 | const SavedVideos = () => { 20 | const savedVideos = useSelector((state) => state.savedVideos.savedVideos); 21 | 22 | return ( 23 | <> 24 | Saved Videos 25 | 26 | {savedVideos.map((video) => ( 27 | 28 | ))} 29 | {savedVideos.length === 0 && ( 30 |
31 | No saved videos yet. Click the + button on any video to save it for later. 32 |
33 | )} 34 |
35 | 36 | ); 37 | }; 38 | 39 | export default SavedVideos; -------------------------------------------------------------------------------- /client/src/firebase.js: -------------------------------------------------------------------------------- 1 | // Import the functions you need from the SDKs you need 2 | import { initializeApp } from "firebase/app"; 3 | import { getAuth, GoogleAuthProvider } from "firebase/auth"; 4 | 5 | // TODO: Add SDKs for Firebase products that you want to use 6 | // https://firebase.google.com/docs/web/setup#available-libraries 7 | 8 | // Your web app's Firebase configuration 9 | 10 | const firebaseConfig = { 11 | 12 | apiKey: process.env.REACT_APP_FIREBASE_KEY, 13 | // authDomain: "fir-51a74.firebaseapp.com", 14 | // projectId: "fir-51a74", 15 | // storageBucket: "fir-51a74.appspot.com", 16 | // messagingSenderId: "377093495071", 17 | // appId: "1:377093495071:web:ad000dafa3ccddc3cf382a" 18 | authDomain: "test-72576.firebaseapp.com", 19 | projectId: "test-72576", 20 | storageBucket: "test-72576.appspot.com", 21 | messagingSenderId: "1027253522132", 22 | appId: "1:1027253522132:web:5845773db04a0b95f17541" 23 | }; 24 | 25 | // Initialize Firebase 26 | const app = initializeApp(firebaseConfig); 27 | export const auth = getAuth(); 28 | export const provider = new GoogleAuthProvider(); 29 | 30 | export default app; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Manan khandelwal 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Fixes Issue 4 | 5 | This PR fixes the following issues: 6 | 7 | #example 8 | 9 | 10 | 11 | ## Changes proposed 12 | 13 | Here comes all the changes proposed through this PR 14 | 15 | 16 | 20 | 21 | ## Check List (Check all the boxes which are applicable) 22 | 23 | - [ ] My code follows the code style of this project. 24 | - [ ] My change requires a change to the documentation. 25 | - [ ] I have updated the documentation accordingly. 26 | - [ ] All new and existing tests passed. 27 | - [ ] This PR does not contain plagiarized content. 28 | - [ ] The title of my pull request is a short description of the requested changes. 29 | 30 | 31 | 32 | ## Screenshots and video 33 | 34 | Add all the screenshots and a video which support your changes 35 | -------------------------------------------------------------------------------- /client/src/redux/store.js: -------------------------------------------------------------------------------- 1 | import { PersistGate } from "redux-persist/integration/react"; 2 | import { configureStore, combineReducers } from "@reduxjs/toolkit"; 3 | import userReducer from "./userSlice"; 4 | import videoReducer from "./videoSlice"; 5 | import savedVideosReducer from "./savedVideosSlice"; 6 | import { 7 | persistStore, 8 | persistReducer, 9 | FLUSH, 10 | REHYDRATE, 11 | PAUSE, 12 | PERSIST, 13 | PURGE, 14 | REGISTER, 15 | } from "redux-persist"; 16 | import storage from "redux-persist/lib/storage"; 17 | 18 | const persistConfig = { 19 | key: "root", 20 | version: 1, 21 | keyPrefix: "", 22 | storage, 23 | }; 24 | 25 | const rootReducer = combineReducers({ user: userReducer, video: videoReducer, savedVideos: savedVideosReducer }); 26 | 27 | const persistedReducer = persistReducer(persistConfig, rootReducer); 28 | 29 | export const store = configureStore({ 30 | reducer: persistedReducer, 31 | middleware: (getDefaultMiddleware) => 32 | getDefaultMiddleware({ 33 | serializableCheck: { 34 | ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER], 35 | }, 36 | }), 37 | }); 38 | 39 | export const persistor = persistStore(store) -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature request 2 | description: Suggest an idea for this project 3 | title: "[Feature]: " 4 | labels: [feature, Review Required] 5 | body: 6 | - type: textarea 7 | attributes: 8 | label: Is your feature request related to a problem? Please describe. 9 | description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 10 | placeholder: Ex. I'm always frustated when [...] 11 | validations: 12 | required: false 13 | - type: textarea 14 | attributes: 15 | label: Describe the solution you'd like 16 | description: A clear and concise description of what you want to happen. 17 | validations: 18 | required: false 19 | - type: textarea 20 | attributes: 21 | label: Describe alternatives you've considered 22 | description: A clear and concise description of any alternative solutions or features you've considered. 23 | validations: 24 | required: false 25 | - type: textarea 26 | attributes: 27 | label: Additional context 28 | description: Add any other context or screenshots about the feature request here. 29 | validations: 30 | required: false 31 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | server: 5 | build: 6 | context: ./server 7 | dockerfile: Dockerfile 8 | image: youtube-node 9 | container_name: myapp-node-server 10 | command: npm start 11 | volumes: 12 | # - ./server/:/usr/src/app 13 | # - /usr/src/app/node_modules 14 | - ./server/:/usr/src/app 15 | - /usr/src/app/node_modules 16 | ports: 17 | - "3001:3001" 18 | # depends_on: 19 | # - mongo 20 | env_file: ./server/.env 21 | environment: 22 | - NODE_ENV=development 23 | networks: 24 | - app-network 25 | # mongo: 26 | # image: mongo 27 | # volumes: 28 | # - data-volume:/data/db 29 | # ports: 30 | # - "27017:27017" 31 | # networks: 32 | # - app-network 33 | client: 34 | build: 35 | context: ./client 36 | dockerfile: Dockerfile 37 | image: youtube-react 38 | container_name: youtube-react-client 39 | command: npm start 40 | volumes: 41 | - ./client/:/usr/app 42 | - /usr/app/node_modules 43 | depends_on: 44 | - server 45 | ports: 46 | - "3000:3000" 47 | networks: 48 | - app-network 49 | 50 | networks: 51 | app-network: 52 | driver: bridge 53 | 54 | volumes: 55 | data-volume: 56 | node_modules: 57 | web-root: 58 | driver: local -------------------------------------------------------------------------------- /client/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 16 | 18 | 19 | 40 | VideoTube 41 | 42 | 43 | 44 |
45 | 46 | 47 | -------------------------------------------------------------------------------- /client/src/pages/Home.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import styled from "styled-components"; 3 | import Card from "../components/Card"; 4 | import { publicRequest, userRequest } from "../config"; 5 | import LoadingSpinner from "../utils/spinner"; 6 | 7 | const Container = styled.div` 8 | display: grid; 9 | grid-template-columns: repeat(3, auto); 10 | grid-gap: 2rem; 11 | @media (max-width: 480px) { 12 | grid-template-columns: repeat(1, auto); 13 | } 14 | `; 15 | 16 | const Home = ({ type }) => { 17 | const [videos, setVideos] = useState([]); 18 | const [loading, setLoading] = useState(false); 19 | useEffect(() => { 20 | const fetchVideos = async () => { 21 | setLoading(true); 22 | if (type === "sub") { 23 | const res = await userRequest.get(`/api/videos/${type}`); 24 | setVideos(res.data); 25 | } else if (type === "settings") { 26 | const res = await userRequest.get(`/api/videos/${type}`); 27 | setVideos(res.data); 28 | } else { 29 | const res = await publicRequest.get(`/api/videos/${type}`); 30 | setVideos(res.data); 31 | } 32 | setLoading(false); 33 | }; 34 | fetchVideos(); 35 | }, [type]); 36 | 37 | return ( 38 | <> 39 | 40 | {loading && } 41 | {videos.map((video) => ( 42 | 43 | ))} 44 | 45 | 46 | ); 47 | }; 48 | 49 | export default Home; 50 | -------------------------------------------------------------------------------- /server/controllers/comment.js: -------------------------------------------------------------------------------- 1 | import { createError } from "../error.js"; 2 | import Comment from "../models/Comment.js"; 3 | import Video from "../models/Video.js"; 4 | import User from "../models/User.js"; 5 | 6 | export const addComment = async (req, res, next) => { 7 | const newComment = new Comment({ ...req.body, userId: req.user.id }); 8 | try { 9 | const savedComment = await newComment.save(); 10 | res.status(200).send(savedComment); 11 | } catch (err) { 12 | next(err); 13 | } 14 | }; 15 | 16 | export const deleteComment = async (req, res, next) => { 17 | try { 18 | console.log(req.params.id); 19 | const comment = await Comment.findById(req.params.id); 20 | const video = await Video.findById(comment.videoId); 21 | const currentUser = await User.findById(req.user.id); 22 | 23 | if ( 24 | req.user.id === comment.userId || 25 | req.user.id === video.userId || 26 | currentUser.isSuperUser 27 | ) { 28 | await Comment.findByIdAndDelete(req.params.id); 29 | res.status(200).json("The comment has been deleted."); 30 | } else { 31 | return next(createError(403, "You can delete ony your comment!")); 32 | } 33 | } catch (err) { 34 | console.log(err); 35 | next(err); 36 | } 37 | }; 38 | 39 | export const getComments = async (req, res, next) => { 40 | try { 41 | const comments = await Comment.find({ videoId: req.params.videoId }); 42 | res.status(200).json(comments); 43 | } catch (err) { 44 | next(err); 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /client/src/redux/videoSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | 3 | const initialState = { 4 | currentVideo: null, 5 | loading: false, 6 | error: false, 7 | }; 8 | 9 | export const videoSlice = createSlice({ 10 | name: "video", 11 | initialState, 12 | reducers: { 13 | fetchStart: (state) => { 14 | state.loading = true; 15 | }, 16 | fetchSuccess: (state, action) => { 17 | state.loading = false; 18 | state.currentVideo = action.payload; 19 | }, 20 | fetchFailure: (state) => { 21 | state.loading = false; 22 | state.error = true; 23 | }, 24 | like: (state, action) => { 25 | if (!state.currentVideo.likes.includes(action.payload)) { 26 | state.currentVideo.likes.push(action.payload); 27 | state.currentVideo.dislikes.splice( 28 | state.currentVideo.dislikes.findIndex( 29 | (userId) => userId === action.payload 30 | ), 31 | 1 32 | ); 33 | } 34 | }, 35 | dislike: (state, action) => { 36 | if (!state.currentVideo.dislikes.includes(action.payload)) { 37 | state.currentVideo.dislikes.push(action.payload); 38 | state.currentVideo.likes.splice( 39 | state.currentVideo.likes.findIndex( 40 | (userId) => userId === action.payload 41 | ), 42 | 1 43 | ); 44 | } 45 | }, 46 | }, 47 | }); 48 | 49 | export const { fetchStart, fetchSuccess, fetchFailure, like, dislike } = videoSlice.actions; 50 | 51 | export default videoSlice.reducer; -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug report 2 | description: Create a report to help us improve 3 | title: "[Bug]: " 4 | labels: [bug, Priority-High, want fix, Review Required] 5 | body: 6 | - type: textarea 7 | attributes: 8 | label: Describe the bug 9 | description: A clear and concise description of what the bug is 10 | validations: 11 | required: false 12 | - type: textarea 13 | attributes: 14 | label: To Reproduce 15 | description: | 16 | Steps to reproduce the behavior. 17 | 1. Go to '...' 18 | 2. Click on '...' 19 | 3. Scroll down to '...' 20 | 4. See error 21 | validations: 22 | required: false 23 | - type: textarea 24 | attributes: 25 | label: Expected Behavior 26 | description: A clear and concise description of what you expected to happen. 27 | validations: 28 | required: false 29 | - type: textarea 30 | attributes: 31 | label: Screenshot/ Video 32 | description: If applicable, add screenshots to help explain your problem. 33 | validations: 34 | required: false 35 | - type: textarea 36 | attributes: 37 | label: Desktop (please complete the following information) 38 | description: | 39 | Device - [e.g. iPhone6] 40 | OS - [e.g. iOS8.1] 41 | Browser [e.g. stock browser, safari] 42 | Version [e.g. 22] 43 | validations: 44 | required: false 45 | - type: textarea 46 | attributes: 47 | label: Additional context 48 | description: Add any other context about the problem here. 49 | validations: 50 | required: false 51 | -------------------------------------------------------------------------------- /client/src/config.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | // export const axiosInstance = axios.create({ 4 | // baseURL : "https://mnnyotube.herokuapp.com/" 5 | // }) 6 | 7 | // export const axiosInstance = axios.create({ 8 | // baseURL : "https://youtube-backend-93iq.onrender.com/" 9 | // }) 10 | 11 | // export const axiosInstance = axios.create({ 12 | // baseURL : "http://localhost:3001/" 13 | // }) 14 | 15 | // import axios from "axios"; 16 | 17 | // //let axios = Axios.create({ withCredentials: true }); 18 | 19 | // // axios.defaults.withCredentials = true; 20 | 21 | // export const axiosInstance = axios.create({ 22 | // baseURL : "http://localhost:5000/" 23 | // }); 24 | const BASE_URL = "http://localhost:3001/"; 25 | // const TOKEN = 26 | // JSON.parse(JSON.parse(localStorage.getItem("persist:root")).user).currentUser 27 | // .accessToken || ""; 28 | // console.log(localStorage.getItem("root")); 29 | const user = JSON.parse(localStorage.getItem("root"))?.user; 30 | //console.log(user); 31 | var TOKEN; 32 | const currentUser = user && JSON.parse(user).currentUser; 33 | TOKEN = currentUser?.token; 34 | //console.log(TOKEN); 35 | // if(JSON.parse(JSON.parse(localStorage.getItem("root"))?.user).currentUser['token'] != null) { 36 | // var TOKEN; 37 | // try { 38 | // TOKEN = JSON.parse(JSON.parse(localStorage.getItem("root"))?.user).currentUser['token']; 39 | // console.log(TOKEN); 40 | // } catch (error) { 41 | // console.log(error); 42 | // } 43 | 44 | // console.log(TOKEN); 45 | // } 46 | 47 | export const publicRequest = axios.create({ 48 | baseURL: BASE_URL, 49 | }); 50 | 51 | export const userRequest = axios.create({ 52 | baseURL: BASE_URL, 53 | headers: { token: `Bearer ${TOKEN}` }, 54 | }); 55 | -------------------------------------------------------------------------------- /client/src/redux/userSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | 3 | const initialState = { 4 | currentUser: null, 5 | loading: false, 6 | error: false, 7 | }; 8 | 9 | export const userSlice = createSlice({ 10 | name : 'user', 11 | initialState, 12 | reducers : { 13 | updateStart : (state) => { 14 | state.loading = true; 15 | } , 16 | updateFailure : (state) => { 17 | state.loading = false; 18 | state.error = true; 19 | } , 20 | updateSuccess : (state, action) => { 21 | state.loading = false; 22 | state.currentUser = action.payload; 23 | } , 24 | loginStart : (state) => { 25 | state.loading = true; 26 | }, 27 | loginSuccess : (state,action) => { 28 | state.loading = false; 29 | state.currentUser = action.payload; 30 | }, 31 | loginFailure : (state) => { 32 | state.loading = false; 33 | state.error = true; 34 | }, 35 | logout : (state) => { 36 | state.currentUser = null; 37 | state.loading = false; 38 | state.error = false; 39 | }, 40 | subscription: (state, action) => { 41 | if (state.currentUser.subscribedUsers.includes(action.payload)) { 42 | state.currentUser.subscribedUsers.splice( 43 | state.currentUser.subscribedUsers.findIndex( 44 | (channelId) => channelId === action.payload 45 | ), 46 | 1 47 | ); 48 | } else { 49 | state.currentUser.subscribedUsers.push(action.payload); 50 | } 51 | }, 52 | }, 53 | }); 54 | 55 | export const { updateStart, updateFailure, updateSuccess, loginStart, loginSuccess, loginFailure, logout, subscription} = userSlice.actions; 56 | 57 | export default userSlice.reducer; -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "video_app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@emotion/react": "^11.9.3", 7 | "@emotion/styled": "^11.9.3", 8 | "@mui/icons-material": "^5.8.4", 9 | "@mui/material": "^5.8.6", 10 | "@reduxjs/toolkit": "^1.8.3", 11 | "@testing-library/jest-dom": "^5.16.4", 12 | "@testing-library/react": "^13.1.1", 13 | "@testing-library/user-event": "^13.5.0", 14 | "axios": "^0.27.2", 15 | "dotenv": "^16.0.1", 16 | "firebase": "^9.9.0", 17 | "is-online": "^10.0.0", 18 | "notistack": "^2.0.8", 19 | "react": "^18.0.0", 20 | "react-dom": "^18.0.0", 21 | "react-redux": "^8.0.2", 22 | "react-router-dom": "^6.3.0", 23 | "react-scripts": "5.0.1", 24 | "react-speech-recognition": "^3.10.0", 25 | "react-swipeable": "^7.0.0", 26 | "redux-persist": "^6.0.0", 27 | "styled-components": "^5.3.5", 28 | "timeago.js": "^4.0.2", 29 | "web-vitals": "^2.1.4" 30 | }, 31 | "scripts": { 32 | "start": "react-scripts start", 33 | "build": "react-scripts build", 34 | "test": "react-scripts test", 35 | "eject": "react-scripts eject" 36 | }, 37 | "eslintConfig": { 38 | "extends": [ 39 | "react-app", 40 | "react-app/jest" 41 | ] 42 | }, 43 | "browserslist": { 44 | "production": [ 45 | ">0.2%", 46 | "not dead", 47 | "not op_mini all" 48 | ], 49 | "development": [ 50 | "last 1 chrome version", 51 | "last 1 firefox version", 52 | "last 1 safari version" 53 | ] 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /server/index.js: -------------------------------------------------------------------------------- 1 | import express, { application } from "express"; 2 | import mongoose from "mongoose"; 3 | import dotenv from "dotenv"; 4 | import userRoutes from "./routes/users.js"; 5 | import videoRoutes from "./routes/videos.js"; 6 | import commentRoutes from "./routes/comments.js"; 7 | import authRoutes from "./routes/auth.js"; 8 | import reportRoutes from "./routes/reports.js"; 9 | import cookieParser from "cookie-parser"; 10 | import cors from "cors"; 11 | const app = express(); 12 | 13 | dotenv.config(); 14 | // const corsOptions = { 15 | // origin: 'http://localhost:3000', 16 | // optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204 17 | // } 18 | app.use(cors()); 19 | // to connect our application to mongodb 20 | const connect = async () => { 21 | try { 22 | const conn = await mongoose.connect(process.env.MONGO, { 23 | useNewUrlParser: true, 24 | useUnifiedTopology: true, 25 | }); 26 | 27 | console.log(`MongoDB Connected: ${conn.connection.host}`); 28 | } catch (error) { 29 | console.log(error); 30 | process.exit(1); 31 | } 32 | }; 33 | 34 | //middlewares 35 | app.use(cookieParser()); 36 | app.use(express.json()); 37 | // app.use(express.urlencoded({ extended: false })) 38 | app.use("/api/auth", authRoutes); 39 | app.use("/api/users", userRoutes); 40 | app.use("/api/videos/", videoRoutes); 41 | app.use("/api/comments", commentRoutes); 42 | app.use("/api/reports", reportRoutes); 43 | 44 | //error handler - to give error messages so that we don't have to implement catch error for every request 45 | app.use((err, req, res, next) => { 46 | const status = err.status || 500; 47 | const message = err.message || "Something went wrong!"; 48 | return res.status(status).json({ 49 | success: false, 50 | status, 51 | message, 52 | }); 53 | }); 54 | 55 | app.listen(process.env.PORT || 5000, () => { 56 | connect(); 57 | console.log("Connected to Server"); 58 | }); 59 | -------------------------------------------------------------------------------- /server/controllers/auth.js: -------------------------------------------------------------------------------- 1 | import mongoose from "mongoose"; 2 | import User from "../models/User.js"; 3 | import bcrypt from "bcryptjs"; 4 | import { createError } from "../error.js"; 5 | import jwt from "jsonwebtoken"; 6 | import { NONAME } from "dns"; 7 | 8 | export const signup = async (req, res, next) => { 9 | try { 10 | const salt = bcrypt.genSaltSync(10); 11 | const hash = bcrypt.hashSync(req.body.password, salt); 12 | const newUser = new User({ ...req.body, password: hash }); 13 | 14 | await newUser.save(); 15 | res.status(200).send("User has been created!"); 16 | } catch (err) { 17 | next(err); 18 | } 19 | }; 20 | 21 | export const signin = async (req, res, next) => { 22 | try { 23 | const user = await User.findOne({name: req.body.name}); 24 | if(!user) return next(createError(404, "User not found!")); 25 | // try { 26 | 27 | // await res.cookie("access_token", token,{ 28 | // httpOnly:true, 29 | // samesite:"strict", 30 | // secure: true, 31 | // }); 32 | // } catch (error) { 33 | // console.log(error); 34 | // } 35 | 36 | 37 | const isCorrect = await bcrypt.compare(req.body.password, user.password); 38 | if (!isCorrect) return next(createError(400, "Wrong Credentials!")); 39 | 40 | const { password, ...others } = user._doc; // as we don't want to dend our password in response 41 | const token = jwt.sign({ id: user._id }, process.env.JWT); 42 | 43 | res.status(200).json({token,...others}); 44 | 45 | } catch (error) { 46 | next(error); 47 | } 48 | }; 49 | 50 | export const googleAuth = async (req, res, next) => { 51 | try { 52 | const user = await User.findOne({ email: req.body.email }); 53 | if (user) { 54 | console.log(user._id.toString('hex')); 55 | const token = jwt.sign({ id: user._id.toString('hex') }, process.env.JWT); 56 | res 57 | .status(200) 58 | .json({token,...user._doc}); 59 | } else { 60 | const newUser = new User({ 61 | ...req.body, 62 | fromGoogle: true, 63 | }); 64 | const savedUser = await newUser.save(); 65 | const token = jwt.sign({ id: savedUser._id }, process.env.JWT); 66 | res.status(200).json({token,...savedUser._doc}); 67 | } 68 | } catch (err) { 69 | next(err); 70 | } 71 | }; -------------------------------------------------------------------------------- /client/src/components/Comment.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import styled from "styled-components"; 3 | import { userRequest } from "../config"; 4 | import { useSelector } from "react-redux"; 5 | import DeleteIcon from "@mui/icons-material/Delete"; 6 | 7 | const Container = styled.div` 8 | display: flex; 9 | gap: 10px; 10 | margin: 30px 0px; 11 | `; 12 | 13 | const Avatar = styled.img` 14 | width: 50px; 15 | height: 50px; 16 | border-radius: 50%; 17 | `; 18 | 19 | const Button = styled.div` 20 | display: flex; 21 | align-items: center; 22 | gap: 5px; 23 | cursor: pointer; 24 | `; 25 | 26 | const Details = styled.div` 27 | display: flex; 28 | flex-direction: column; 29 | gap: 10px; 30 | color: ${({ theme }) => theme.text}; 31 | `; 32 | const Name = styled.span` 33 | font-size: 13px; 34 | font-weight: 500; 35 | `; 36 | 37 | const Date = styled.span` 38 | font-size: 12px; 39 | font-weight: 400; 40 | color: ${({ theme }) => theme.textSoft}; 41 | margin-left: 5px; 42 | `; 43 | 44 | const Text = styled.span` 45 | font-size: 14px; 46 | `; 47 | 48 | const Comment = ({ comment, viid }) => { 49 | const { currentUser } = useSelector((state) => state.user); 50 | const [channel, setChannel] = useState({}); 51 | 52 | useEffect(() => { 53 | const fetchComment = async () => { 54 | const res = await userRequest.get(`/api/users/find/${comment.userId}`); 55 | setChannel(res.data); 56 | }; 57 | fetchComment(); 58 | }, [comment.userId]); 59 | 60 | const handleDelete = async () => { 61 | try { 62 | await userRequest.delete(`/api/comments/${comment._id}`); 63 | window.location.reload(); 64 | } catch (error) { 65 | console.log(comment); 66 | console.log(error); 67 | } 68 | }; 69 | 70 | return ( 71 | 72 | 73 |
74 | 75 | {channel.name} 1 day ago 76 | 77 | {comment.desc} 78 | {currentUser?._id === comment.userId || currentUser?.isSuperUser ? ( 79 | 82 | ) : ( 83 | <> 84 | )} 85 |
86 |
87 | ); 88 | }; 89 | 90 | export default Comment; 91 | -------------------------------------------------------------------------------- /client/src/components/ReportModal.jsx: -------------------------------------------------------------------------------- 1 | import { Button, Dialog, Input } from "@mui/material"; 2 | import { useState } from "react"; 3 | import { userRequest } from "../config"; 4 | import { useSelector } from "react-redux"; 5 | 6 | const ReportIssueModal = (props) => { 7 | const { currentUser } = useSelector((state) => state.user); 8 | const { openReportModal, setOpenReportModal } = props; 9 | const [issueText, setIssueText] = useState(""); 10 | 11 | const handleReportSumbit = async (e) => { 12 | e.preventDefault(); 13 | try { 14 | const resp = await userRequest.post("/api/reports/new", { 15 | userId: currentUser?._id, 16 | issue: issueText, 17 | }); 18 | resp.status === 200 && window.alert(`Issue Reported Successfully!`); 19 | setOpenReportModal(false); 20 | } catch (err) { 21 | console.error(err); 22 | } 23 | }; 24 | 25 | return ( 26 | setOpenReportModal(false)} 30 | > 31 |
40 |

47 | Report Issue 48 |

49 | 50 | setIssueText(e.target.value)} 57 | sx={{ 58 | boxSizing: "border-box", 59 | borderRadius: "4px", 60 | width: "80%", 61 | margin: "2rem 1rem 1rem 1rem", 62 | color: "var(--color)", 63 | backgroundColor: "white", 64 | overflow: "auto", 65 | padding: "12px 6px", 66 | outline: "1px solid black", 67 | }} 68 | /> 69 | 70 |
71 |
72 | ); 73 | }; 74 | 75 | export default ReportIssueModal; 76 | -------------------------------------------------------------------------------- /client/src/components/Comments.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import { useSelector } from "react-redux"; 3 | import styled from "styled-components"; 4 | import { publicRequest, userRequest } from "../config"; 5 | import Comment from "./Comment"; 6 | const Container = styled.div``; 7 | 8 | const NewComment = styled.div` 9 | display: flex; 10 | justify-content: center; 11 | gap: 10px; 12 | @media (max-width: 480px) { 13 | justify-content: space-evenly; 14 | gap: 0px; 15 | } 16 | `; 17 | 18 | const Avatar = styled.img` 19 | width: 50px; 20 | height: 50px; 21 | border-radius: 50%; 22 | `; 23 | 24 | const Input = styled.input` 25 | border: none; 26 | border-bottom: 1px solid ${({ theme }) => theme.soft}; 27 | color: ${({ theme }) => theme.text}; 28 | background-color: transparent; 29 | outline: none; 30 | padding: 5px; 31 | width: 100%; 32 | @media (max-width: 480px) { 33 | width: 80%; 34 | } 35 | `; 36 | const AddComment = styled.button` 37 | background-color: #87ceeb; 38 | font-weight: 500; 39 | color: white; 40 | border: none; 41 | justify-content: center; 42 | border-radius: 10px; 43 | height: max-content; 44 | padding: 10px 20px; 45 | cursor: pointer; 46 | @media (max-width: 480px) { 47 | margin-right: 25px; 48 | } 49 | `; 50 | 51 | const Comments = ({ videoId }) => { 52 | const { currentUser } = useSelector((state) => state.user); 53 | 54 | const [comments, setComments] = useState([]); 55 | const [newComment, setNewComment] = useState(""); 56 | 57 | useEffect(() => { 58 | const fetchComments = async () => { 59 | try { 60 | const res = await publicRequest.get(`/api/comments/${videoId}`); 61 | setComments(res.data); 62 | } catch (err) {} 63 | }; 64 | fetchComments(); 65 | }, [videoId]); 66 | 67 | //TODO: ADD NEW COMMENT FUNCTIONALITY 68 | const fetchComments = async () => { 69 | try { 70 | const res = await publicRequest.get(`/api/comments/${videoId}`); 71 | setComments(res.data); 72 | } catch (err) {} 73 | }; 74 | const handleComment = async () => { 75 | try { 76 | await userRequest.post(`/api/comments/`,{ 77 | videoId : videoId, 78 | desc : newComment 79 | }); 80 | fetchComments(); 81 | setNewComment(''); 82 | } catch (error) { 83 | console.log(error); 84 | } 85 | }; 86 | 87 | return ( 88 | 89 | 90 | 91 | setNewComment(e.target.value)} 95 | /> 96 | comment 97 | 98 | {comments.map((comment) => ( 99 | 100 | ))} 101 | 102 | ); 103 | }; 104 | 105 | export default Comments; 106 | -------------------------------------------------------------------------------- /server/controllers/user.js: -------------------------------------------------------------------------------- 1 | import { createError } from "../error.js"; 2 | import User from "../models/User.js"; 3 | import Video from "../models/Video.js"; 4 | 5 | export const update = async (req, res, next) => { 6 | if (req.params.id === req.user.id) { 7 | try { 8 | const updatedUser = await User.findByIdAndUpdate( 9 | req.params.id, 10 | { 11 | $set: req.body, 12 | }, 13 | { new: true } 14 | ); 15 | res.status(200).json(updatedUser); 16 | } catch (err) { 17 | next(err); 18 | } 19 | } else { 20 | return next(createError(403, "You can update only your account!")); 21 | } 22 | }; 23 | 24 | export const deleteUser = async (req, res, next) => { 25 | if (req.params.id === req.user.id) { 26 | try { 27 | await User.findByIdAndDelete(req.params.id); 28 | res.status(200).json("User has been deleted."); 29 | } catch (err) { 30 | next(err); 31 | } 32 | } else { 33 | return next(createError(403, "You can delete only your account!")); 34 | } 35 | }; 36 | 37 | export const getUser = async (req, res, next) => { 38 | try { 39 | const user = await User.findById(req.params.id); 40 | res.status(200).json(user); 41 | } catch (err) { 42 | next(err); 43 | } 44 | }; 45 | 46 | export const subscribe = async (req, res, next) => { 47 | try { 48 | await User.findByIdAndUpdate(req.user.id, { 49 | $push: { subscribedUsers: req.params.id }, // pushing user id to subscribedUsers array 50 | }); 51 | await User.findByIdAndUpdate(req.params.id, { 52 | $inc: { subscribers: 1 }, // incrementing subscribers 53 | }); 54 | res.status(200).json("Subscription successfull.") 55 | } catch (err) { 56 | next(err); 57 | } 58 | }; 59 | 60 | export const unsubscribe = async (req, res, next) => { 61 | try { 62 | try { 63 | await User.findByIdAndUpdate(req.user.id, { 64 | $pull: { subscribedUsers: req.params.id }, 65 | }); 66 | await User.findByIdAndUpdate(req.params.id, { 67 | $inc: { subscribers: -1 }, 68 | }); 69 | res.status(200).json("Unsubscription successfull.") 70 | } catch (err) { 71 | next(err); 72 | } 73 | } catch (err) { 74 | next(err); 75 | } 76 | }; 77 | 78 | export const like = async (req, res, next) => { 79 | const id = req.user.id; 80 | const videoId = req.params.videoId; 81 | try { 82 | await Video.findByIdAndUpdate(videoId,{ 83 | $addToSet:{likes:id}, 84 | $pull:{dislikes:id} 85 | }) 86 | res.status(200).json("The video has been liked.") 87 | } catch (err) { 88 | next(err); 89 | } 90 | }; 91 | 92 | export const dislike = async (req, res, next) => { 93 | const id = req.user.id; 94 | const videoId = req.params.videoId; 95 | try { 96 | await Video.findByIdAndUpdate(videoId,{ 97 | $addToSet:{dislikes:id}, 98 | $pull:{likes:id} 99 | }) 100 | res.status(200).json("The video has been disliked.") 101 | } catch (err) { 102 | next(err); 103 | } 104 | }; -------------------------------------------------------------------------------- /client/src/components/Model.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import styled from 'styled-components' 3 | import { useNavigate } from 'react-router-dom' 4 | import Avatar from "../assests/images/Avatar.png" 5 | import { useSelector } from 'react-redux' 6 | const DropDown = styled.div` 7 | position: absolute; 8 | top: 60px; 9 | z-index:10; 10 | padding: 10px 0; 11 | box-sizing: border-box; 12 | right: 20px; 13 | border-radius:8px; 14 | background-color: #202020; 15 | color: ${({ theme }) => theme.text};//var(--text-main); 16 | font-family: 'Roboto'; 17 | ` 18 | 19 | const DropDownItem = styled.div` 20 | display: flex; 21 | align-items: center; 22 | padding: 7px 20px; 23 | cursor: pointer; 24 | transition: .2s; 25 | 26 | &:hover{ 27 | background-color: ${({ theme }) => theme.secondary_light_color} 28 | } 29 | 30 | span{ 31 | font-size: 30px; 32 | } 33 | 34 | p{ 35 | margin: 0; 36 | font-size: 15px; 37 | margin-left: 15px; 38 | } 39 | 40 | ` 41 | 42 | const EditProfile = styled(DropDownItem)` 43 | padding: 4px 10px; 44 | display: flex; 45 | img{ 46 | width: 40px; 47 | height: 40px; 48 | border-radius: 50%; 49 | cursor: pointer; 50 | } 51 | ` 52 | const Line = styled.div` 53 | width: 100%; 54 | background-color: ${({ theme }) => theme.hover_text_color}; 55 | height: 1px; 56 | margin: 8px 0; 57 | position: relative; 58 | border-radius: 4px; 59 | ` 60 | 61 | const Model = () => { 62 | 63 | const navigate = useNavigate() 64 | const { currentUser } = useSelector(state => state.user) 65 | return ( 66 | 67 | navigate('/profile')}> 68 | Your Avatar 69 |

Edit Profile

70 |
71 | 72 | <> 73 | 74 | 75 | account_box 76 | 77 |

Your Channel

78 |
79 | 80 | 81 | play_circle 82 | 83 |

Youtube Studio

84 |
85 | 86 | 87 | logout 88 | 89 |

Sign Out

90 |
91 | 92 | 93 | 94 | 95 | 96 |
97 | ) 98 | } 99 | 100 | export default Model 101 | -------------------------------------------------------------------------------- /client/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /server/controllers/video.js: -------------------------------------------------------------------------------- 1 | import User from "../models/User.js"; 2 | import Video from "../models/Video.js"; 3 | import { createError } from "../error.js"; 4 | import { response } from "express"; 5 | 6 | export const addVideo = async (req, res, next) => { 7 | const newVideo = new Video({ userId: req.user.id, ...req.body }); 8 | try { 9 | const savedVideo = await newVideo.save(); 10 | res.status(200).json(savedVideo); 11 | } catch (err) { 12 | next(err); 13 | } 14 | }; 15 | 16 | export const updateVideo = async (req, res, next) => { 17 | try { 18 | const video = await Video.findById(req.params.id); 19 | if (!video) return next(createError(404, "Video not found!")); 20 | if (req.user.id === video.userId) { 21 | const updatedVideo = await Video.findByIdAndUpdate( 22 | req.params.id, 23 | { 24 | $set: req.body, 25 | }, 26 | { new: true } 27 | ); 28 | res.status(200).json(updatedVideo); 29 | } else { 30 | return next(createError(403, "You can update only your video!")); 31 | } 32 | } catch (err) { 33 | next(err); 34 | } 35 | }; 36 | 37 | export const deleteVideo = async (req, res, next) => { 38 | try { 39 | const video = await Video.findById(req.params.id); 40 | const currentUser = await User.findById(req.user.id); 41 | if (!video) return next(createError(404, "Video not found!")); 42 | if (req.user.id === video.userId || currentUser.isSuperUser) { 43 | await Video.findByIdAndDelete(req.params.id); 44 | res.status(200).json("The video has been deleted."); 45 | } else { 46 | return next(createError(403, "You can delete only your video!")); 47 | } 48 | } catch (err) { 49 | next(err); 50 | } 51 | }; 52 | 53 | export const getVideo = async (req, res, next) => { 54 | try { 55 | const video = await Video.findById(req.params.id); 56 | res.status(200).json(video); 57 | } catch (err) { 58 | next(err); 59 | } 60 | }; 61 | 62 | export const addView = async (req, res, next) => { 63 | try { 64 | await Video.findByIdAndUpdate(req.params.id, { 65 | $inc: { views: 1 }, 66 | }); 67 | res.status(200).json("The view has been increased."); 68 | } catch (error) { 69 | next(error); 70 | } 71 | }; 72 | 73 | export const random = async (req, res, next) => { 74 | try { 75 | const videos = await Video.aggregate([{ $sample: { size: 20 } }]); 76 | res.status(200).json(videos); 77 | } catch (error) { 78 | next(error); 79 | } 80 | }; 81 | 82 | export const trend = async (req, res, next) => { 83 | try { 84 | const videos = await Video.find().sort({ views: -1 }); 85 | res.status(200).json(videos); 86 | } catch (error) { 87 | next(error); 88 | } 89 | }; 90 | 91 | export const sub = async (req, res, next) => { 92 | // in subscribed users array we have stored user ids so we gonna find videos of all the userids 93 | try { 94 | const user = await User.findById(req.user.id); 95 | const subscribedChannels = user.subscribedUsers; 96 | 97 | const list = await Promise.all( 98 | subscribedChannels.map(async (channelId) => { 99 | return await Video.find({ userId: channelId }); 100 | }) 101 | ); 102 | res.status(200).json(list.flat().sort((a, b) => b.createdAt - a.createdAt)); 103 | } catch (error) { 104 | next(error); 105 | } 106 | }; 107 | 108 | export const set = async (req, res, next) => { 109 | try { 110 | const videos = await Video.find({ userId: req.user.id }); 111 | res.status(200).json(videos); 112 | } catch (error) { 113 | next(error); 114 | } 115 | }; 116 | 117 | export const getByTag = async (req, res, next) => { 118 | const tags = req.query.tags.split(","); // query is part of url after the question mark 119 | try { 120 | const videos = await Video.find({ tags: { $in: tags } }).limit(20); 121 | res.status(200).json(videos); 122 | } catch (error) { 123 | next(error); 124 | } 125 | }; 126 | 127 | export const search = async (req, res, next) => { 128 | const query = req.query.q; // title will be our query 129 | try { 130 | const videos = await Video.find({ 131 | title: { $regex: query, $options: "i" }, 132 | }).limit(40); 133 | res.status(200).json(videos); 134 | } catch (err) { 135 | next(err); 136 | } 137 | }; 138 | -------------------------------------------------------------------------------- /client/src/App.js: -------------------------------------------------------------------------------- 1 | import { darkTheme, lightTheme } from "./utils/Theme"; 2 | import styled, { ThemeProvider } from "styled-components"; 3 | import Menu from "./components/Menu"; 4 | import Navbar from "./components/Navbar"; 5 | import { useState, React } from "react"; 6 | import { BrowserRouter, Routes, Route } from "react-router-dom"; 7 | import Home from "./pages/Home"; 8 | import Video from "./pages/Video"; 9 | import SignIn from "./pages/SignIn"; 10 | import Search from "./pages/Search"; 11 | import { useSelector } from "react-redux"; 12 | // import { useSwipeable } from "react-swipeable"; 13 | import useNetworkStatus from "./utils/useNetworkStatus"; 14 | import Profile from "./pages/Profile"; 15 | import ReportIssueModal from "./components/ReportModal"; 16 | import SavedVideos from "./pages/SavedVideos"; 17 | 18 | const Container = styled.div` 19 | display: flex; 20 | 21 | @media (max-width: 480px) { 22 | overflow-x: hidden; 23 | justify-content: center; 24 | align-items: center; 25 | } 26 | `; 27 | 28 | // const SwipeContainer = styled.div` 29 | // ${ 30 | // "" /* background-color: ${({ theme }) => theme.bg}; 31 | // &.open { 32 | // display : none; 33 | // } */ 34 | // } 35 | // `; 36 | 37 | const Main = styled.div` 38 | // flex: 7; 39 | width: 100%; 40 | background-color: ${({ theme }) => theme.bg}; 41 | /* padding:0; 42 | margin:0 */ 43 | `; 44 | 45 | const Wrapper = styled.div` 46 | padding: 0; 47 | /* gap: 0; */ 48 | padding: 22px 96px; 49 | @media (max-width: 480px) { 50 | padding: 0; 51 | } 52 | `; 53 | 54 | const NetworkStatus = styled.div` 55 | background-color: #fff3cd; 56 | border: 1px solid #ffeeba; 57 | padding: 28px; 58 | text-align: center; 59 | border-radius: 10px; 60 | color: #856404; 61 | font-weight: bold; 62 | margin: 10px; 63 | z-index: 10px; 64 | `; 65 | 66 | function App() { 67 | const [darkMode, setDarkMode] = useState(true); 68 | const [isOpen, setIsOpen] = useState(false); 69 | const [openReportModal, setOpenReportModal] = useState(false); 70 | 71 | const handleToggle = () => { 72 | setIsOpen(!isOpen); 73 | }; 74 | 75 | // const swipeHandlers = useSwipeable({ 76 | // onSwipedLeft: handleToggle, 77 | // onSwipedRight: handleToggle, 78 | // }); 79 | 80 | const { currentUser } = useSelector((state) => state.user); 81 | const status = useNetworkStatus(); 82 | 83 | return ( 84 | 85 | {status ? null : ( 86 | You are currently Offline ! 87 | )} 88 | 89 | 90 | 96 |
97 | 98 |
99 | 100 | 104 | 105 | 106 | } /> 107 | } 111 | /> 112 | } /> 113 | } /> 114 | } /> 115 | } /> 116 | } /> 117 | : } 120 | /> 121 | 122 | } /> 123 | 124 | 125 | 126 | 127 |
128 |
129 | 130 | 131 | 132 | ); 133 | } 134 | 135 | export default App; 136 | -------------------------------------------------------------------------------- /client/src/pages/Profile.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react' 2 | import styled from 'styled-components' 3 | import { userRequest } from '../config'; 4 | import { useDispatch, useSelector } from "react-redux"; 5 | import { useNavigate } from "react-router-dom"; 6 | import { updateStart, updateFailure, updateSuccess } from "../redux/userSlice"; 7 | 8 | const ProfileModel = styled.div` 9 | height: calc(100vh - 56px); 10 | color: ${({ theme }) => theme.text}; 11 | display: flex; 12 | align-items: center; 13 | justify-content: center; 14 | padding: 30px; 15 | box-sizing: border-box; 16 | min-width:200px; 17 | 18 | 19 | ` 20 | const UpdateProfile = styled.form` 21 | background-color: #5E5E5E ; 22 | width: 40%; 23 | color:#fff; 24 | background-color: ${({ theme }) => theme.bgLighter}; 25 | border-radius: 10px; 26 | box-sizing: border-box; 27 | padding: 30px; 28 | display: flex; 29 | flex-direction: column; 30 | align-items: center; 31 | 32 | ` 33 | const Inputs = styled.input` 34 | box-sizing: border-box; 35 | padding: 1vmax 2vmax; 36 | width: 80%; 37 | background-color: transparent; 38 | border-radius: 10px; 39 | border: 1px solid #ccc; 40 | margin: 2vmax; 41 | font: 100 1.2rem "Roboto", sans-serif; 42 | outline: none; 43 | color:#fff 44 | ` 45 | const Title = styled.h3` 46 | padding:2vmax; 47 | ` 48 | const Avatar = styled.img` 49 | height:10vmax; 50 | width:10vmax; 51 | border-radius:50%; 52 | 53 | ` 54 | const Button = styled.button` 55 | border-radius: 3px; 56 | border: none; 57 | padding: 10px 20px; 58 | font-weight: 500; 59 | cursor: pointer; 60 | background-color: ${({ theme }) => theme.soft}; 61 | color: ${({ theme }) => theme.textSoft}; 62 | ` 63 | const Profile = () => { 64 | const navigate = useNavigate(); 65 | const dispatch = useDispatch(); 66 | const { currentUser } = useSelector((state) => state.user); 67 | const userId = currentUser ? currentUser._id : ""; 68 | 69 | const [name, setName] = useState(''); 70 | const [email, setEmail] = useState(''); 71 | // const [avatar, setAvatar] = useState(''); 72 | const [avatarPrev, setAvatarPrev] = useState(''); 73 | const [error, setError] = useState(''); 74 | 75 | 76 | window.onload = () => { 77 | if (!userId) navigate('/') 78 | }; 79 | 80 | useEffect(() => { 81 | const fetchUserInfo = async () => { 82 | try { 83 | const userResp = await userRequest.get(`/api/users/find/${userId}`); 84 | setName(userResp.data['name']); 85 | setEmail(userResp.data['email']); 86 | setAvatarPrev(userResp.data['img']); 87 | } catch (err) { 88 | console.log(err); 89 | } 90 | }; 91 | fetchUserInfo(); 92 | }, [userId]); 93 | 94 | const submitHandler = async (e) => { 95 | e.preventDefault(); 96 | dispatch(updateStart()); 97 | try { 98 | const res = await userRequest.put(`/api/users/${userId}`, { 99 | id: userId, 100 | name: name, 101 | email: email, 102 | // img: avatar, 103 | }); 104 | console.log(res); 105 | dispatch(updateSuccess(res.data)); 106 | } catch (err) { 107 | console.log(error); 108 | setError(error); 109 | dispatch(updateFailure()); 110 | } finally { 111 | // window.location.reload(); 112 | } 113 | } 114 | 115 | const handleImageChange = (e) => { 116 | const file = e.target.files[0]; 117 | 118 | const Reader = new FileReader(); 119 | Reader.readAsDataURL(file); 120 | 121 | Reader.onload = () => { 122 | if (Reader.readyState === 2) { 123 | setAvatarPrev(Reader.result); 124 | // setAvatar(Reader.result); 125 | } 126 | }; 127 | }; 128 | 129 | return ( 130 | 131 | 132 | 133 | 134 | 135 | Update Profile 136 | 137 | 138 | 142 | 143 | 144 | 145 | setName(e.target.value)} 152 | /> 153 | 154 | setEmail(e.target.value)} 161 | /> 162 | 163 | 166 | 167 | 168 | 169 | 170 | ); 171 | } 172 | 173 | export default Profile 174 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct - MERN Youtube Clone 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to a positive environment for our 15 | community include: 16 | 17 | - Demonstrating empathy and kindness toward other people 18 | - Being respectful of differing opinions, viewpoints, and experiences 19 | - Giving and gracefully accepting constructive feedback 20 | - Accepting responsibility and apologizing to those affected by our mistakes, 21 | and learning from the experience 22 | - Focusing on what is best not just for us as individuals, but for the 23 | overall community 24 | 25 | Examples of unacceptable behavior include: 26 | 27 | - The use of sexualized language or imagery, and sexual attention or 28 | advances 29 | - Trolling, insulting or derogatory comments, and personal or political attacks 30 | - Public or private harassment 31 | - Publishing others' private information, such as a physical or email 32 | address, without their explicit permission 33 | - Other conduct which could reasonably be considered inappropriate in a 34 | professional setting 35 | 36 | ## Our Responsibilities 37 | 38 | Project maintainers are responsible for clarifying and enforcing our standards of 39 | acceptable behavior and will take appropriate and fair corrective action in 40 | response to any behavior that they deem inappropriate, 41 | threatening, offensive, or harmful. 42 | 43 | Project maintainers have the right and responsibility to remove, edit, or reject 44 | comments, commits, code, wiki edits, issues, and other contributions that are 45 | not aligned to this Code of Conduct, and will 46 | communicate reasons for moderation decisions when appropriate. 47 | 48 | ## Scope 49 | 50 | This Code of Conduct applies within all community spaces, and also applies when 51 | an individual is officially representing the community in public spaces. 52 | Examples of representing our community include using an official e-mail address, 53 | posting via an official social media account, or acting as an appointed 54 | representative at an online or offline event. 55 | 56 | ## Enforcement 57 | 58 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 59 | reported to the community leaders responsible for enforcement at <>. 60 | All complaints will be reviewed and investigated promptly and fairly. 61 | 62 | All community leaders are obligated to respect the privacy and security of the 63 | reporter of any incident. 64 | 65 | ## Enforcement Guidelines 66 | 67 | Community leaders will follow these Community Impact Guidelines in determining 68 | the consequences for any action they deem in violation of this Code of Conduct: 69 | 70 | ### 1. Correction 71 | 72 | **Community Impact**: Use of inappropriate language or other behavior deemed 73 | unprofessional or unwelcome in the community. 74 | 75 | **Consequence**: A private, written warning from community leaders, providing 76 | clarity around the nature of the violation and an explanation of why the 77 | behavior was inappropriate. A public apology may be requested. 78 | 79 | ### 2. Warning 80 | 81 | **Community Impact**: A violation through a single incident or series 82 | of actions. 83 | 84 | **Consequence**: A warning with consequences for continued behavior. No 85 | interaction with the people involved, including unsolicited interaction with 86 | those enforcing the Code of Conduct, for a specified period of time. This 87 | includes avoiding interactions in community spaces as well as external channels 88 | like social media. Violating these terms may lead to a temporary or 89 | permanent ban. 90 | 91 | ### 3. Temporary Ban 92 | 93 | **Community Impact**: A serious violation of community standards, including 94 | sustained inappropriate behavior. 95 | 96 | **Consequence**: A temporary ban from any sort of interaction or public 97 | communication with the community for a specified period of time. No public or 98 | private interaction with the people involved, including unsolicited interaction 99 | with those enforcing the Code of Conduct, is allowed during this period. 100 | Violating these terms may lead to a permanent ban. 101 | 102 | ### 4. Permanent Ban 103 | 104 | **Community Impact**: Demonstrating a pattern of violation of community 105 | standards, including sustained inappropriate behavior, harassment of an 106 | individual, or aggression toward or disparagement of classes of individuals. 107 | 108 | **Consequence**: A permanent ban from any sort of public interaction within 109 | the community. 110 | -------------------------------------------------------------------------------- /client/src/components/Card.jsx: -------------------------------------------------------------------------------- 1 | import { Link } from "react-router-dom"; 2 | import styled from "styled-components"; 3 | import { format } from "timeago.js"; 4 | import React, { useEffect, useState } from "react"; 5 | import { publicRequest } from "../config.js"; 6 | import LoadingSpinner from "../utils/spinner"; 7 | import { useDispatch, useSelector } from "react-redux"; 8 | import { saveVideo, unsaveVideo } from "../redux/savedVideosSlice"; 9 | 10 | const Container = styled.div` 11 | width: ${(props) => props.type !== "sm" && "360px"}; 12 | margin-bottom: ${(props) => (props.type === "sm" ? "10px" : "45px")}; 13 | cursor: pointer; 14 | display : ${(props) => props.type === "sm" && "flex"}; 15 | padding-left: 10px; 16 | @media (max-width: 480px) { 17 | width: 100vw; 18 | margin-bottom: 20px; 19 | flex-direction: column; 20 | } 21 | `; 22 | 23 | const Image = styled.img` 24 | width: 100%; 25 | height: ${(props) => (props.type === "sm" ? "120px" : "202px")}; 26 | background-color: #999; 27 | flex: 1; 28 | transition: transform 0.2s; 29 | &:hover { 30 | transform: scale(1.02); 31 | box-shadow: 0 3px 50px black; 32 | } 33 | @media (max-width: 480px) { 34 | height: 150px; 35 | } 36 | `; 37 | 38 | const Details = styled.div` 39 | display: flex; 40 | margin-top: ${(props) => props.type !== "sm" && "16px"}; 41 | gap: 12px; 42 | flex: 1; 43 | @media (max-width: 480px) { 44 | flex-direction: column; 45 | gap: 6px; 46 | margin-top: 12px; 47 | margin-left: 20px; 48 | } 49 | `; 50 | 51 | const ChannelImage = styled.img` 52 | width: 36px; 53 | height: 36px; 54 | border-radius: 50%; 55 | background-color: #999; 56 | display: ${(props) => props.type === "sm" && "none"}; 57 | @media only screen and (max-width: 480px) { 58 | display: block; 59 | margin-bottom: 8px; 60 | } 61 | `; 62 | 63 | const Texts = styled.div``; 64 | 65 | const Title = styled.h1` 66 | font-size: ${(props) => (props.type === "sm" ? "14px" : "16px")}; 67 | font-weight: 500; 68 | color: ${({ theme }) => theme.text}; 69 | margin-left:${(props) => props.type === "sm" && "25%" }; 70 | @media only screen and (max-width: 480px) { 71 | font-size: 14px; 72 | margin-left: 0; 73 | } 74 | 75 | `; 76 | 77 | const ChannelName = styled.h2` 78 | font-size: 14px; 79 | color: ${({ theme }) => theme.textSoft}; 80 | margin: 9px 0px; 81 | margin-left:${(props) => props.type === "sm" && "25%"}; 82 | @media only screen and (max-width: 480px) { 83 | font-size: 12px; 84 | margin-left: 0; 85 | } 86 | `; 87 | 88 | const Info = styled.div` 89 | font-size: 14px; 90 | color: ${({ theme }) => theme.textSoft}; 91 | margin-left: ${(props) => props.type === "sm" && "25%"}; 92 | @media only screen and (max-width: 480px) { 93 | font-size: 12px; 94 | margin-left: 0; 95 | } 96 | `; 97 | 98 | const SaveButton = styled.button` 99 | position: absolute; 100 | top: 10px; 101 | right: 10px; 102 | background: rgba(0, 0, 0, 0.5); 103 | border: none; 104 | border-radius: 50%; 105 | width: 32px; 106 | height: 32px; 107 | display: flex; 108 | align-items: center; 109 | justify-content: center; 110 | cursor: pointer; 111 | color: white; 112 | transition: all 0.2s ease; 113 | &:hover { 114 | background: rgba(0, 0, 0, 0.7); 115 | } 116 | `; 117 | 118 | const Card = ({ type, video }) => { 119 | const [channel, setChannel] = useState({}); 120 | const [isLoading, setLoading] = useState(true); 121 | const dispatch = useDispatch(); 122 | const savedVideos = useSelector((state) => state.savedVideos.savedVideos); 123 | const isSaved = savedVideos.some((savedVideo) => savedVideo._id === video._id); 124 | 125 | useEffect(() => { 126 | const fetchChannel = async () => { 127 | const res = await publicRequest.get(`/api/users/find/${video.userId}`); 128 | setChannel(res.data); 129 | setLoading(false); 130 | }; 131 | fetchChannel(); 132 | }, [video.userId]); 133 | 134 | const handleSave = (e) => { 135 | e.preventDefault(); 136 | if (isSaved) { 137 | dispatch(unsaveVideo(video._id)); 138 | } else { 139 | dispatch(saveVideo(video)); 140 | } 141 | }; 142 | 143 | return ( 144 | <> 145 | {isLoading ? ( 146 | 147 | ) : ( 148 | <> 149 | 150 | 151 | 152 | 153 | {isSaved ? "✓" : "+"} 154 | 155 |
156 | 157 | 158 | {video.title} 159 | {channel.name} 160 | 161 | {video.views / 2} views • {format(video.createdAt)} 162 | 163 | 164 |
165 |
166 | 167 | 168 | )} 169 | 170 | ); 171 | }; 172 | 173 | export default Card; 174 | -------------------------------------------------------------------------------- /client/src/components/Upload.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import styled from "styled-components"; 3 | import { 4 | getStorage, 5 | ref, 6 | uploadBytesResumable, 7 | getDownloadURL, 8 | } from "firebase/storage"; 9 | import app from "../firebase"; 10 | import {userRequest} from "../config.js"; 11 | import { useNavigate } from "react-router-dom"; 12 | 13 | const Container = styled.div` 14 | width: 100%; 15 | height: 100%; 16 | position: absolute; 17 | top: 0; 18 | left: 0; 19 | background-color: #000000a7; 20 | display: flex; 21 | align-items: center; 22 | justify-content: center; 23 | `; 24 | 25 | const Wrapper = styled.div` 26 | width: 600px; 27 | height: 600px; 28 | background-color: ${({ theme }) => theme.bgLighter}; 29 | color: ${({ theme }) => theme.text}; 30 | padding: 20px; 31 | display: flex; 32 | flex-direction: column; 33 | gap: 20px; 34 | position: relative; 35 | `; 36 | const Close = styled.div` 37 | position: absolute; 38 | top: 10px; 39 | right: 10px; 40 | cursor: pointer; 41 | `; 42 | const Title = styled.h1` 43 | text-align: center; 44 | `; 45 | 46 | const Input = styled.input` 47 | border: 1px solid ${({ theme }) => theme.soft}; 48 | color: ${({ theme }) => theme.text}; 49 | border-radius: 3px; 50 | padding: 10px; 51 | background-color: transparent; 52 | z-index: 999; 53 | `; 54 | 55 | const Desc = styled.textarea` 56 | border: 1px solid ${({ theme }) => theme.soft}; 57 | color: ${({ theme }) => theme.text}; 58 | border-radius: 3px; 59 | padding: 10px; 60 | background-color: transparent; 61 | `; 62 | 63 | const Button = styled.button` 64 | border-radius: 3px; 65 | border: none; 66 | padding: 10px 20px; 67 | font-weight: 500; 68 | cursor: pointer; 69 | background-color: ${({ theme }) => theme.soft}; 70 | color: ${({ theme }) => theme.textSoft}; 71 | `; 72 | const Label = styled.label` 73 | font-size: 14px; 74 | `; 75 | 76 | const Upload = ({ setOpen }) => { 77 | 78 | const [img, setImg] = useState(undefined); 79 | const [video, setVideo] = useState(undefined); 80 | const [imgPerc, setImgPerc] = useState(0); // image percentage 81 | const [videoPerc, setVideoPerc] = useState(0); // video percentage 82 | const [inputs, setInputs] = useState({}); 83 | const [tags, setTags] = useState([]); 84 | 85 | const navigate = useNavigate() 86 | 87 | const handleChange = (e) => { 88 | setInputs((prev) => { 89 | return { ...prev, [e.target.name]: e.target.value }; 90 | }); 91 | }; 92 | 93 | const handleTags = (e) => { 94 | setTags(e.target.value.split(",")); 95 | }; 96 | 97 | const uploadFile = (file, urlType) => { // upload to firebase // urltype is for imgurl and videourl 98 | const storage = getStorage(app); 99 | const fileName = new Date().getTime() + file.name; 100 | const storageRef = ref(storage, fileName); 101 | const uploadTask = uploadBytesResumable(storageRef, file); 102 | 103 | uploadTask.on( 104 | "state_changed", 105 | (snapshot) => { 106 | const progress = 107 | (snapshot.bytesTransferred / snapshot.totalBytes) * 100; 108 | urlType === "imgUrl" ? setImgPerc(Math.round(progress)) : setVideoPerc(Math.round(progress)); // if it's imgurl then set imgperc otherwise set videoperc 109 | switch (snapshot.state) { 110 | case "paused": 111 | console.log("Upload is paused"); 112 | break; 113 | case "running": 114 | console.log("Upload is running"); 115 | break; 116 | default: 117 | break; 118 | } 119 | }, 120 | (error) => {}, 121 | () => { 122 | getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => { // save download url in mongodb 123 | setInputs((prev) => { 124 | return { ...prev, [urlType]: downloadURL }; 125 | }); 126 | }); 127 | } 128 | ); 129 | }; 130 | 131 | useEffect(() => { 132 | video && uploadFile(video , "videoUrl"); 133 | }, [video]); 134 | 135 | useEffect(() => { 136 | img && uploadFile(img, "imgUrl"); 137 | }, [img]); 138 | 139 | const handleUpload = async (e)=>{ 140 | e.preventDefault(); 141 | try { 142 | const res = await userRequest.post("/api/videos/", {...inputs, tags}); 143 | setOpen(false) 144 | res.status===200 && navigate(`/video/${res.data._id}`); 145 | } catch (error) { 146 | console.log(error); 147 | } 148 | 149 | } 150 | 151 | return ( 152 | 153 | 154 | setOpen(false)}>X 155 | Upload a New Video 156 | 157 | {videoPerc > 0 ? ( // video upload 158 | "Uploading:" + videoPerc + "%" 159 | ) : ( 160 | setVideo(e.target.files[0])} 164 | /> 165 | )} 166 | 172 | 178 | 183 | 184 | {imgPerc > 0 ? ( // image upload 185 | "Uploading:" + imgPerc + "%" 186 | ) : ( 187 | setImg(e.target.files[0])} 191 | /> 192 | )} 193 | 194 | 195 | 196 | ); 197 | }; 198 | 199 | export default Upload; 200 | -------------------------------------------------------------------------------- /client/src/pages/SignIn.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import styled from "styled-components"; 3 | import { useNavigate } from "react-router-dom"; 4 | import { publicRequest } from "../config"; 5 | import { useDispatch,useSelector } from "react-redux"; 6 | import { loginFailure, loginStart, loginSuccess } from "../redux/userSlice"; 7 | import { auth, provider } from "../firebase"; 8 | import { signInWithPopup } from "firebase/auth"; 9 | import ErrorMessage from "../utils/errorMessage"; 10 | import LoadingSpinner from "../utils/spinner"; 11 | 12 | const Container = styled.div` 13 | display: flex; 14 | flex-direction: column; 15 | align-items: center; 16 | justify-content: center; 17 | height: calc(100vh - 56px); 18 | color: ${({ theme }) => theme.text}; 19 | `; 20 | 21 | const Wrapper = styled.div` 22 | display: flex; 23 | align-items: center; 24 | flex-direction: column; 25 | background-color: ${({ theme }) => theme.bgLighter}; 26 | border: 1px solid ${({ theme }) => theme.soft}; 27 | padding: 20px 50px; 28 | gap: 10px; 29 | `; 30 | 31 | const Title = styled.h1` 32 | font-size: 24px; 33 | `; 34 | 35 | const SubTitle = styled.h2` 36 | font-size: 20px; 37 | font-weight: 300; 38 | `; 39 | 40 | const Input = styled.input` 41 | border: 1px solid ${({ theme }) => theme.soft}; 42 | border-radius: 3px; 43 | padding: 10px; 44 | background-color: transparent; 45 | width: 100%; 46 | color: ${({ theme }) => theme.text}; 47 | `; 48 | 49 | const Button = styled.button` 50 | border-radius: 3px; 51 | border: none; 52 | padding: 10px 20px; 53 | font-weight: 500; 54 | cursor: pointer; 55 | background-color: ${({ theme }) => theme.soft}; 56 | color: ${({ theme }) => theme.textSoft}; 57 | `; 58 | 59 | const More = styled.div` 60 | display: flex; 61 | margin-top: 10px; 62 | font-size: 12px; 63 | color: ${({ theme }) => theme.textSoft}; 64 | `; 65 | 66 | const Links = styled.div` 67 | margin-left: 50px; 68 | `; 69 | 70 | const Link = styled.span` 71 | margin-left: 30px; 72 | `; 73 | 74 | const SignIn = () => { 75 | const { loading } = useSelector((state) => state.user); 76 | const [name, setName] = useState(""); 77 | const [email, setEmail] = useState(""); 78 | const [password, setPassword] = useState(""); 79 | const [error, setError] = useState(''); 80 | const navigate = useNavigate(); 81 | const dispatch = useDispatch(); 82 | console.log(email); 83 | 84 | const handleLogin = async (e) => { 85 | e.preventDefault(); 86 | dispatch(loginStart()); 87 | try { 88 | const res = await publicRequest.post("/api/auth/signin", { 89 | name, 90 | password, 91 | }); 92 | dispatch(loginSuccess(res.data)); 93 | navigate("/"); 94 | window.location.reload(); 95 | } catch (error) { 96 | console.log(error.response['data']); 97 | setError(error.response['data']['message']); 98 | dispatch(loginFailure()); 99 | } 100 | }; 101 | 102 | const handleRegister = async (e) => { 103 | e.preventDefault(); 104 | try { 105 | await publicRequest.post("/api/auth/signup", { 106 | name, 107 | password, 108 | email, 109 | }); 110 | setError('Account has been created'); 111 | } catch (error) { 112 | setError(error.response['data']['message']); 113 | dispatch(loginFailure()); 114 | } 115 | }; 116 | 117 | const signInWithGoogle = async () => { 118 | dispatch(loginStart()); 119 | signInWithPopup(auth, provider) 120 | .then((result) => { 121 | publicRequest 122 | .post("/api/auth/google", { 123 | name: result.user.displayName, 124 | email: result.user.email, 125 | img: result.user.photoURL, 126 | }) 127 | .then((res) => { 128 | console.log(res); 129 | dispatch(loginSuccess(res.data)); 130 | navigate("/"); 131 | window.location.reload(); 132 | }); 133 | }) 134 | .catch((error) => { 135 | dispatch(loginFailure()); 136 | }); 137 | }; 138 | 139 | const CloseError = async (e) => { 140 | e.preventDefault(); 141 | setError('') 142 | } 143 | 144 | console.log(loading) 145 | 146 | return ( 147 | <> 148 | { 149 | loading ? : 150 | 151 | { 152 | error && 153 |
154 | 155 |
156 | 157 | } 158 | 159 | { 160 | 161 | <> 162 | Sign in 163 | to continue to videoTube 164 | setName(e.target.value)} 167 | /> 168 | setPassword(e.target.value)} 172 | /> 173 | 174 | or 175 | 176 | or 177 | setName(e.target.value)} 180 | /> 181 | setEmail(e.target.value)} /> 182 | setPassword(e.target.value)} 186 | required 187 | /> 188 | 189 | 190 | } 191 | 192 | 193 | Angrezi(US) 194 | 195 | Help 196 | Privacy 197 | Terms 198 | 199 | 200 |
201 | } 202 | 203 | ); 204 | }; 205 | 206 | export default SignIn; 207 | -------------------------------------------------------------------------------- /client/src/components/Menu.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import styled from "styled-components"; 3 | import HomeIcon from "@mui/icons-material/Home"; 4 | import { useSelector } from "react-redux"; 5 | import ExploreOutlinedIcon from "@mui/icons-material/ExploreOutlined"; 6 | import ExitToAppIcon from "@mui/icons-material/ExitToApp"; 7 | import SubscriptionsOutlinedIcon from "@mui/icons-material/SubscriptionsOutlined"; 8 | import VideoLibraryOutlinedIcon from "@mui/icons-material/VideoLibraryOutlined"; 9 | import HistoryOutlinedIcon from "@mui/icons-material/HistoryOutlined"; 10 | import LibraryMusicOutlinedIcon from "@mui/icons-material/LibraryMusicOutlined"; 11 | import SportsEsportsOutlinedIcon from "@mui/icons-material/SportsEsportsOutlined"; 12 | import SportsBasketballOutlinedIcon from "@mui/icons-material/SportsBasketballOutlined"; 13 | import MovieOutlinedIcon from "@mui/icons-material/MovieOutlined"; 14 | import ArticleOutlinedIcon from "@mui/icons-material/ArticleOutlined"; 15 | import LiveTvOutlinedIcon from "@mui/icons-material/LiveTvOutlined"; 16 | import AccountCircleOutlinedIcon from "@mui/icons-material/AccountCircleOutlined"; 17 | import SettingsOutlinedIcon from "@mui/icons-material/SettingsOutlined"; 18 | import FlagOutlinedIcon from "@mui/icons-material/FlagOutlined"; 19 | import HelpOutlineOutlinedIcon from "@mui/icons-material/HelpOutlineOutlined"; 20 | import SettingsBrightnessOutlinedIcon from "@mui/icons-material/SettingsBrightnessOutlined"; 21 | import BookmarkBorderOutlinedIcon from "@mui/icons-material/BookmarkBorderOutlined"; 22 | import { Link, useNavigate } from "react-router-dom"; 23 | import { logout } from "../redux/userSlice"; 24 | import { useDispatch } from "react-redux"; 25 | 26 | const Container = styled.div` 27 | padding: 20px 20px; 28 | position: fixed; 29 | top: 56px; 30 | z-index: 100; 31 | background-color: ${({ theme }) => theme.bgLighter}; 32 | height: -webkit-fill-available; 33 | width: 200px; 34 | overflow-y: scroll; 35 | `; 36 | 37 | const Item = styled.div` 38 | display: flex; 39 | align-items: center; 40 | cursor: pointer; 41 | padding: 7.5px 20px; 42 | margin: 5px 0px; 43 | color: ${({ theme }) => theme.text}; 44 | border-radius: 5px; 45 | gap: 10px; 46 | &:hover { 47 | background-color: ${({ theme }) => theme.soft}; 48 | } 49 | `; 50 | 51 | const Hr = styled.hr` 52 | margin: 15px 0px; 53 | border: 0.5px solid ${({ theme }) => theme.soft}; 54 | `; 55 | 56 | const Login = styled.div``; 57 | const Button = styled.button` 58 | padding: 5px 15px; 59 | background-color: transparent; 60 | border: 1px solid #3ea6ff; 61 | color: #3ea6ff; 62 | border-radius: 3px; 63 | font-weight: 500; 64 | margin-top: 10px; 65 | cursor: pointer; 66 | display: flex; 67 | align-items: center; 68 | gap: 5px; 69 | `; 70 | 71 | const Title = styled.h2` 72 | font-size: 14px; 73 | font-weight: 500; 74 | color: #aaaaaa; 75 | margin-bottom: 20px; 76 | `; 77 | 78 | const Menu = ({ darkMode, setDarkMode, isOpen, setOpenReportModal }) => { 79 | const { currentUser } = useSelector((state) => state.user); 80 | 81 | const navigate = useNavigate(); 82 | const dispatch = useDispatch(); 83 | 84 | const handleLogout = async (e) => { 85 | e.preventDefault(); 86 | try { 87 | dispatch(logout()); 88 | localStorage.clear(); 89 | navigate("/"); 90 | } catch (error) { 91 | console.log(error); 92 | } 93 | }; 94 | 95 | const handleReportClick = () => { 96 | if (currentUser) { 97 | setOpenReportModal(true); 98 | } else { 99 | window.alert("Login first"); 100 | } 101 | }; 102 | 103 | return ( 104 | <> 105 | {isOpen && ( 106 | 107 | 108 | 109 | 110 | Home 111 | 112 | 113 | 117 | 118 | 119 | Explore 120 | 121 | 122 | 126 | 127 | 128 | Subscriptions 129 | 130 | 131 |
132 | 133 | 134 | Library 135 | 136 | 137 | 138 | History 139 | 140 | 144 | 145 | 146 | Saved Videos 147 | 148 | 149 |
150 | {currentUser ? ( 151 | <> 152 | 156 | 157 | ) : ( 158 | <> 159 | 160 | Sign in to like videos, comment, and subscribe. 161 | 162 | 166 | 167 | 168 | 169 | )} 170 |
171 | BEST Categories 172 | 173 | 174 | Music 175 | 176 | 177 | 178 | Sports 179 | 180 | 181 | 182 | Gaming 183 | 184 | 185 | 186 | Movies 187 | 188 | 189 | 190 | News 191 | 192 | 193 | 194 | Live 195 | 196 |
197 | 201 | 202 | 203 | Your Videos 204 | 205 | 206 | 207 | 208 | Report 209 | 210 | 211 | 212 | Help 213 | 214 | setDarkMode(!darkMode)}> 215 | 216 | {darkMode ? "Light" : "Dark"} Mode 217 | 218 |
219 | )} 220 | 221 | ); 222 | }; 223 | 224 | export default Menu; 225 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to MERN Youtube Clone 2 | 3 | First off, thanks for taking the time to contribute! ❤️ 4 | 5 | All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The community looks forward to your contributions. 🎉 6 | 7 | > And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about: 8 | > 9 | > - Star the project 10 | > - Tweet about it 11 | > - Refer this project in your project's readme 12 | > - Mention the project at local meetups and tell your friends/colleagues 13 | 14 | ## Table of Contents 15 | 16 | - [Code of Conduct](#code-of-conduct) 17 | - [I Have a Question](#i-have-a-question) 18 | - [I Want To Contribute](#i-want-to-contribute) 19 | - [Reporting Bugs](#reporting-bugs) 20 | - [Suggesting Enhancements](#suggesting-enhancements) 21 | - [Your First Code Contribution](#your-first-code-contribution) 22 | - [Improving The Documentation](#improving-the-documentation) 23 | - [Styleguides](#styleguides) 24 | - [Commit Messages](#commit-messages) 25 | - [Join The Project Team](#join-the-project-team) 26 | 27 | ## Code of Conduct 28 | 29 | This project and everyone participating in it is governed by the 30 | [MERN Youtube Clone Code of Conduct](https://github.com/mnnkhndlwl/mern_youtube_cloneblob/master/CODE_OF_CONDUCT.md). 31 | By participating, you are expected to uphold this code. Please report unacceptable behavior 32 | to <>. 33 | 34 | ## I Have a Question 35 | 36 | > If you want to ask a question, we assume that you have read the available [Documentation](). 37 | 38 | Before you ask a question, it is best to search for existing [Issues](https://github.com/mnnkhndlwl/mern_youtube_clone/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first. 39 | 40 | If you then still feel the need to ask a question and need clarification, we recommend the following: 41 | 42 | - Open an [Issue](https://github.com/mnnkhndlwl/mern_youtube_clone/issues/new). 43 | - Provide as much context as you can about what you're running into. 44 | - Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant. 45 | 46 | We will then take care of the issue as soon as possible. 47 | 48 | 62 | 63 | ## I Want To Contribute 64 | 65 | > ### Legal Notice 66 | > 67 | > When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license. 68 | 69 | ### Reporting Bugs 70 | 71 | #### Before Submitting a Bug Report 72 | 73 | A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible. 74 | 75 | - Make sure that you are using the latest version. 76 | - Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](). If you are looking for support, you might want to check [this section](#i-have-a-question)). 77 | - To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/mnnkhndlwl/mern_youtube_cloneissues?q=label%3Abug). 78 | - Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue. 79 | - Collect information about the bug: 80 | - Stack trace (Traceback) 81 | - OS, Platform and Version (Windows, Linux, macOS, x86, ARM) 82 | - Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant. 83 | - Possibly your input and the output 84 | - Can you reliably reproduce the issue? And can you also reproduce it with older versions? 85 | 86 | #### How Do I Submit a Good Bug Report? 87 | 88 | > You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue tracker, or elsewhere in public. Instead sensitive bugs must be sent by email to <>. 89 | 90 | 91 | 92 | We use GitHub issues to track bugs and errors. If you run into an issue with the project: 93 | 94 | - Open an [Issue](https://github.com/mnnkhndlwl/mern_youtube_clone/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.) 95 | - Explain the behavior you would expect and the actual behavior. 96 | - Please provide as much context as possible and describe the _reproduction steps_ that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case. 97 | - Provide the information you collected in the previous section. 98 | 99 | Once it's filed: 100 | 101 | - The project team will label the issue accordingly. 102 | - A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for those steps and mark the issue as `needs-repro`. Bugs with the `needs-repro` tag will not be addressed until they are reproduced. 103 | - If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as possibly other tags (such as `critical`), and the issue will be left to be [implemented by someone](#your-first-code-contribution). 104 | 105 | ### Suggesting Enhancements 106 | 107 | This section guides you through submitting an enhancement suggestion for MERN Youtube Clone, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the community to understand your suggestion and find related suggestions. 108 | 109 | #### Before Submitting an Enhancement 110 | 111 | - Make sure that you are using the latest version. 112 | - Read the [documentation]() carefully and find out if the functionality is already covered, maybe by an individual configuration. 113 | - Perform a [search](https://github.com/mnnkhndlwl/mern_youtube_clone/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one. 114 | - Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library. 115 | 116 | #### How Do I Submit a Good Enhancement Suggestion? 117 | 118 | Enhancement suggestions are tracked as [GitHub issues](https://github.com/mnnkhndlwl/mern_youtube_clone/issues). 119 | 120 | - Use a **clear and descriptive title** for the issue to identify the suggestion. 121 | - Provide a **step-by-step description of the suggested enhancement** in as many details as possible. 122 | - **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you. 123 | - You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux. 124 | - **Explain why this enhancement would be useful** to most MERN Youtube Clone users. You may also want to point out the other projects that solved it better and which could serve as inspiration. 125 | -------------------------------------------------------------------------------- /client/src/components/Navbar.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import styled from "styled-components"; 3 | import Tooltip from "@mui/material/Tooltip"; 4 | import AccountCircleOutlinedIcon from "@mui/icons-material/AccountCircleOutlined"; 5 | import SearchOutlinedIcon from "@mui/icons-material/SearchOutlined"; 6 | import { Link, useNavigate } from "react-router-dom"; 7 | import { useSelector } from "react-redux"; 8 | import VideoCallOutlinedIcon from "@mui/icons-material/VideoCallOutlined"; 9 | import SpeechRecognition, { 10 | useSpeechRecognition, 11 | } from "react-speech-recognition"; 12 | import Upload from "./Upload"; 13 | import Model from "./Model"; 14 | import MenuIcon from "@mui/icons-material/Menu"; 15 | import logo from "../img/logo.png"; 16 | 17 | const Container = styled.div` 18 | padding: 5px 0; 19 | width: 100vw; 20 | position: sticky; 21 | top: 0; 22 | background-color: ${({ theme }) => theme.bgLighter}; 23 | height: 56px; 24 | z-index: 100; 25 | 26 | @media (max-width: 480px) { 27 | height: 48px; 28 | padding: 0 20px; 29 | } 30 | `; 31 | 32 | const Wrapper = styled.div` 33 | display: flex; 34 | align-items: center; 35 | justify-content: space-between; 36 | height: 100%; 37 | padding: 0px 20px; 38 | position: relative; 39 | font-size: 5px; 40 | 41 | @media (max-width: 480px) { 42 | font-size: 1px; 43 | padding: 0 10px; 44 | } 45 | `; 46 | 47 | const Search = styled.div` 48 | background-color: ${({ theme }) => theme.bgLighter}; 49 | width: 95%; 50 | ${ 51 | "" /* position: absolute; 52 | left: 0px; 53 | right: 0px; */ 54 | } 55 | margin: auto; 56 | display: flex; 57 | align-items: center; 58 | justify-content: space-between; 59 | padding-left: 10px; 60 | border: 1px solid ${({ theme }) => theme.text}; 61 | border-radius: 30px; 62 | color: ${({ theme }) => theme.text}; 63 | @media (max-width: 480px) { 64 | width: 50%; 65 | padding: 5px; 66 | margin-left: 100px; 67 | } 68 | `; 69 | 70 | const Input = styled.input` 71 | padding: 10px; 72 | width: 100%; 73 | height: 100%; 74 | background-color: transparent; 75 | border: none; 76 | outline: none; 77 | font-size: 18px; 78 | color: ${({ theme }) => theme.text}; 79 | @media (max-width: 480px) { 80 | padding: 5px; 81 | font-size: 15px; 82 | } 83 | `; 84 | 85 | const Button = styled.button` 86 | padding: 5px 15px; 87 | background-color: transparent; 88 | border: 1px solid #3ea6ff; 89 | color: #3ea6ff; 90 | border-radius: 3px; 91 | font-weight: 500; 92 | cursor: pointer; 93 | display: flex; 94 | align-items: center; 95 | gap: 5px; 96 | @media (max-width: 480px) { 97 | margin-right: -5px; 98 | font-size: 12px; 99 | padding: 2px; 100 | gap: 2px; 101 | } 102 | `; 103 | 104 | const SearchButton = styled.div` 105 | background-color: ${({ theme }) => theme.bgLighter}; 106 | padding: 10px; 107 | border-radius: 0 30px 30px 0; 108 | display: flex; 109 | 110 | padding-right: 20px; 111 | padding-left: 20px; 112 | @media (max-width: 480px) { 113 | width: 50%; 114 | padding: 5px; 115 | } 116 | `; 117 | 118 | const User = styled.div` 119 | display: flex; 120 | align-items: center; 121 | gap: 10px; 122 | font-weight: 500; 123 | cursor: pointer; 124 | color: ${({ theme }) => theme.text}; 125 | `; 126 | 127 | const Avatar = styled.img` 128 | width: 32px; 129 | height: 32px; 130 | border-radius: 50%; 131 | background-color: #999; 132 | @media (min-width: 480px) and (max-width: 768px) { 133 | width: 48px; 134 | height: 48px; 135 | } 136 | `; 137 | 138 | const SVG = styled.div` 139 | width: 42px; 140 | height: 42px; 141 | display: flex; 142 | align-items: center; 143 | justify-content: center; 144 | 145 | margin-left: 12px; 146 | border: 0.1px solid rgb(255, 255, 255, 0.05); 147 | background-color: ${({ theme }) => theme.bgLighter}; 148 | color: ${({ theme }) => theme.text}; 149 | border-radius: 50%; 150 | `; 151 | 152 | const Item = styled.div` 153 | color: ${({ theme }) => theme.text}; 154 | &:hover { 155 | background-color: ${({ theme }) => theme.theme}; 156 | } 157 | `; 158 | 159 | const Logo = styled.div` 160 | width: 150px; 161 | @media (max-width: 480px) { 162 | width: 48px; 163 | height: 48px; 164 | } 165 | `; 166 | 167 | const Navbar = ({ handleToggle, darkMode }) => { 168 | const navigate = useNavigate(); 169 | const [open, setOpen] = useState(false); 170 | const [q, setQ] = useState(""); 171 | const { currentUser } = useSelector((state) => state.user); 172 | const [openModal, setModel] = useState(false); 173 | 174 | const { 175 | transcript, 176 | listening, 177 | browserSupportsSpeechRecognition, 178 | isMicrophoneAvailable, 179 | } = useSpeechRecognition(); 180 | 181 | useEffect(() => { 182 | if (!browserSupportsSpeechRecognition) { 183 | window.alert(`Your Browser doesn't supprt this feature.`); 184 | } 185 | }, [browserSupportsSpeechRecognition]); 186 | 187 | const handleMicButton = () => { 188 | if (!isMicrophoneAvailable) { 189 | return window.alert(`Microphone Permission Not Availble`); 190 | // if (window.confirm(`Allow Microphone Permission`)) { 191 | // navigator.mediaDevices 192 | // .getUserMedia({ audio: true }) 193 | // .then(function (stream) { 194 | // console.log("You let me use your mic!"); 195 | // }) 196 | // .catch(function (err) { 197 | // console.log("No mic for you!"); 198 | // }); 199 | // } else { 200 | // return; 201 | // } 202 | } 203 | if (listening) { 204 | setQ(transcript); 205 | SpeechRecognition.stopListening(); 206 | } else { 207 | SpeechRecognition.startListening(); 208 | } 209 | }; 210 | 211 | return ( 212 | <> 213 | 214 | 215 |
216 | 217 | handleToggle()} /> 218 | 219 | 220 | 223 | logo 224 | 225 |

VideoTube

226 |
227 |
228 | 229 |
230 | 231 |
239 | 240 | { 245 | if (listening) { 246 | setQ(transcript); 247 | SpeechRecognition.stopListening(); 248 | } 249 | setQ(e.target.value); 250 | }} 251 | onSelect={() => { 252 | document.getElementById( 253 | "search-bar" 254 | ).style.border = `2px solid ${({ theme }) => theme.text}`; 255 | document.getElementById( 256 | "search-btn" 257 | ).style.borderLeft = `1px solid ${({ theme }) => 258 | theme.bgLighter}`; 259 | }} 260 | /> 261 | 262 | 263 | navigate(`/search?q=${q}`)} 265 | /> 266 | 267 | 268 | 269 | 280 | 281 | 289 | 290 | 291 | 292 | 293 | 294 |
295 | 296 | {currentUser ? ( 297 | <> 298 | setModel(!openModal)}> 299 | setOpen(true)} /> 300 | 301 | {currentUser.name} 302 | 303 | {openModal && } 304 | 305 | ) : ( 306 | 307 | 311 | 312 | )} 313 |
314 |
315 | {open && } 316 | 317 | ); 318 | }; 319 | 320 | export default Navbar; 321 | -------------------------------------------------------------------------------- /client/src/pages/Video.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import styled from "styled-components"; 3 | import DeleteIcon from "@mui/icons-material/Delete"; 4 | import ThumbUpOutlinedIcon from "@mui/icons-material/ThumbUpOutlined"; 5 | import ThumbDownOffAltOutlinedIcon from "@mui/icons-material/ThumbDownOffAltOutlined"; 6 | import ReplyOutlinedIcon from "@mui/icons-material/ReplyOutlined"; 7 | import AddTaskOutlinedIcon from "@mui/icons-material/AddTaskOutlined"; 8 | import ThumbDownIcon from "@mui/icons-material/ThumbDown"; 9 | import ThumbUpIcon from "@mui/icons-material/ThumbUp"; 10 | import Comments from "../components/Comments"; 11 | import { useDispatch, useSelector } from "react-redux"; 12 | import { useLocation, useNavigate } from "react-router-dom"; 13 | import { dislike, fetchSuccess, like } from "../redux/videoSlice"; 14 | import { format } from "timeago.js"; 15 | import { subscription } from "../redux/userSlice"; 16 | import Recommendation from "../components/Recommendation"; 17 | import { publicRequest, userRequest } from "../config"; 18 | import LoadingSpinner from "../utils/spinner"; 19 | import { useSnackbar } from "notistack"; 20 | 21 | const Container = styled.div` 22 | display: flex; 23 | gap: 24px; 24 | @media (max-width: 480px) { 25 | margin-top: 20px; 26 | flex-direction: column; 27 | } 28 | `; 29 | 30 | const Content = styled.div` 31 | flex: 5; 32 | @media (max-width: 480px) { 33 | padding-left: 50px; 34 | } 35 | `; 36 | const VideoWrapper = styled.div``; 37 | 38 | const Title = styled.h1` 39 | font-size: 18px; 40 | font-weight: 400; 41 | margin-top: 20px; 42 | margin-bottom: 10px; 43 | color: ${({ theme }) => theme.text}; 44 | `; 45 | 46 | const Details = styled.div` 47 | display: flex; 48 | align-items: center; 49 | justify-content: space-between; 50 | @media (maxwidth:480px) { 51 | display:block; 52 | } 53 | `; 54 | 55 | const Info = styled.span` 56 | color: ${({ theme }) => theme.textSoft}; 57 | `; 58 | 59 | const Buttons = styled.div` 60 | display: flex; 61 | gap: 20px; 62 | color: ${({ theme }) => theme.text}; 63 | @media (max-width: 480px) { 64 | margin-right: 35px; 65 | } 66 | `; 67 | 68 | const Button = styled.div` 69 | display: flex; 70 | align-items: center; 71 | gap: 5px; 72 | cursor: pointer; 73 | &:first-child { 74 | background-color: #3b3a3a; 75 | border-bottom-left-radius: 10px; 76 | border-top-left-radius: 10px; 77 | padding: 10px 15px; 78 | 79 | } 80 | &:nth-child(2) { 81 | background-color: #3b3a3a; 82 | margin-left: -20px; 83 | padding: 10px 15px; 84 | border-left: 1px solid #6f6f6f; 85 | border-bottom-right-radius: 10px; 86 | border-top-right-radius: 10px; 87 | } 88 | &:nth-child(3) { 89 | background-color: #3b3a3a; 90 | padding: 10px 15px; 91 | border-radius: 10px; 92 | } 93 | &:nth-child(4) { 94 | background-color: #3b3a3a; 95 | padding: 10px 15px; 96 | border-radius: 10px; 97 | } 98 | `; 99 | const Hr = styled.hr` 100 | margin: 15px 0px; 101 | border: 0.5px solid ${({ theme }) => theme.soft}; 102 | `; 103 | 104 | const Channel = styled.div` 105 | display: flex; 106 | justify-content: space-between; 107 | align-items: center; 108 | `; 109 | 110 | const ChannelInfo = styled.div` 111 | display: flex; 112 | gap: 20px; 113 | @media (max-width: 480px) { 114 | flex-wrap: wrap; 115 | } 116 | `; 117 | 118 | const Image = styled.img` 119 | width: 50px; 120 | height: 50px; 121 | border-radius: 50%; 122 | `; 123 | 124 | const ChannelDetail = styled.div` 125 | display: flex; 126 | flex-direction: column; 127 | color: ${({ theme }) => theme.text}; 128 | `; 129 | 130 | const ChannelName = styled.span` 131 | font-weight: 500; 132 | `; 133 | 134 | const ChannelCounter = styled.span` 135 | margin-top: 5px; 136 | margin-bottom: 20px; 137 | color: ${({ theme }) => theme.textSoft}; 138 | font-size: 12px; 139 | `; 140 | 141 | const Description = styled.p` 142 | font-size: 14px; 143 | `; 144 | 145 | const Subscribe = styled.button` 146 | background-color: ${(props) => (props.isSubscribed ? "#a1a6ad" : "#cc1a00")}; 147 | font-weight: 500; 148 | color: white; 149 | border: none; 150 | border-radius: 10px; 151 | height: max-content; 152 | padding: 10px 20px; 153 | margin-left: 40px; 154 | cursor: pointer; 155 | @media (max-width: 480px) { 156 | margin-right: 30px; 157 | } 158 | `; 159 | 160 | const VideoFrame = styled.video` 161 | max-height: 720px; 162 | width: 100%; 163 | object-fit: cover; 164 | @media (max-width:'480px') { 165 | width: 100vw; 166 | object-fit: contain; 167 | } 168 | `; 169 | 170 | const Video = () => { 171 | const [isHovering, setIsHovering] = useState(false); 172 | const { currentUser } = useSelector((state) => state.user); 173 | const { enqueueSnackbar, closeSnackbar } = useSnackbar(); 174 | const [isLoading, setLoading] = useState(false); 175 | 176 | const { currentVideo, loading } = useSelector((state) => state.video); 177 | const navigate = useNavigate(); 178 | const dispatch = useDispatch(); 179 | 180 | const path = useLocation().pathname.split("/")[2]; 181 | 182 | const [channel, setChannel] = useState({}); 183 | 184 | const fetchData = async () => { 185 | try { 186 | setLoading(true); 187 | const videoRes = await publicRequest.get(`/api/videos/find/${path}`); 188 | await publicRequest.put(`api/videos/view/${path}`); 189 | console.log(path); 190 | const channelRes = await publicRequest.get( 191 | `/api/users/find/${videoRes.data.userId}` 192 | ); 193 | setChannel(channelRes.data); 194 | dispatch(fetchSuccess(videoRes.data)); 195 | setLoading(false); 196 | } catch (err) { 197 | console.log(err); 198 | } 199 | }; 200 | 201 | useEffect(() => { 202 | fetchData(); 203 | },[path,dispatch]); 204 | 205 | 206 | 207 | if (!currentVideo) { 208 | setLoading(true); 209 | } 210 | 211 | const handleLike = async () => { 212 | await userRequest.put(`/api/users/like/${currentVideo._id}`); 213 | dispatch(like(currentUser._id)); 214 | }; 215 | const handleDislike = async () => { 216 | await userRequest.put(`/api/users/dislike/${currentVideo._id}`); 217 | dispatch(dislike(currentUser._id)); 218 | }; 219 | 220 | const handleSub = async () => { 221 | if (!currentUser) { 222 | alert("Please login to subscribe to this channel."); 223 | } 224 | currentUser.subscribedUsers.includes(channel._id) 225 | ? await userRequest.put(`/api/users/unsub/${channel._id}`) 226 | : await userRequest.put(`/api/users/sub/${channel._id}`); 227 | dispatch(subscription(channel._id)); 228 | }; 229 | 230 | // to do 231 | const handleDelete = async () => { 232 | try { 233 | await userRequest.delete(`/api/videos/${path}`); 234 | navigate("/"); 235 | } catch (error) { 236 | console.log(error); 237 | } 238 | }; 239 | 240 | const handleShare = async () => { 241 | await window.navigator.clipboard.writeText(window.location.href); 242 | enqueueSnackbar("Share Link is copied!", { variant: "success" }); 243 | }; 244 | 245 | const handleMouseEnter = () => { 246 | setIsHovering(true); 247 | }; 248 | 249 | const handleMouseLeave = () => { 250 | setIsHovering(false); 251 | }; 252 | 253 | return ( 254 | <> 255 | { 256 | isLoading ? : 257 | <> 258 | 259 | 260 | 261 | 262 | 263 | {currentVideo.title} 264 |
265 | 266 | 267 | 268 | 269 | {channel.name} 270 | 271 | {channel.subscribers} subscribers 272 | 273 | {currentVideo.desc} 274 | 275 | 276 | 277 | {currentUser?.subscribedUsers?.includes(channel._id) 278 | ? "SUBSCRIBED" 279 | : "SUBSCRIBE"} 280 | 281 | 282 | 283 | 291 | 299 | 307 | 310 | {currentUser?._id !== currentVideo.userId ? ( 311 | <> 312 | ) : ( 313 | 316 | )} 317 | 318 |
319 |
320 |
321 | 322 | {currentVideo.views / 2} views • {format(currentVideo.createdAt)} 323 | 324 |
325 |
326 | 327 |
328 | 329 |
330 | 331 | } 332 | 333 | ); 334 | }; 335 | 336 | export default Video; 337 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Mern_Youtube_Clone

4 |

⭐Youtube Clone built with Mern Stack⭐

5 | 6 | 7 | 8 | 9 |
10 | 11 | ![GitHub stars](https://img.shields.io/github/stars/mnnkhndlwl/mern_youtube_clone?) 12 | ![GitHub forks](https://img.shields.io/github/forks/mnnkhndlwl/mern_youtube_clone?) 13 | ![GitHub watchers](https://img.shields.io/github/watchers/mnnkhndlwl/mern_youtube_clone?) 14 | ![Repo. Size](https://img.shields.io/github/repo-size/mnnkhndlwl/mern_youtube_clone?) 15 | ![GitHub Maintained](https://img.shields.io/badge/Maintained%3F-yes-brightgreen.svg?) 16 | ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?) 17 | 18 | ![GitHub contributors](https://img.shields.io/github/contributors/mnnkhndlwl/mern_youtube_clone?) 19 | ![GitHub Closed issues](https://img.shields.io/github/issues-closed-raw/mnnkhndlwl/mern_youtube_clone?) 20 | ![GitHub PR Open](https://img.shields.io/github/issues-pr/mnnkhndlwl/mern_youtube_clone?) 21 | ![GitHub PR closed](https://img.shields.io/github/issues-pr-closed-raw/mnnkhndlwl/mern_youtube_clone?) 22 | ![GitHub language count](https://img.shields.io/github/languages/count/mnnkhndlwl/mern_youtube_clone?) 23 | ![GitHub top language](https://img.shields.io/github/languages/top/mnnkhndlwl/mern_youtube_clone?) 24 | ![GitHub last commit](https://img.shields.io/github/last-commit/mnnkhndlwl/mern_youtube_clone?) 25 | 26 | 27 |
28 | 29 | 30 | 31 |

32 | A beginner friendly project to help you in open source contributions. 33 |
34 | 35 |
36 | Visit the Official Website » 37 |
38 | Report Bug 39 | · 40 | Documentation Request 41 | . 42 | Feature Request 43 |

44 | 45 | 46 | 47 | 48 | ### 📌Table of Contents : 49 | - [](#) 50 | - [](#-1) 51 | - [](#-2) 52 | - [](#-3) 53 | - [](#-4) 54 | - [Contribution Guidelines](#contribution-guidelines) 55 | - [🔑Guidelines](#guidelines) 56 | - [How to Contribute:](#how-to-contribute) 57 | - [Usage](#usage) 58 | - [Install dependencies](#install-dependencies) 59 | - [Run Server](#run-server) 60 | - [Contributors](#contributors) 61 | - [Github Beginner Guide](#github-beginner-guide) 62 | - [Are you a beginner in using Github?](#are-you-a-beginner-in-using-github) 63 | - [Feedback](#feedback) 64 | - [](#-5) 65 | 66 | 67 | 68 |

(Bottom)

69 | 70 |
71 | 72 | 73 | 74 | ## What is Open Source? 75 | 76 |

The open source community provides a great opportunity for aspiring programmers to distinguish themselves; and by contributing to various projects, developers can improve their skills and get inspiration and support from like-minded people. When you contribute to something you already know and love, it can have so much more meaning, because you know how the tool is used and the good it does for you. Being part of an open source community opens you up to a broader range of people to interact with. 77 | 78 | Read more about it here. 79 | 80 |

81 | 82 |

(back to top)

83 | 84 | 85 | 86 | ## Open Source programs this repo has been part of 87 | 88 | 89 | 90 |
91 | 92 |
93 | 94 |
95 | JGEC Winter of Code 96 | 97 |
98 | 99 |
100 | 101 |
102 | 103 |
104 | Hacktoberfest 2023 105 | 106 |
107 | 108 |
109 | 110 |
111 | 112 |

(back to top)

113 | 114 | 115 | 116 | ## Overview of Project 117 | 118 |

The goal of this project is to help the beginners with their contributions in Open Source. We aim to achieve this collaboratively, so feel free to contribute in any way you want, just make sure to follow the contribution guidelines. 119 |

120 | 121 | 122 | ### Tech Stacks used 123 | 124 | 125 | ![Javascript](https://img.shields.io/badge/JavaScript-323330?style=for-the-badge&logo=javascript&logoColor=F7DF1E) 126 | ![React](https://img.shields.io/badge/React-323330?style=for-the-badge&logo=react&logoColor=F7DF1E) 127 | ![MaterialUI](https://img.shields.io/badge/Material--UI-0081CB?style=for-the-badge&logo=material-ui&logoColor=F7DF1E) 128 | ![Firebase](https://img.shields.io/badge/firebase-%23039BE5.svg?style=for-the-badge&logo=firebase) 129 | ![NPM](https://img.shields.io/badge/NPM-%23000000.svg?style=for-the-badge&logo=npm&logoColor=white) 130 | ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white) 131 | ![React](https://img.shields.io/badge/react-%2320232a.svg?style=for-the-badge&logo=react&logoColor=%2361DAFB) 132 | ![Redux](https://img.shields.io/badge/redux-%23593d88.svg?style=for-the-badge&logo=redux&logoColor=white) 133 | ![Express.js](https://img.shields.io/badge/express.js-%23404d59.svg?style=for-the-badge&logo=express&logoColor=%2361DAFB) 134 | ![MongoDB](https://img.shields.io/badge/MongoDB-%234ea94b.svg?style=for-the-badge&logo=mongodb&logoColor=white) 135 | 136 | 137 | 138 | 139 | 140 | 141 | ### Key Features 142 | 143 | ``` 144 | # ReactJS in the frontend 145 | # State management in the frontend using Redux & Redux Toolkit 146 | # Styled components with more emphasis on custom CSS & little bit of Material UI & Icons 147 | # Video & Image upload using firebase storage 148 | # Search, Like & Dislike, Subscribe a channel & Comment a video features 149 | # Video recommendations on the video page 150 | # Light / Dark Mode toggling 151 | # Axios http client 152 | # JWT cookie authentication 153 | # Hashed password saving in the MongoDB database 154 | # Login & Signup with custom Email & Password, Google OAuth using firebase authentication 155 | # RESTful API using ExpressJS and MongoDB with mongoose 156 | # Error handler & Protected routes 157 | ``` 158 | 159 | 160 | ### Screenshots of Website 161 | # ![image](https://user-images.githubusercontent.com/75252077/224484912-899b97b9-c8e5-4e06-9dc6-1677ff190c20.png) 162 | # ![image](https://user-images.githubusercontent.com/75252077/215504244-3c88e023-4749-4366-99f5-b50575440c94.png) 163 | # ![image](https://user-images.githubusercontent.com/75252077/215592578-6ba38684-3016-45c9-9c5f-05e620f91227.png) 164 | 165 | # ![image](https://user-images.githubusercontent.com/75252077/215592676-c3456e26-73e0-4b17-9236-ae1199ddc4c1.png) 166 | 167 | # ![image](https://user-images.githubusercontent.com/75252077/215592772-3840835c-d298-41b8-9f12-a23c0d633f47.png) 168 | 169 |

(back to top)

170 | 171 | 172 | ## Contribution Guidelines 173 | 174 | 175 | 176 | 177 | #### 🔑Guidelines 178 | 179 | Here are some set of guidelines to follow while contributing to `mern_youtube_clone` : 180 | ``` 181 | 1. Welcome to this repository, if you are here as an open-source program participant/contributor. 182 | 2. Participants/contributors have to **comment** on issues they would like to work on, and mentors or the PA will assign you. 183 | 3. Issues will be assigned on a **first-come, first-serve basis.** 184 | 4. Participants/contributors can also **open their issues**, but it needs to be verified and labelled by a mentor. We respect all your contributions, whether 185 | it is an Issue or a Pull Request. 186 | 5. When you raise an issue, make sure you get it assigned to you before you start working on that project. 187 | 6. Each participant/contributor will be **assigned 1 issue (max)** at a time to work. 188 | 7. Don't create issues that are **already listed**. 189 | 8. Please don't pick up an issue already assigned to someone else. Work on the issues after it gets **assigned to you**. 190 | 9. Create your file in an appropriate folder with appropriate name and extension. 191 | 10. Pull requests will be merged after being **reviewed** by mentor . 192 | 11. We all are here to learn. You are allowed to make mistakes. That's how you learn, right!. 193 | ``` 194 | 195 | ### How to Contribute: 196 | 197 | 198 | - Before Contribute Please read [CONTRIBUTING.md](https://github.com/mnnkhndlwl/mern_youtube_clone/blob/master/CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](https://github.com/mnnkhndlwl/mern_youtube_clone/blob/master/CODE_OF_CONDUCT.md) 199 | - Fork the repo to your Github.
200 | 201 | - Clone the Forked Repository to your local machine. 202 | ``` 203 | git clone https://github.com/ mnnkhndlwl/mern_youtube_clone.git. 204 | ``` 205 | - Change the directory to mern_youtube_clone. 206 | ```bash 207 | cd mern_youtube_clone 208 | ``` 209 | - Add remote to the Original Repository. 210 | ``` 211 | git remote add upstream https://github.com/mnnkhndlwl/mern_youtube_clone.git 212 | ``` 213 | - Check the remotes for this repository. 214 | ``` 215 | git remote -v 216 | ``` 217 | - Always take a pull from the upstream repository to your master branch to keep it at par with the main project(updated repository). 218 | ``` 219 | git pull upstream main 220 | ``` 221 | - Create a new branch. 222 | ``` 223 | git checkout -b 224 | ``` 225 | - Perform your desired changes to the code base. 226 | - Track your changes:heavy_check_mark: . 227 | ``` 228 | git add . 229 | ``` 230 | - Commit your changes . 231 | ``` 232 | git commit -m "Relevant message" 233 | ``` 234 | - Push the committed changes in your feature branch to your remote repo. 235 | ``` 236 | git push -u origin 237 | ``` 238 | - To create a pull request, click on `compare and pull requests`. Please ensure you compare your feature branch to the desired branch of the repository you are supposed to make a PR to. 239 | 240 | - Add appropriate title and description to your pull request explaining your changes and efforts done. 241 | 242 | 243 | - Click on `Create Pull Request`. 244 | 245 | 246 | - Voila! You have made a PR to this repo. Sit back patiently and relax while your PR is reviewed 247 | 248 | 249 | 250 |

(back to top)

251 | 252 | 253 | ## Usage 254 | Create .env file in the server folder and add the following environment variables: 255 | ``` 256 | # MONGO = 257 | # JWT = 258 | # PORT = 3001 259 | ``` 260 | Create .env file in the client folder and add the following environment variables, values can be found from firebase project setup 261 | ``` 262 | # REACT_APP_FIREBASE_KEY = 263 | # GENERATE_SOURCEMAP=false 264 | ``` 265 | ### Install dependencies 266 | ``` 267 | # Backend deps 268 | cd server 269 | npm install 270 | # client deps 271 | cd client 272 | npm install 273 | ``` 274 | ### Run Server 275 | ``` 276 | # Backend Server (Local) 277 | cd server 278 | npm start 279 | 280 | # client Server (Local) 281 | cd client 282 | npm start 283 | ``` 284 | 285 | you need to setup new project in firebase and enable storage and signin with google option 286 | 287 |

(back to top)

288 | 289 | 290 | 291 | ## Contributors 292 |
293 | 294 | 295 |
296 |
297 |
298 |

299 | Thanks to these amazing people 300 |

301 | 302 | 303 | 304 |

305 | 306 |

(back to top)

307 | 308 | 309 | ## Github Beginner Guide 310 | #### Are you a beginner in using Github? 311 | 312 | You can refer to the following articles on the basics of Git and Github and also contact me, in case you are stuck: 313 | - [Forking a Repo](https://help.github.com/en/github/getting-started-with-github/fork-a-repo) 314 | - [Cloning a Repo](https://help.github.com/en/desktop/contributing-to-projects/creating-an-issue-or-pull-request) 315 | - [How to create a Pull Request](https://opensource.com/article/19/7/create-pull-request-github) 316 | - [Getting started with Git and GitHub](https://towardsdatascience.com/getting-started-with-git-and-github-6fcd0f2d4ac6) 317 | - [Learn GitHub from Scratch](https://lab.github.com/githubtraining/introduction-to-github) 318 | 319 | 320 |

(back to top)

321 | 322 | 323 | 324 | 325 | ## Feedback 326 | 327 | If you have any feedback or suggestions please reach out to maintainers. 328 | * [Manan khandelwal](https://github.com/mnnkhndlwl) 329 | 330 | Or you can create a issue and mention there , which features can make this Project more good. 331 | 332 | 333 | 334 | 335 |
336 | 337 |
338 |

Show some ❤️ by starring this awesome repository!

339 |
340 | 341 | ### [![Typing SVG](https://readme-typing-svg.herokuapp.com/?lines=Thanks+for+contributing!;&size=30;align=center)](https://git.io/typing-svg) 342 | 343 | 344 |
345 | --------------------------------------------------------------------------------