Skip to content

Commit cfd787e

Browse files
authored
Merge branch '1.3.x' into 20-usegithubautomatedrepos-add-other-type-of-img-file-in-banner---svg
2 parents d1f4581 + dda12e8 commit cfd787e

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22

33
<!--Commit changes
4-
docs: update Readme
4+
55
-->
66

77
<!-- VISUALIZAR NO VSCODE CTRL + K V -->
@@ -326,7 +326,7 @@ import { useGitHubAutomatedRepos, ProjectIcons, StackIcons, StackLabels } from '
326326
...
327327
{item.topics.map((icon, index) => {
328328
return (
329-
<StackLabes key={ index } itemTopics={ icon } className={ } />
329+
<StackLabels key={ index } itemTopics={ icon } className={ } />
330330
}
331331
...
332332

README_PT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ Array(0)
311311
...
312312
{item.topics.map((icon, index) => {
313313
return (
314-
<StackLabes key={ index } itemTopics={ icon } className={ } />
314+
<StackLabels key={ index } itemTopics={ icon } className={ } />
315315
}
316316
...
317317
```

src/hooks/useGithubAutomatedRepos.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,33 @@ export interface IGithubRepos {
3434
* @returns {(IGithubRepos[])} - Returns an array with the properties: name, topics, html_url, description, id, homepage.
3535
*/
3636
export function useGitHubAutomatedRepos(usernameGitHub: string, keyWordDeploy: string) {
37-
const [repository, setRepository] = useState<IGithubRepos[]>([]);
3837

39-
useEffect(() => {
40-
fetch(`https://api.github.com/users/${usernameGitHub}/repos?sort=created&per_page=999`)
41-
.then((response) => response.json())
42-
.then((data) => setRepository(data));
43-
}, []);
44-
45-
let dataFilter = [];
38+
const [data, setData] = useState<IGithubRepos[]>([]);
39+
const [loading, setLoading] = useState<boolean>(true);
40+
const [error, setError] = useState<string>('');
4641

47-
dataFilter = repository.filter((item: IGithubRepos) => item.topics.includes(keyWordDeploy as never));
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+
};
4858

49-
const typeImg = ['svg', 'png'];
59+
fetchData();
60+
}, [usernameGitHub, keyWordDeploy]);
61+
62+
63+
const typeImg = ['svg', 'png'];
5064
function checkImage(usernameGitHub: string, repositoryName: string): string {
5165
let checkURL = '';
5266
typeImg.map((type) => {
@@ -61,8 +75,11 @@ export function useGitHubAutomatedRepos(usernameGitHub: string, keyWordDeploy: s
6175
});
6276
return checkURL;
6377
}
78+
79+
80+
81+
const repository = data.map((item: IGithubRepos) => ({
6482

65-
return dataFilter.map((item: IGithubRepos) => ({
6683
id: item.id,
6784
name: item.name,
6885
html_url: item.html_url,
@@ -71,6 +88,8 @@ export function useGitHubAutomatedRepos(usernameGitHub: string, keyWordDeploy: s
7188
homepage: item.homepage,
7289
banner: checkImage(usernameGitHub, item.name),
7390
}));
91+
return { repository, loading, error };
92+
7493
}
7594

7695
export function IconsData() {

0 commit comments

Comments
 (0)