Skip to content

Commit

Permalink
added youtube search
Browse files Browse the repository at this point in the history
  • Loading branch information
darylbg committed Aug 24, 2023
1 parent 99fe7bf commit bbf3ab4
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
.env

# dependencies
/node_modules
Expand Down
99 changes: 94 additions & 5 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.4.0",
"bootstrap": "^5.3.1",
"dotenv": "^16.3.1",
"react": "^18.2.0",
"react-bootstrap": "^2.8.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"split-pane-react": "^0.1.3",
"web-vitals": "^2.1.4"
"web-vitals": "^2.1.4",
"youtube-search": "^1.1.6",
"youtube-search-api": "^1.2.1"
},
"scripts": {
"start": "react-scripts start",
Expand Down
4 changes: 2 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Sidebar from "./sections/Sidebar";
import Chat from "./sections/Chat";
import Footer from "./sections/Footer";
import React, { useState, useEffect } from "react";
import SplitPane, { Pane } from "split-pane-react";
Expand Down Expand Up @@ -54,7 +54,7 @@ function App() {
<button onClick={handleChatToggleOff} className="close-chat-btn">
x
</button>
<Sidebar />
<Chat />
</div>
</div>
</SplitPane>
Expand Down
38 changes: 38 additions & 0 deletions src/sections/Chat.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useState, useEffect } from "react";

function Chat() {
const [searchResults, setSearchResults] = useState([]);

useEffect(() => {
const apiKey = "AIzaSyCk_cO8UzS_H1vab6iGke7RSS0xJt1BAu8";
const keyword = "react";
const maxResults = 10;

const apiUrl = `https://www.googleapis.com/youtube/v3/search?part=snippet&q=${keyword}&type=video&maxResults=${maxResults}&key=${apiKey}`;

const fetchData = async () => {
try {
const response = await fetch(apiUrl);
const data = await response.json();
setSearchResults(data.items);
} catch (error) {
console.error("Error fetching data:", error);
}
};

fetchData();
}, []);
console.log(searchResults[0].snippet);
return (
<div className="chat">
<h3>Chat</h3>
<ul>
{searchResults.map((result) => (
<li key={result.id.videoId}>{result.snippet.title}</li>
))}
</ul>
</div>
);
}

export default Chat;
10 changes: 0 additions & 10 deletions src/sections/Sidebar.jsx

This file was deleted.

0 comments on commit bbf3ab4

Please sign in to comment.