Merge branch 'dev' into 'main'

doc: import BrowserRouter, Routes, and Route from react-router-dom, and import...

See merge request leonxu260/youtube-clone!2
This commit is contained in:
Leon Xu committed 2022-08-28 03:16:51 +00:00
commit 9af6e482d9
24 files changed
+576 -7

No files matched your search

+1
View File
@@ -14,6 +14,7 @@
# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
+5 -2
View File
@@ -1,6 +1,6 @@
# YouTube Clone
This is a clone of YouTube - the video sharing application
This is a clone web application of YouTube
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
@@ -40,7 +40,10 @@ For people who want to make changes to your project, it's helpful to have some d
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
- [Leon Xu](https://gitlab.com/leonxu260)
**API Used**
- [RapidAPI - YouTube V3](https://rapidapi.com/ytdlfree/api/youtube-v31/)
## License
For open source projects, say how it is licensed.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

+2 -2
View File
@@ -2,14 +2,14 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="icon" href="%PUBLIC_URL%/logo.png />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

+14 -2
View File
@@ -1,8 +1,20 @@
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import { Box } from '@mui/material'
import { Navbar, Feed, VideoDetail, ChannelDetail, SearchFeed } from './components';
function App() {
return (
<div>App</div>
<BrowserRouter>
<Box sx={{ backgroundColor: '#000'}}>
<Navbar />
<Routes>
<Route path={'/'} exact element={<Feed />}/>
<Route path={'/video/:id'} element={<VideoDetail />}/>
<Route path={'/channel/:id'} element={<ChannelDetail />}/>
<Route path={'/search/:searchTerm'} element={<SearchFeed />}/>
</Routes>
</Box>
</BrowserRouter>
);
}
+54
View File
@@ -0,0 +1,54 @@
import { Box, CardContent, CardMedia, Typography } from "@mui/material";
import { CheckCircle} from "@mui/icons-material";
import { Link } from 'react-router-dom';
const ChannelCard = ({ channelDetail, marginTop }) => (
<Box
sx={{
boxShadow: 'none',
borderRadius: '20px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: { xs: '356px', md: '320px' },
height: '326px',
margin: 'auto',
marginTop: marginTop
}}
>
<Link to={`/channel/${channelDetail?.id?.channelId}`}>
<CardContent
sx={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
textAlign: 'center',
color: '#fff'
}}
>
<CardMedia
image={channelDetail?.snippet?.thumbnails?.high?.url}
alt={channelDetail?.snippet?.title}
sx={{
borderRadius: '50%',
height: '180px',
width: '180px',
mb: 2,
border: '1px solid #e3e3e3'
}}
/>
<Typography variant={'h6'}>
{channelDetail?.snippet?.title}
<CheckCircle sx={ { fontSize: 14, color: 'gray', ml: '5px'}} />
</Typography>
{channelDetail?.statistics?.subscriberCount && (
<Typography>
{parseInt(channelDetail?.statistics?.subscriberCount, 10).toLocaleString()} Subscribers
</Typography>
)}
</CardContent>
</Link>
</Box>
)
export default ChannelCard;
+40
View File
@@ -0,0 +1,40 @@
import { useState, useEffect } from 'react';
import { useParams } from "react-router-dom";
import { Box } from '@mui/material';
import { api } from '../utils/api';
import {Videos, ChannelCard} from "./";
const ChannelDetail = () => {
const [ channelDetail, setChannelDetail ] = useState(null);
const [ videos, setVideos ] = useState([])
const { id } = useParams();
useEffect(() => {
api(`channels?part="snippet&id=${id}`)
.then((data) => setChannelDetail(data?.items[0]));
api(`search?channelId=${id}&part=snippet&order=date`)
.then((data) => setVideos(data?.items));
}, [id])
return (
<Box minHeight={"95vh"}>
<Box>
<div style={{
background: 'linear-gradient(90deg, rgba(0, 238, 247, 1) 0%, rgba(206, 3, 184, 1) 100%, rgba(0, 212, 255, 1) 100%)',
zIndex: 10,
height: '300px'
}}
/>
<ChannelCard channelDetail={channelDetail}
marginTop={"-110px"}/>
</Box>
<Box display={"flex"} p={"2"}>
<Box sx={{ mr: { sm : '100px'}}} />
<Videos videos={videos}/>
</Box>
</Box>
)
}
export default ChannelDetail;
+46
View File
@@ -0,0 +1,46 @@
import {useState, useEffect } from 'react';
import { Box, Stack, Typography} from "@mui/material";
import { SideBar, Videos } from './';
import { api } from "../utils/api";
const Feed = () => {
const [ selectedCategory, setSelectedCategory ] = useState('New');
const [videos, setVideos] = useState([])
useEffect(() => {
api(`search?part=snippet&q=${selectedCategory}`)
.then((data) => setVideos(data.items))
}, [selectedCategory]);
return (
<Stack
sx={{
flexDirection: {
sx: 'column',
md: 'row'
}
}}>
<Box
sx={{
height: {
sx: 'auto', md: '92vh'
}, borderRight: '1px solid #3d3d3d', px: {
sx: 0,
md: 2
}
}}
>
<SideBar selectedCategory={selectedCategory} setSelectedCategory={setSelectedCategory}/>
<Typography className={'copyright'} variant={'body2'} sx={{ mt: 1.5, color: "#fff"}}>
Copyright &copy; 2022 - Leon Xu
</Typography>
</Box>
<Box p={2} sx={{overflowY: 'auto', height: '90vh', flex: '2'}}>
<Typography variant={"h4"} fontWeight={"bold"} mb={2} sx={{color: "white"}}>
{selectedCategory} <span style={{color: "#F31503"}}>videos</span>
</Typography>
<Videos videos={videos}/>
</Box>
</Stack>
)
}
export default Feed;
+16
View File
@@ -0,0 +1,16 @@
import { Box, CircularProgress, Stack } from "@mui/material";
const Loader = () => (
<Box minHeight={"95vh"}>
<Stack
direction={"row"}
justifyContent={"center"}
alignItems={"center"}
height={"80vh"}
>
<CircularProgress />
</Stack>
</Box>
);
export default Loader;
+21
View File
@@ -0,0 +1,21 @@
import { Stack } from "@mui/material";
import { Link } from 'react-router-dom'
import { logo } from '../utils/constant'
import SearchBar from './SearchBar'
const Navbar = () => (
<Stack
direction={"row"}
alignItems={"center"}
p={2}
sx={{ position: 'sticky', background: '#000', top: 0, justifyContent: 'space-between'}}
>
<Link to={"/"} style={{ display: "flex", alignItems: "center" }}>
<img src={logo} alt={logo} height={45} />
</Link>
<SearchBar />
</Stack>
)
export default Navbar;
+47
View File
@@ -0,0 +1,47 @@
import { useState } from 'react';
import { useNavigate } from "react-router-dom";
import { Paper, IconButton } from "@mui/material";
import { Search } from '@mui/icons-material'
const SearchBar = () => {
const [ searchTerm, setSearchTerm ] = useState('');
const navigate = useNavigate();
const handleSubmit = (e) => {
e.preventDefault();
if (searchTerm) {
navigate(`/search/${searchTerm}`);
setSearchTerm('');
}
}
return (
<Paper
component={"form"}
onSubmit={handleSubmit}
sx={{
borderRadius: 20,
border: '1px solid #e3e3e3',
pl: 2,
boxShadow: 'none',
mr: { sm: 5 }
}}
>
<input
className={"search-bar"}
placeholder={"Search..."}
value={searchTerm}
onChange={(e) => {
setSearchTerm(e.target.value);
}}
/>
<IconButton>
<Search type={'submit'} sx={{
p: '10px',
color: 'red'}}/>
</IconButton>
</Paper>
)
}
export default SearchBar;
+25
View File
@@ -0,0 +1,25 @@
import { useState, useEffect } from 'react';
import { Box, Typography } from "@mui/material";
import { useParams } from "react-router-dom";
import { api } from "../utils/api";
import { Videos } from './'
const SearchFeed = () => {
const [videos, setVideos] = useState ([])
const { searchTerm } = useParams();
useEffect (() => {
api (`search?part=snippet&q=${searchTerm}`)
.then ((data) => setVideos (data.items))
}, [searchTerm]);
return (
<Box p={2} sx={{overflowY: 'auto', height: '90vh', flex: '2'}}>
<Typography variant={"h4"} fontWeight={"bold"} mb={2} sx={{color: "white"}}>
Search Request for: <span style={{color: "#F31503"}}>
{searchTerm}</span> videos
</Typography>
<Videos videos={videos}/>
</Box>
)
}
export default SearchFeed;
+39
View File
@@ -0,0 +1,39 @@
import { Stack } from "@mui/material";
import { categories } from "../utils/constant";
const Sidebar = ({ selectedCategory, setSelectedCategory }) => (
<Stack
direction={"row"}
sx={{
overflow: "auto",
height: {
sx: 'auto',
md: '95%'
},
flexDirection: {md: 'column'}
}}
>
{categories.map ((category) => (
<button className={'category-btn'}
onClick={() => setSelectedCategory(category.name)}
style={{
background: category.name === selectedCategory && '#FC1503', color: 'white'
}}
key={category.name}
>
<span style={{
color: category.name === selectedCategory ? 'white' : 'red', marginRight: '15px'
}}
>
{category.icon}
</span>
<span style={{opacity: category.name === selectedCategory ? '1' : '0.8'}}
>
{category.name}
</span>
</button>
))}
</Stack>
)
export default Sidebar;
+32
View File
@@ -0,0 +1,32 @@
import { Link } from 'react-router-dom';
import { Typography, Card, CardContent, CardMedia} from "@mui/material";
import { CheckCircle } from '@mui/icons-material';
const VideoCard = ({ video: { id: { videoId }, snippet } }) => {
return (
<Card sx={{ width: { xs: '100%', sm: '358px', md: '320px' }, boxShadow: 'none', borderRadius: 0 }}>
<Link to={ videoId ? `/video/${videoId}` : `URL not found` }>
<CardMedia
image={snippet?.thumbnails?.high?.url || `Thunbnail not found`}
alt={snippet?.title}
sx={{ width: { xs: '100%', sm: '358px', md: '320px'}, height: 180}}
/>
</Link>
<CardContent sx={{ backgroundColor: '#1E1E1E', height: '106px' }}>
<Link to={ videoId ? `/video/${videoId}` : `` }>
<Typography variant={"subtitle1"} fontWeight={"bold"} color={"#FFF"}>
{snippet?.title.slice(0, 60) || `No title`}
</Typography>
</Link>
<Link to={ snippet?.channelId ? `/channel/${snippet?.channelId}` : `` }>
<Typography variant={"subtitle1"} fontWeight={"bold"} color={"gray"}>
{snippet?.channelTitle.slice(0, 60) || `No channel title`}
<CheckCircle sx={ { fontSize: 12, color: 'gray', ml: '5px'}} />
</Typography>
</Link>
</CardContent>
</Card>
)
}
export default VideoCard;
+62
View File
@@ -0,0 +1,62 @@
import React, { useEffect, useState } from "react";
import { Link, useParams } from "react-router-dom";
import ReactPlayer from "react-player";
import { Typography, Box, Stack } from "@mui/material";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import { Videos, Loader } from "./";
import { api } from "../utils/api";
const VideoDetail = () => {
const [videoDetail, setVideoDetail] = useState(null);
const [videos, setVideos] = useState(null);
const { id } = useParams();
useEffect(() => {
api(`videos?part=snippet,statistics&id=${id}`)
.then((data) => setVideoDetail(data.items[0]))
api(`search?part=snippet&relatedToVideoId=${id}&type=video`)
.then((data) => setVideos(data.items))
}, [id]);
if(!videoDetail?.snippet) return <Loader />;
const { snippet: { title, channelId, channelTitle }, statistics: { viewCount, likeCount } } = videoDetail;
return (
<Box minHeight="95vh">
<Stack direction={{ xs: "column", md: "row" }}>
<Box flex={1}>
<Box sx={{ width: "100%", position: "sticky", top: "86px" }}>
<ReactPlayer url={`https://www.youtube.com/watch?v=${id}`} className="react-player" controls />
<Typography color="#fff" variant="h5" fontWeight="bold" p={2}>
{title}
</Typography>
<Stack direction="row" justifyContent="space-between" sx={{ color: "#fff" }} py={1} px={2} >
<Link to={`/channel/${channelId}`}>
<Typography color="#fff" >
{channelTitle}
<CheckCircleIcon sx={{ fontSize: "12px", color: "gray", ml: "5px" }} />
</Typography>
</Link>
<Stack direction="row" gap="20px" alignItems="center">
<Typography variant="body1" sx={{ opacity: 0.7 }}>
{parseInt(viewCount).toLocaleString()} views
</Typography>
<Typography variant="body1" sx={{ opacity: 0.7 }}>
{parseInt(likeCount).toLocaleString()} likes
</Typography>
</Stack>
</Stack>
</Box>
</Box>
<Box px={2} py={{ md: 1, xs: 5 }} justifyContent="center" alignItems="center" >
<Videos videos={videos} direction="column" />
</Box>
</Stack>
</Box>
);
};
export default VideoDetail;
+18
View File
@@ -0,0 +1,18 @@
import { Stack, Box } from '@mui/material';
import { VideoCard, ChannelCard, Loader } from './'
const Videos = ({ videos, direction }) => {
if (!videos?.length) return <Loader />
return (
<Stack direction={ direction || "row"} flexWrap={"wrap"} justifyContent={"start"} gap={2}>
{videos.map((item, idx) => (
<Box key={idx}>
{item.id.videoId && <VideoCard video={item}/>}
{item.id.channelId && <ChannelCard channelDetail={item}/>}
</Box>
))}
</Stack>
)
}
export default Videos;
+11
View File
@@ -0,0 +1,11 @@
export { default as Navbar} from './Navbar'
export { default as Feed} from './Feed'
export { default as ChannelDetail} from './ChannelDetail'
export { default as VideoDetail} from './VideoDetail'
export { default as SearchFeed} from './SearchFeed'
export { default as SearchBar} from './SearchBar'
export { default as SideBar} from './Sidebar'
export { default as Videos} from './Videos'
export { default as VideoCard } from './VideoCard'
export { default as ChannelCard } from './ChannelCard'
export { default as Loader } from './Loader'
+88
View File
@@ -0,0 +1,88 @@
html,
body {
margin: 0;
padding: 0;
box-sizing: border-box;
}
a {
text-decoration: none;
color: black;
}
::-webkit-scrollbar {
width: 0px;
height: 5px;
}
::-webkit-scrollbar-thumb {
background-color: rgb(114, 113, 113);
border-radius: 10px;
height: 200px;
}
::-webkit-scrollbar-track {
background-color: transparent;
}
.category-btn:hover {
background-color: #FC1503 !important;
color: white !important;
}
.category-btn:hover span{
color: white !important;
}
.react-player {
height: 77vh !important;
width: 100% !important;
}
.search-bar{
border:none;
outline:none;
width:350px;
}
.category-btn{
font-weight: bold !important;
text-transform: capitalize;
display: flex;
align-items: center;
justify-content: start;
cursor:pointer;
background: transparent;
outline: none;
border: none;
padding: 7px 15px;
margin: 10px 0px;
border-radius: 20px;
transition: all 0.3s ease;
}
@media screen and (max-width: 900px) {
.category-btn{
margin: 10px;
}
}
@media screen and (max-width:800px){
.copyright{
display:none !important;
}
}
@media screen and (max-width: 600px) {
.scroll-horizontal {
overflow: auto !important;
}
.react-player {
height: 45vh !important;
}
.search-bar{
width:200px;
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
+20
View File
@@ -0,0 +1,20 @@
import axios from 'axios';
const BASE_URL = 'https://youtube-v31.p.rapidapi.com'
const options = {
url: BASE_URL,
params: {
maxResults: '50'
},
headers: {
'X-RapidAPI-Key': process.env.REACT_APP_RAPID_API_KEY,
'X-RapidAPI-Host': 'youtube-v31.p.rapidapi.com'
}
};
export const api = async (url) => {
const { data } = await axios.get(`${BASE_URL}/${url}`, options);
return data;
}
+34
View File
@@ -0,0 +1,34 @@
import MusicNoteIcon from '@mui/icons-material/MusicNote';
import HomeIcon from '@mui/icons-material/Home';
import CodeIcon from '@mui/icons-material/Code';
import OndemandVideoIcon from '@mui/icons-material/OndemandVideo';
import SportsEsportsIcon from '@mui/icons-material/SportsEsports';
import LiveTvIcon from '@mui/icons-material/LiveTv';
import SchoolIcon from '@mui/icons-material/School';
import FaceRetouchingNaturalIcon from '@mui/icons-material/FaceRetouchingNatural';
import CheckroomIcon from '@mui/icons-material/Checkroom';
import GraphicEqIcon from '@mui/icons-material/GraphicEq';
import TheaterComedyIcon from '@mui/icons-material/TheaterComedy';
import FitnessCenterIcon from '@mui/icons-material/FitnessCenter';
import DeveloperModeIcon from '@mui/icons-material/DeveloperMode';
export const logo = 'https://i.ibb.co/s9Qys2j/logo.png';
export const categories = [
{ name: 'New', icon: <HomeIcon />, },
{ name: 'Coding', icon: <CodeIcon />, },
{ name: 'ReactJS', icon: <CodeIcon />, },
{ name: 'NextJS', icon: <CodeIcon />, },
{ name: 'Music', icon: <MusicNoteIcon /> },
{ name: 'Education', icon: <SchoolIcon />, },
{ name: 'Podcast', icon: <GraphicEqIcon />, },
{ name: 'Movie', icon: <OndemandVideoIcon />, },
{ name: 'Gaming', icon: <SportsEsportsIcon />, },
{ name: 'Live', icon: <LiveTvIcon />, },
{ name: 'Sport', icon: <FitnessCenterIcon />, },
{ name: 'Fashion', icon: <CheckroomIcon />, },
{ name: 'Beauty', icon: <FaceRetouchingNaturalIcon />, },
{ name: 'Comedy', icon: <TheaterComedyIcon />, },
{ name: 'Gym', icon: <FitnessCenterIcon />, },
{ name: 'Crypto', icon: <DeveloperModeIcon />, },
];