Skip to content

Commit f32fb6e

Browse files
committed
Added api and other functions
1 parent 85afc42 commit f32fb6e

File tree

12 files changed

+152
-12
lines changed

12 files changed

+152
-12
lines changed

.prettierrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"singleQuote": true,
2+
"singleQuote": false,
33
"jsxSingleQuote": true,
44
"semi": false,
55
"tabWidth": 2,
66
"bracketSpacing": true,
77
"jsxBracketSameLine": false,
88
"arrowParens": "always",
99
"trailingComma": "none"
10-
}
10+
}

example/src/App.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import React from 'react'
1+
import React from "react"
22

3-
import { ExampleComponent } from 'github-repo-display-react'
4-
import 'github-repo-display-react/dist/index.css'
3+
import { GithubRepoDisplay } from "github-repo-display-react"
4+
import "github-repo-display-react/dist/index.css"
55

66
const App = () => {
7-
return <ExampleComponent text="Create React Library Example 😄" />
7+
return (
8+
<div className='repos'>
9+
<GithubRepoDisplay userName='msmfa' />
10+
</div>
11+
)
812
}
913

1014
export default App

package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"deploy": "gh-pages -d example/build"
2525
},
2626
"peerDependencies": {
27-
"react": "^16.0.0"
27+
"react": "^16.0.0",
28+
"axios": "^0.19.2"
2829
},
2930
"devDependencies": {
3031
"microbundle-crl": "^0.13.10",
@@ -45,7 +46,8 @@
4546
"prettier": "^2.0.4",
4647
"react": "^16.13.1",
4748
"react-dom": "^16.13.1",
48-
"react-scripts": "^3.4.1"
49+
"react-scripts": "^3.4.1",
50+
"axios": "^0.19.2"
4951
},
5052
"files": [
5153
"dist"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from "react"
2+
import { removeDash } from "../helper/removeDash"
3+
import { sortByMostRecentDate } from "../helper/sortByMostRecentDate"
4+
import { convertToHours } from "../helper/convertToHours"
5+
import { arrayToLength } from "../helper/arrayToLength"
6+
import { getRemainingSeconds } from "../helper/getRemainingSeconds"
7+
8+
export function DisplaySortedRepoData({ repoData, numOfrepos }) {
9+
const sortedRepos = sortByMostRecentDate(repoData)
10+
const sortedAndReducedRepos = arrayToLength(sortedRepos, numOfrepos)
11+
12+
return (
13+
<div>
14+
{sortedAndReducedRepos
15+
? sortedAndReducedRepos.map((repo) => (
16+
<ul key={repo.id}>
17+
<li>{removeDash(repo.name)}</li>
18+
<li>{repo.description}</li>
19+
<li>
20+
<a
21+
href={repo.html_url}
22+
target='_blank'
23+
rel='noopener noreferrer'
24+
>
25+
Github
26+
</a>
27+
</li>
28+
<li>
29+
{convertToHours(
30+
getRemainingSeconds(new Date(repo.updated_at), Date.now())
31+
)}
32+
</li>
33+
</ul>
34+
))
35+
: null}
36+
</div>
37+
)
38+
}

src/helper/arrayToLength.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function arrayToLength(array, length) {
2+
if (array) return array.splice(0, length)
3+
}

src/helper/convertToHours.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function convertToHours(seconds) {
2+
if (seconds >= 63072000) return `${Math.floor(seconds / 31536000)} years ago`
3+
if (seconds >= 31536000) return `${Math.floor(seconds / 31536000)} year ago`
4+
if (seconds >= 5184000) return `${Math.floor(seconds / 2592000)} months ago`
5+
if (seconds >= 2592000) return `${Math.floor(seconds / 2592000)} month ago`
6+
if (seconds >= 1209600) return `${Math.floor(seconds / 604800)} weeks ago`
7+
if (seconds >= 604800) return `${Math.floor(seconds / 604800)} week ago`
8+
if (seconds >= 172800) return `${Math.floor(seconds / 86400)} days ago`
9+
if (seconds >= 86400) return `${Math.floor(seconds / 86400)} day ago`
10+
if (seconds >= 7200) return `${Math.floor(seconds / 3600)} hours ago`
11+
if (seconds >= 3600) return `${Math.floor(seconds / 3600)} hour ago`
12+
if (seconds >= 120) return `${Math.floor(seconds / 60)} minutes ago`
13+
if (seconds >= 60) return `${Math.floor(seconds / 60)} minute ago`
14+
if (seconds < 60) return `${Math.floor(seconds)} seconds ago`
15+
}

src/helper/fetchApiData.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Axios from "axios"
2+
3+
export const fetchApiData = async (username) => {
4+
const response = await Axios.get(
5+
`https://api.github.com/users/${username}/repos`
6+
)
7+
return response.data
8+
}

src/helper/getRemainingSeconds.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const getRemainingSeconds = (previousDate, currentDate) => {
2+
return Math.floor((currentDate - previousDate) / 1000)
3+
}

src/helper/removeDash.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function removeDash(string) {
2+
return string.replace(/-/g, " ")
3+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy