Skip to content

Commit

Permalink
fetching apis
Browse files Browse the repository at this point in the history
  • Loading branch information
kmr-ankitt committed Jun 16, 2024
1 parent a0fb60d commit 685834c
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ dist-ssr
*.njsproj
*.sln
*.sw?
.env
122 changes: 122 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.2",
"dotenv": "^16.4.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.52.0",
Expand Down
22 changes: 17 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import Input from "./components/Input"
import Navbar from "./components/Navbar"
import { useState } from "react";
import Calculator from "./api/Calculator";
import Input from "./components/Input";
import Navbar from "./components/Navbar";

function App() {
const [id, setid] = useState<string>("");

const handleID = (id: string) => {
if (id === "") {
throw new Error("Invalid URL");
}
setid(id);
};

return (
<div className="bg-zinc-900 text-zinc-200 h-screen font-mono">
<Navbar />
<Input />
<Input sendID={handleID} />
<Calculator pID={id} />
</div>
)
);
}

export default App
export default App;
45 changes: 40 additions & 5 deletions src/api/Calculator.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
function Calculator() {
import React, { useEffect } from 'react';
import axios from 'axios';

type CalculatorProps = {
pID: string;
};

const Calculator: React.FC<CalculatorProps> = ({ pID }) => {
useEffect(() => {
const getVideoIDs = async () => {
try {
const response = await axios.get(`https://www.googleapis.com/youtube/v3/playlistItems`, {
params: {
part: 'snippet',
playlistId: pID,
key: import.meta.env.VITE_API_KEY
},
headers: {
'x-api-key': import.meta.env.VITE_API_KEY
}
});

console.log('Playlist Items:', response.data.items);
} catch (error) {
console.error('Error fetching playlist items:', error);
}
};

if (pID) {
getVideoIDs();
}
}, [pID]);

console.log('Playlist ID:', pID);

return (
<div>

<p>Playlist ID: {pID}</p>
<p>Video ID: {pID}</p>
</div>
)
}
);
};

export default Calculator
export default Calculator;
1 change: 0 additions & 1 deletion src/assets/react.svg

This file was deleted.

0 comments on commit 685834c

Please sign in to comment.