|
1 | | -// Project Icon Font: |
2 | | -// https://www.svgrepo.com/svg/384245/controller-joystick-games-video-console?edit=true |
3 | | -// https://www.svgrepo.com/svg/383702/landing-page-web-design?edit=true |
4 | | -// https://www.svgrepo.com/svg/459107/robot?edit=true |
5 | | -// https://www.svgrepo.com/svg/471159/check-square-broken?edit=true |
6 | | -// https://www.svgrepo.com/svg/383754/security-protection-lock-padlock-square-locked?edit=true |
7 | | -// https://www.svgrepo.com/svg/339111/dashboard?edit=true |
8 | | -// https://www.svgrepo.com/svg/257454/profile?edit=true |
9 | | -// https://www.svgrepo.com/svg/298828/store?edit=true |
10 | | -// https://www.svgrepo.com/svg/429278/cart-essential-shopping?edit=true |
11 | | -// https://www.svgrepo.com/svg/144539/artist-color-palette?edit=true |
12 | | -// https://www.svgrepo.com/svg/424981/online?edit=true |
13 | | -// https://www.svgrepo.com/svg/384295/weather-forecast-sunny-snow-cloud-day?edit=true |
14 | | -// https://www.svgrepo.com/svg/456864/diagram |
15 | | -// https://www.svgrepo.com/svg/455166/map-navigation?edit=true |
16 | | -// https://www.svgrepo.com/svg/343466/news-feed?edit=true |
17 | | -// https://www.svgrepo.com/svg/458454/database-1?edit=true |
| 1 | +interface IStackIcons { |
| 2 | + readonly [key: string]: string; |
| 3 | + } |
18 | 4 |
|
19 | | -import { useEffect, useState } from 'react'; |
20 | | - |
21 | | -export interface IGithubRepos { |
22 | | - name: string; |
23 | | - topics: string[]; |
24 | | - html_url: string; |
25 | | - description: string; |
26 | | - id: number; |
27 | | - homepage: string; |
28 | | - banner: () => string; |
29 | | -} |
30 | | - |
31 | | -/** |
32 | | - * @param {string} usernameGitHub - Insert your username GitHub Ex.: https://github.com/USERNAME |
33 | | - * @param {string} keyWordDeploy - Insert a keyword chosen by you. - This key is responsible for managing your projects on GitHub in topics field Ex.: https://github.com/DIGOARTHUR/github-automated-repos#--about-library-. |
34 | | - * @returns {(IGithubRepos[])} - Returns an array with the properties: name, topics, html_url, description, id, homepage. |
35 | | - */ |
36 | | -export function useGitHubAutomatedRepos(usernameGitHub: string, keyWordDeploy: string) { |
37 | | - |
38 | | - const [data, setData] = useState<IGithubRepos[]>([]); |
39 | | - const [loading, setLoading] = useState<boolean>(true); |
40 | | - const [error, setError] = useState<string>(''); |
41 | | - |
42 | | - useEffect(() => { |
43 | | - const fetchData = async () => { |
44 | | - setLoading(true); |
45 | | - try { |
46 | | - const response = await fetch(`https://api.github.com/users/${usernameGitHub}/repos?sort=created&per_page=999`); |
47 | | - if (!response.ok) { |
48 | | - throw new Error(`Unsuccessful request: ${response.statusText}`); |
49 | | - } |
50 | | - const jsonData = await response.json(); |
51 | | - setData(jsonData.filter((item: IGithubRepos) => item.topics.includes(keyWordDeploy as never))); |
52 | | - } catch (err) { |
53 | | - setError((err as Error).message); |
54 | | - } finally { |
55 | | - setLoading(false); |
56 | | - } |
57 | | - }; |
58 | | - |
59 | | - fetchData(); |
60 | | - }, [usernameGitHub, keyWordDeploy]); |
61 | | - |
62 | | - |
63 | | - const typeImg = ['svg', 'png']; |
64 | | - function checkImage(usernameGitHub: string, repositoryName: string): string { |
65 | | - let checkURL = ''; |
66 | | - typeImg.map((type) => { |
67 | | - const url = `https://raw.githubusercontent.com/${usernameGitHub}/${repositoryName}/main/src/assets/imgs/banner.${type}`; |
68 | | - const http = new XMLHttpRequest(); |
69 | | - http.open('HEAD', url, false); |
70 | | - http.send(); |
71 | | - |
72 | | - if (http.status === 200) { |
73 | | - checkURL = url; |
74 | | - } |
75 | | - }); |
76 | | - return checkURL; |
77 | | - } |
78 | | - |
79 | | - |
80 | | - |
81 | | - const repository = data.map((item: IGithubRepos) => ({ |
82 | | - |
83 | | - id: item.id, |
84 | | - name: item.name, |
85 | | - html_url: item.html_url, |
86 | | - description: item.description, |
87 | | - topics: item.topics, |
88 | | - homepage: item.homepage, |
89 | | - banner: checkImage(usernameGitHub, item.name), |
90 | | - })); |
91 | | - return { repository, loading, error }; |
92 | | - |
93 | | -} |
94 | | - |
95 | | -export function IconsData() { |
96 | | - // 25px |
97 | | - const stackIcons = { |
| 5 | +export const stackIconsURL:IStackIcons = { |
98 | 6 | androidstudio: 'https://user-images.githubusercontent.com/59892368/216783644-f664d47c-f686-496d-8073-2e83b2b469ab.svg', |
99 | 7 | angular: 'https://github-production-user-asset-6210df.s3.amazonaws.com/59892368/287532135-7c81a717-da75-4aeb-ab22-95fc2a3254be.svg', |
100 | 8 | arduino: 'https://user-images.githubusercontent.com/59892368/216785825-af6a605c-6ca3-4bb5-9889-31ad818fb20b.svg', |
@@ -191,25 +99,4 @@ export function IconsData() { |
191 | 99 | vitejs: 'https://user-images.githubusercontent.com/59892368/218274365-3eae86f7-7953-4209-b5e7-466c8335caa2.svg', |
192 | 100 | vuejs: 'https://user-images.githubusercontent.com/59892368/215260542-defd6142-e8a8-44f5-8c8a-c6dfaf3d114a.svg', |
193 | 101 | yarn: 'https://github-production-user-asset-6210df.s3.amazonaws.com/59892368/287774024-f3af28e4-40c9-4b02-b5e4-c33702c2fca0.svg', |
194 | | - }; |
195 | | - |
196 | | - // 64px |
197 | | - const projectIcons = { |
198 | | - art: 'https://user-images.githubusercontent.com/59892368/212994060-8d1644c7-96d7-4f3b-8e94-65ff76db0c92.svg', |
199 | | - artificialintelligence: 'https://user-images.githubusercontent.com/59892368/212984565-a424b06e-db5e-464a-a5df-ddf7c9bab6ad.svg', |
200 | | - dashboard: 'https://user-images.githubusercontent.com/59892368/212991791-588a6c13-795e-47aa-b496-8bdbaa3cac30.svg', |
201 | | - education: 'https://user-images.githubusercontent.com/59892368/212284904-0b4f29fa-4141-4212-b516-d4e4fcdb8519.svg', |
202 | | - game: 'https://user-images.githubusercontent.com/59892368/212984732-79dd44aa-23a5-4b83-ae28-7a2ddd443032.svg', |
203 | | - landingpage: 'https://user-images.githubusercontent.com/59892368/212984364-88a0808b-a8d1-440c-b74e-f82bc3e28748.svg', |
204 | | - personalwebsite: 'https://user-images.githubusercontent.com/59892368/213131421-fa77f07c-9120-4b40-859d-2bd799de6681.svg', |
205 | | - productivity: 'https://user-images.githubusercontent.com/59892368/212994727-f05595d9-53b7-43a5-b974-b27fa2557653.svg', |
206 | | - security: 'https://user-images.githubusercontent.com/59892368/212985266-a658da1c-64ba-46b7-a069-a148ca217be9.svg', |
207 | | - store: 'https://user-images.githubusercontent.com/59892368/213137554-83aa6798-9487-4d1b-a260-fd2035adaaad.svg', |
208 | | - }; |
209 | | - |
210 | | - return { |
211 | | - stackIcons, |
212 | | - projectIcons, |
213 | | - IconsData, |
214 | | - }; |
215 | | -} |
| 102 | + } |
0 commit comments