Skip to content
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
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ACCESS_TOKEN = "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"
ACCESS_TOKEN = "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"

# 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
41 changes: 40 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"postcss": "^8.4.32",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-firebase-hooks": "^5.1.1"
"react-firebase-hooks": "^5.1.1",
"react-router-dom": "^6.21.1"
},
"devDependencies": {
"@types/react": "^18.2.43",
Expand Down
9 changes: 2 additions & 7 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { useState } from 'react'
import './styles/App.css'
import Header from './components/Header'
import List from './components/List'
import Refresh from './components/Refresh'
import Header from './components/sub-components/Header'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faBarsStaggered, faMagnifyingGlass, faCircleUser, faArrowsRotate, faCodeFork, faStar, faEye, faFilter, faFilterCircleXmark, faArrowsUpDown, faSort } from '@fortawesome/free-solid-svg-icons'
import { faGithubAlt } from '@fortawesome/free-brands-svg-icons'
import Fetch from './components/Fetch'
import Fetch from './components/pages/Fetch'
// import Activity from './components/Activity'
library.add(faBarsStaggered, faMagnifyingGlass, faCircleUser, faArrowsRotate, faCodeFork, faStar, faEye, faFilter, faFilterCircleXmark, faArrowsUpDown, faGithubAlt, faSort)

Expand All @@ -15,8 +12,6 @@ function App() {
<div className='m-4'>
<Header />
<Fetch />
{/* <Activity /> */}
{/* <Refresh /> */}
</div>
)
}
Expand Down
35 changes: 0 additions & 35 deletions src/components/Activity.jsx

This file was deleted.

102 changes: 51 additions & 51 deletions src/components/Fetch.jsx → src/components/pages/Fetch.jsx
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
import React, { useEffect, useState } from 'react'
import List from './List'
import List from '../sub-components/List.jsx'
import axios from 'axios';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import db from './firebase.js' //can import default export with any name
import db from '../../firebase.js' //can import default export with any name
import { getDocs, collection, setDoc, doc, writeBatch } from "firebase/firestore";


function Fetch() {
const [results, setResults] = useState([])
const [callFetch, setCallFetch] = useState(false);

useEffect(() => {
console.log('inside 1st useEffect')
const getRepoList = async () => {
try {
const data = await getDocs(collection(db, '001'));
console.log('Data from firestore : ', data);
const filteredData = data.docs.map((doc) => ({
...doc.data(),
id: doc.id,
}));
setResults(filteredData);
console.log('filteredData : ', filteredData);
} catch (err) {
console.error(err);
}
};
getRepoList();
}, []);
// useEffect(() => {
// console.log('inside 1st useEffect')
// const getRepoList = async () => {
// try {
// const data = await getDocs(collection(db, '001'));
// console.log('Data from firestore : ', data);
// const filteredData = data.docs.map((doc) => ({
// ...doc.data(),
// id: doc.id,
// }));
// setResults(filteredData);
// console.log('filteredData : ', filteredData);
// } catch (err) {
// console.error(err);
// }
// };
// getRepoList();
// }, []);

useEffect(() => {
console.log('results ', results);
const batch = writeBatch(db);
const addRepos = async () => {
try {
results.map((result) => {
// console.log("single item ", result);
const docRef = doc(db, "001", (result.id).toString());
const payload = {
description: result.description,
forks_count: result.forks_count,
full_name: result.full_name,
id: result.id,
owner: {
avatar_url: result.owner.avatar_url,
},
stargazers_count: result.stargazers_count,
updated_at: result.updated_at,
watchers_count: result.watchers_count
}
// console.log('payload : ', payload);
batch.set(docRef, payload);
});
await batch.commit();
} catch (err) {
console.error(err);
}
}
addRepos();
// useEffect(() => {
// console.log('results ', results);
// const batch = writeBatch(db);
// const addRepos = async () => {
// try {
// results.map((result) => {
// // console.log("single item ", result);
// const docRef = doc(db, "001", (result.id).toString());
// const payload = {
// description: result.description,
// forks_count: result.forks_count,
// full_name: result.full_name,
// id: result.id,
// owner: {
// avatar_url: result.owner.avatar_url,
// },
// stargazers_count: result.stargazers_count,
// updated_at: result.updated_at,
// watchers_count: result.watchers_count
// }
// // console.log('payload : ', payload);
// batch.set(docRef, payload);
// });
// await batch.commit();
// } catch (err) {
// console.error(err);
// }
// }
// addRepos();

}, [results])
// }, [results])


useEffect(() => {
Expand All @@ -68,7 +68,7 @@ function Fetch() {
const search = async () => {
try {
const accessToken = import.meta.env.ACCESS_TOKEN;
let apiUrl = `https://api.github.com/search/repositories?q=js&language=javascript&sort=updated&order=desc`;
let apiUrl = `https://api.github.com/search/repositories?q=js&language=javascript{&page,per_page,sort,order}`;
const response = await axios.get(apiUrl, {
headers: {
'Authorization': `${accessToken}`,
Expand Down
116 changes: 116 additions & 0 deletions src/components/pages/Issues.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React, { useEffect, useState } from 'react'
import Header from '../sub-components/Header'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import axios from 'axios';
import List from '../sub-components/List'
import { convertTime } from '../sub-components/TimeStamp';
import { isDark } from '../sub-components/isDark';


function Issues() {
const [results, setResults] = useState([])
const [callFetch, setCallFetch] = useState(false);
const [urls, setUrls] = useState();
const [url, setUrl] = useState('https://api.github.com/search/issues?q=label:goodfirstissue&sort:updatedat')

useEffect(() => {
//console.log("url, and urls: ", url, urls);
console.log("Results :", results);
}, [results])

useEffect(() => {
if (callFetch) {
const search = async () => {
try {
const accessToken = import.meta.env.ACCESS_TOKEN;
const response = await axios.get(url, {
headers: {
'Authorization': `${accessToken}`,
},
});

const link = response.headers.get("link");
const links = link.split(",");
const urls = links.map(a => {
return {
url: a.split(';')[0].replace(">", "").replace("<", ""),
title: a.split(';')[1].substring(6, 10)
}
})
setUrls(urls);
console.log('links', links, urls)


const data = response.data.items;
setResults(data);
console.log("data items: ", data, "type : ", Array.isArray(data));
} catch (error) {
console.error('Error:', error);
setResults([]);
}
setCallFetch(false);
}
search();
}
}, [callFetch, url]);

return (
<>
<Header />
{results.length > 0 ?
results.slice(0, 5).map((r, k) => (
<React.Fragment key={k}>
<div className='my-10 mx-12'>
<h1>{r.title}</h1>
<p className=' text-gray-300'>{convertTime(r.updated_at)}</p>
{r.labels.length > 0 &&
r.labels.map((l, index) => (
<React.Fragment key={index}>
{/* backgroundColor : #${l[i].color}; */}
<button
style={{ 'backgroundColor': `#${l.color}`, }}
className={`${isDark(l.color) ? "text-white " : "text-black "}bg-opacity-95 mr-4 p-2 my-2 rounded-md`}
>{l.name}</button>
</React.Fragment>
))
}
<br></br>
<p>{r.state}</p>
<a href={r.url} className='underline text-blue-600'>Go to issue <sup>↗</sup></a>
<div className='flex'>
<img src={r.user.avatar_url}
className='h-8 w-8 rounded-full mr-2' />
<p>{r.user.login}</p>
</div>
<p>{r.assignees.length} assignee{r.assignees.length > 1 ? 's' : ''}</p>
</div>
<hr />
</React.Fragment>
))
:
<>Loading...</>
}
<div
onClick={() => {
setCallFetch(true)
}}
className={`flex flex-row items-center justify-center bg-neutral-200 hover:bg-neutral-300 my-20 py-3 rounded-md ${callFetch ? 'cursor-default' : 'cursor-pointer'} text-md`}
style={{ pointerEvents: callFetch ? 'none' : 'auto' }}
>
<FontAwesomeIcon icon="fa-solid fa-arrows-rotate" className='px-2' />
Refresh</div>

{urls?.map((u) => {
return (
<button key={u.title}
className='my-10 px-4 py-2 bg-gray-300 rounded-md mx-2 cursor-pointer'
onClick={() => setUrl(u.url)}>
{u.title}
</button>
);
})}
</>
)
}

export default Issues
File renamed without changes.
File renamed without changes.
Loading