Skip to content

Commit

Permalink
update: header
Browse files Browse the repository at this point in the history
  • Loading branch information
Nayana62 committed Jan 19, 2024
1 parent 78fcda8 commit aac9e5f
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 77 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/components/CommentsContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import CommentsList from "./CommentsList";
import commentsDummyData from "../constants/commentsDummyData";

const CommentsContainer = () => {
return (
<div>
<h2 className=" font-bold text-lg mb-2">Comments:</h2>
<CommentsList comments={commentsDummyData} />
</div>
);
};

export default CommentsContainer;
6 changes: 2 additions & 4 deletions src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import Logo from "../assets/youtube_logo.jpg";
import { useDispatch, useSelector } from "react-redux";
import { cacheResults } from "../redux/cacheSlice";
import { Link, useNavigate } from "react-router-dom";

const searchSuggestionsAPI =
process.env.REACT_APP_YOUTUBE_SEARCH_SUGGESTIONS_API;
import { YOUTUBE_SEARCH_SUGGESTIONS_API } from "../constants/constants";

const Header = ({ toggleMenu }) => {
const navigate = useNavigate();
Expand Down Expand Up @@ -52,7 +50,7 @@ const Header = ({ toggleMenu }) => {

const getSearchSuggestions = async () => {
try {
const data = await fetch(searchSuggestionsAPI + searchQuery);
const data = await fetch(YOUTUBE_SEARCH_SUGGESTIONS_API + searchQuery);
const json = await data.json();
setSuggestions(json[1]);

Expand Down
39 changes: 39 additions & 0 deletions src/components/SearchResultsContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import moment from "moment";
import React from "react";
import { Link } from "react-router-dom";
import Channel from "./Channel";

const SearchResultsContainer = ({ video }) => {
return (
<Link
to={"/watch?v=" + video?.id?.videoId}
key={video.id.videoId || video.id.channelId || video.id.playlistId}
>
{video?.id?.kind !== "youtube#playlist" && (
<div className="flex flex-col sm:flex-row gap-2 relative">
<img
src={video?.snippet?.thumbnails?.medium?.url}
alt="thumbnail"
className={` mb-5 ${
video?.id?.kind === "youtube#channel"
? "rounded-full w-full sm:w-2/12 h-[12rem] mx-[5rem]"
: "rounded-xl w-full sm:w-4/12 h-[12rem]"
}`}
/>
<div className="w-full sm:w-8/12">
<h2 className=" text-lg">{video?.snippet?.title}</h2>
<p className=" text-[14px] text-[#606060] ml-1">
{moment(video?.snippet?.publishedAt).fromNow()}
</p>
<div className=" my-4">
<Channel channelId={video?.snippet?.channelId} />
</div>
<p className=" text-xs my-4">{video?.snippet?.description}</p>
</div>
</div>
)}
</Link>
);
};

export default SearchResultsContainer;
42 changes: 28 additions & 14 deletions src/constants/commentsDummyData.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
const commentsDummyData = [
{
username: "@user1",
id: 1,
username: "@john123",
comment: "Great video!",
likes: 3,
replies: [
{
username: "@user11",
id: 11,
username: "@jane456",
comment: "Thanks! I enjoyed it too.",
likes: 2,
replies: [
{
username: "@user111",
id: 111,
username: "@steve789",
comment: "The content was amazing!",
likes: 1,
replies: [
{
username: "@user1111",
id: 1111,
username: "@alice012",
comment: "I agree! The presenter was fantastic.",
likes: 3,
replies: [],
},
{
username: "@user1112",
id: 1112,
username: "@bob345",
comment: "Looking forward to more videos like this.",
likes: 2,
replies: [],
},
],
},
{
username: "@user12",
id: 12,
username: "@kate678",
comment: "Keep up the good work!",
likes: 1,
replies: [],
Expand All @@ -39,50 +45,58 @@ const commentsDummyData = [
],
},
{
username: "@user2",
id: 2,
username: "@david890",
comment: "Interesting topic!",
likes: 5,
replies: [
{
username: "@user21",
id: 21,
username: "@emily123",
comment: "I learned a lot from this video.",
likes: 4,
replies: [
{
username: "@user211",
id: 211,
username: "@oliver456",
comment: "Me too! The explanations were clear.",
likes: 2,
replies: [],
},
{
username: "@user212",
id: 212,
username: "@sophia789",
comment: "The visuals helped a lot in understanding.",
likes: 3,
replies: [],
},
],
},
{
username: "@user22",
id: 22,
username: "@charlotte012",
comment: "Can you cover more advanced topics?",
likes: 7,
replies: [],
},
],
},
{
username: "@user3",
id: 3,
username: "@ben345",
comment: "I enjoyed every minute of it!",
likes: 8,
replies: [
{
username: "@user31",
id: 31,
username: "@emma678",
comment: "The examples were really helpful.",
likes: 5,
replies: [],
},
{
username: "@user32",
id: 32,
username: "@liam890",
comment: "Great job explaining complex concepts.",
likes: 6,
replies: [],
Expand Down
44 changes: 3 additions & 41 deletions src/pages/SearchResults.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { useEffect, useState } from "react";
import SearchButtons from "../components/SearchButtons";
import { getSearchResults } from "../fetchData/getSearchResults";
import { Link, useSearchParams } from "react-router-dom";
import { useSearchParams } from "react-router-dom";
import { useSelector } from "react-redux";
import moment from "moment";
import Channel from "../components/Channel";
import ErrorPage from "../components/ErrorPage";
import SearchResultsContainer from "../components/SearchResultsContainer";

const SearchResults = () => {
const { isMenuOpen } = useSelector((store) => store.app);
Expand Down Expand Up @@ -34,44 +33,7 @@ const SearchResults = () => {
{searchResults.length !== 0 && (
<div className="m-auto max-w-6xl px-10">
{searchResults.map((video) => {
return (
<Link
to={"/watch?v=" + video?.id?.videoId}
key={
video.id.videoId ||
video.id.channelId ||
video.id.playlistId
}
>
{video?.id?.kind !== "youtube#playlist" && (
<div className="flex flex-col sm:flex-row gap-2 relative">
<img
src={video?.snippet?.thumbnails?.medium?.url}
alt="thumbnail"
className={` mb-5 ${
video?.id?.kind === "youtube#channel"
? "rounded-full w-full sm:w-2/12 h-[12rem] mx-[5rem]"
: "rounded-xl w-full sm:w-4/12 h-[12rem]"
}`}
/>
<div className="w-full sm:w-8/12">
<h2 className=" text-lg">
{video?.snippet?.title}
</h2>
<p className=" text-[14px] text-[#606060] ml-1">
{moment(video?.snippet?.publishedAt).fromNow()}
</p>
<div className=" my-4">
<Channel channelId={video?.snippet?.channelId} />
</div>
<p className=" text-xs my-4">
{video?.snippet?.description}
</p>
</div>
</div>
)}
</Link>
);
return <SearchResultsContainer video={video} />;
})}
</div>
)}
Expand Down
12 changes: 2 additions & 10 deletions src/pages/WatchVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import SuggestedVideos from "../components/SuggestedVideos";
import ButtonsList from "../components/ButtonsList";
import { getVideo } from "../fetchData/getVideo";
import Channel from "../components/Channel";
import CommentsList from "../components/CommentsList";
import commentsDummyData from "../constants/commentsDummyData";
import LiveChat from "../components/LiveChat";
import ErrorPage from "../components/ErrorPage";
import CommentsContainer from "../components/CommentsContainer";

const WatchVideo = () => {
const dispatch = useDispatch();
Expand All @@ -33,12 +32,6 @@ const WatchVideo = () => {
// eslint-disable-next-line
}, []);

// if (videosList.length !== 0) {
// var suggestedVideos = videosList.filter((videos) => videos.id !== videoId);
// }

console.log("videosList", videosList);

return (
<>
{videosList.error ? (
Expand Down Expand Up @@ -70,8 +63,7 @@ const WatchVideo = () => {
</div>
</>
)}
<h2 className=" font-bold text-lg mb-2">Comments:</h2>
<CommentsList comments={commentsDummyData} />
<CommentsContainer />
</div>
</div>
<div className="hidden w-4/12 lg:block">
Expand Down

0 comments on commit aac9e5f

Please sign in to comment.