Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update on same set of videos issue (small feature update) #23

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Build and Deploy a Modern YouTube Clone Application in React JS with Material UI 5
Build and Deploy a Modern YouTube Clone Application in React JS with Material UI 5
YouTube

![YouTube](https://i.ibb.co/4R5RkmW/Thumbnail-5.png)

### Showcase your dev skills with practical experience and land the coding career of your dreams
💻 JS Mastery Pro - https://jsmastery.pro/youtube
✅ A special YOUTUBE discount code is automatically applied!
Showcase your dev skills with practical experience and land the coding career of your dreams
💻 JS Mastery Pro - https://jsmastery.pro/youtube ✅ A special YOUTUBE discount code is automatically applied!

📙 Get the Ultimate Frontend & Backend Development Roadmaps, a Complete JavaScript Cheatsheet, Portfolio Tips, and more - https://www.jsmastery.pro/links
2 changes: 1 addition & 1 deletion src/components/ChannelDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ChannelDetail = () => {

setChannelDetail(data?.items[0]);

const videosData = await fetchFromAPI(`search?channelId=${id}&part=snippet%2Cid&order=date`);
const videosData = await fetchFromAPI(`search?channelId=${id}&part=snippet`,true);

setVideos(videosData?.items);
};
Expand Down
25 changes: 24 additions & 1 deletion src/utils/fetchFromAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@ import axios from 'axios';

export const BASE_URL = 'https://youtube-v31.p.rapidapi.com';

let sorting = ["date","relevance","rating","title","viewCount"];
let sortingIndex = Math.floor(Math.random() * sorting.length);

let countryCodes = ["AF", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS",
"BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN",
"BG", "BF", "BI", "CV", "KH", "CM", "CA", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CD",
"CG", "CK", "CR", "HR", "CU", "CW", "CY", "CZ", "CI", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ",
"ER", "EE", "SZ", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH",
"GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU",
"IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP",
"KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MG", "MW", "MY", "MV",
"ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM",
"NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS",
"PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "MK", "RO", "RU", "RW", "RE", "BL", "SH",
"KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI",
"SB", "SO", "ZA", "GS", "SS", "ES", "LK", "SD", "SR", "SJ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH",
"TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "UM", "US", "UY",
"UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW", "AX"];

let countryIndex = Math.floor(Math.random()*countryCodes.length);

const options = {
params: {
maxResults: 50,
Expand All @@ -12,7 +33,9 @@ const options = {
},
};

export const fetchFromAPI = async (url) => {
export const fetchFromAPI = async (url,channel) => {
options.params.regionCode = countryCodes[countryIndex];
options.params.order = !channel?sorting[sortingIndex] : "date";
const { data } = await axios.get(`${BASE_URL}/${url}`, options);

return data;
Expand Down