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 |
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 |
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 | 
126 | 
127 | 
128 | 
129 | 
130 | 
131 | 
132 | 
133 | 
134 | 
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 | # 
162 | # 
163 | # 
164 |
165 | # 
166 |
167 | # 
168 |
169 |
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 |
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 |
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 |