Skip to content

Commit c25685d

Browse files
global context
1 parent 68873ef commit c25685d

File tree

7 files changed

+80
-17
lines changed

7 files changed

+80
-17
lines changed

context/GlobalProvider.jsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { createContext, useState, useEffect } from "react";
2+
import { fetchReposData } from "../utils/helpers";
3+
import { ORGNAME } from "../config/globals";
4+
5+
export const GlobalContext = createContext();
6+
7+
const GlobalProvider = ({ children }) => {
8+
const [reposData, setReposData] = useState(null);
9+
10+
useEffect(() => {
11+
// Pour éviter de multiples refetch pendant le dev (github api rate limit)
12+
if (!reposData) {
13+
fetchReposData(ORGNAME)
14+
.then((res) => {
15+
if (res) {
16+
setReposData(res);
17+
console.log("Repo data fetched");
18+
} else {
19+
setReposData(null);
20+
}
21+
})
22+
.catch((error) => {
23+
console.log(error);
24+
});
25+
}
26+
// eslint-disable-next-line react-hooks/exhaustive-deps
27+
}, []);
28+
29+
return (
30+
<GlobalContext.Provider
31+
value={{
32+
reposData,
33+
setReposData,
34+
}}
35+
>
36+
{children}
37+
</GlobalContext.Provider>
38+
);
39+
};
40+
41+
export default GlobalProvider;

context/useGlobalContext.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { useContext } from "react";
2+
import { GlobalContext } from "../context/GlobalProvider";
3+
4+
export const useGlobalContext = () => useContext(GlobalContext);

data/cardsData.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,31 @@ export const cardsData = [
7171
},
7272
],
7373
},
74+
{
75+
project: "bitguardian",
76+
imageCover: "bitguardian.jpg",
77+
title: "BitGuardian",
78+
author: "Moon",
79+
github: "https://github.com/Bit-Scripts/BitGuardian",
80+
demo: "",
81+
translations: [
82+
{
83+
lang: "en",
84+
description:
85+
"BitGuardian is a Discord moderation bot that assigns a role to new members and logs user messages. By facilitating server management, it enhances the user experience and offers extensible support for custom features.",
86+
},
87+
{
88+
lang: "fr",
89+
description:
90+
"BitGuardian est un bot Discord de modération qui attribue un rôle aux nouveaux membres et enregistre les messages utilisateur. Facilitant la gestion des serveurs, il améliore l'expérience utilisateur et offre un support extensible pour des fonctionnalités personnalisées.",
91+
},
92+
{
93+
lang: "es",
94+
description:
95+
"BitGuardian es un bot de moderación de Discord que asigna un rol a los nuevos miembros y registra los mensajes de los usuarios. Al facilitar la gestión de servidores, mejora la experiencia del usuario y ofrece soporte extensible para funciones personalizadas.",
96+
},
97+
],
98+
},
7499
{
75100
project: "lowfuel",
76101
imageCover: "lowfuel.jpg",

public/images/bitguardian.jpg

338 KB
Loading

src/App.jsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
import { useEffect } from "react";
2-
// import { ORGNAME } from "../config/globals";
3-
// import { fetchReposData } from "../utils/helpers";
41
import CardsWrapper from "./components/CardsWrapper";
52
import Header from "./components/Header";
63
import Info from "./components/Info";
74
import LangageSwitcher from "./components/LangSwitcher";
5+
import GlobalProvider from "../context/GlobalProvider";
86

97
function App() {
10-
useEffect(() => {
11-
// fetchReposData(ORGNAME);
12-
}, []);
13-
14-
console.log('"render app');
15-
168
return (
17-
<div className="min-h-screen overflow-x-hidden bg-neutral-800">
18-
<Header />
19-
<LangageSwitcher />
20-
<Info />
21-
<CardsWrapper />
22-
</div>
9+
<GlobalProvider>
10+
<div className="min-h-screen overflow-x-hidden bg-neutral-800">
11+
<Header />
12+
<LangageSwitcher />
13+
<Info />
14+
<CardsWrapper />
15+
</div>
16+
</GlobalProvider>
2317
);
2418
}
2519

src/components/Card.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function Card({
2727
{title}
2828
</div>
2929

30-
<div className="h-full max-h-[180px] overflow-hidden overflow-y-auto text-ellipsis py-4 text-sm text-neutral-200">
30+
<div className="h-full max-h-[200px] overflow-hidden text-ellipsis py-4 text-sm text-neutral-200">
3131
{t(`app.card:${translationKey}.description`)}
3232
</div>
3333

src/components/CardsWrapper.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ function CardsWrapper() {
66
<div className="flex items-center justify-center">
77
<div className="flex max-w-[1280px] flex-wrap justify-center gap-8 p-8">
88
{cardsData.map((card, i) => {
9-
console.log(card);
109
return (
1110
<Card
1211
title={card.title}

0 commit comments

Comments
 (0)