Skip to content

Commit f9abed4

Browse files
update
1 parent c25685d commit f9abed4

File tree

7 files changed

+96
-23
lines changed

7 files changed

+96
-23
lines changed

config/globals.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export const GUILDID = "1039788044691181608";
33
export const DISCORDINVITECODE = "uAtm6aMnHR";
44
export const BASE_IMG_PATH = "/images/";
55
export const DEFAULT_IMG_COVER = "default_card_cover.jpg";
6+
export const GITHUB_BASE_URL = "https://github.com/Bit-Scripts/";

data/cardsData.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
/**
88
* @typedef {Object} CardsData
9-
* @property {string} project - REQUIS - "project" devient la clé unique de l'objet qui contient toutes les infos et traductions relatives à la carte et qui seront poussées à i18n lors de l'initialisation.
9+
* @property {string} githubRepoName - !Doit correspondre exactement au nom du repo
10+
* @property {string} project - REQUIS - "project" devient la clé unique de l'objet qui contient toutes les infos et traductions relatives à la carte et qui seront poussées lors de l'initialisation.
1011
* @property {string} imageCover - Nom du fichier image avec extension.
1112
* @property {string} title - Nom du projet affiché sur la carte.
1213
* @property {string} author - Auteur du projet affiché sur la carte.
13-
* @property {string} github - Nom exact du repo pour pouvoir afficher les infos du projet.
14+
* @property {string} github - lien vers le repo
1415
* @property {string} demo - URL de démo du projet.
1516
* @property {Translation[]} translations - Description du projet dans toutes les langues souhaitées. Dans le cas où vous ne fournissez qu'une langue, ce doit être l'anglais.
1617
*/
@@ -22,6 +23,7 @@
2223

2324
export const cardsData = [
2425
{
26+
githubRepoName: "Marv",
2527
project: "marv",
2628
imageCover: "marv.jpg",
2729
title: "Marv",
@@ -47,11 +49,12 @@ export const cardsData = [
4749
],
4850
},
4951
{
52+
githubRepoName: "Matrix",
5053
project: "matrix",
5154
imageCover: "matrix.jpg",
5255
title: "Matrix",
5356
author: "Paul",
54-
github: "Matrix",
57+
github: "https://github.com/Bit-Scripts/Matrix",
5558
demo: "",
5659
translations: [
5760
{
@@ -72,6 +75,7 @@ export const cardsData = [
7275
],
7376
},
7477
{
78+
githubRepoName: "BitGuardian",
7579
project: "bitguardian",
7680
imageCover: "bitguardian.jpg",
7781
title: "BitGuardian",
@@ -97,6 +101,7 @@ export const cardsData = [
97101
],
98102
},
99103
{
104+
githubRepoName: "Low-Fuel",
100105
project: "lowfuel",
101106
imageCover: "lowfuel.jpg",
102107
title: "Low-Fuel",

hooks/useProjectInfo.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { useMemo } from "react";
2+
3+
function useProjectInfo(reposData, githubRepoName) {
4+
const findProjectObjectByName = (array, name) => {
5+
if (!array) {
6+
console.error("Vous devez fournir un tableau");
7+
return null;
8+
}
9+
10+
if (!name) {
11+
console.error("Vous devez fournir un élément à rechercher");
12+
return null;
13+
}
14+
return array.find((item) => item.name === name);
15+
};
16+
17+
const projectInfo = useMemo(() => {
18+
return findProjectObjectByName(reposData, githubRepoName);
19+
}, [reposData, githubRepoName]);
20+
21+
return projectInfo;
22+
}
23+
24+
export default useProjectInfo;

src/components/Card.jsx

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useTranslation } from "react-i18next";
22
import { FaGithub } from "react-icons/fa";
33
import { MdOutlineRemoveRedEye } from "react-icons/md";
44
import { BASE_IMG_PATH, DEFAULT_IMG_COVER } from "../../config/globals";
5+
import GithubInfo from "./GithubInfo";
56

67
function Card({
78
imgName = DEFAULT_IMG_COVER,
@@ -10,14 +11,15 @@ function Card({
1011
demoUrl,
1112
author,
1213
githubProjectUrl,
14+
githubRepoName,
1315
}) {
1416
const { t } = useTranslation();
1517

1618
const buttonStyle =
1719
"bg-accentDarker flex min-w-[120px] cursor-pointer items-center justify-center rounded-full py-2 text-white transition-opacity hover:opacity-80";
1820

1921
return (
20-
<div className="h-[520px] w-[330px] overflow-hidden rounded-2xl bg-neutral-900 shadow-lg">
22+
<div className="h-[580px] w-[330px] overflow-hidden rounded-2xl bg-neutral-900 shadow-lg">
2123
<div
2224
className={`h-[200px] border-b border-accent bg-cover`}
2325
style={{ backgroundImage: `url(${BASE_IMG_PATH}${imgName})` }}
@@ -27,27 +29,29 @@ function Card({
2729
{title}
2830
</div>
2931

30-
<div className="h-full max-h-[200px] overflow-hidden text-ellipsis py-4 text-sm text-neutral-200">
32+
<div className="max-h-[250px] overflow-hidden pt-2 text-sm text-neutral-200">
3133
{t(`app.card:${translationKey}.description`)}
3234
</div>
33-
34-
<div className="py-4 text-center italic text-neutral-300">
35-
{t("devby")} <span className="font-bold">{author}</span>
36-
</div>
37-
38-
<div className="flex justify-center gap-x-4 py-2">
39-
{githubProjectUrl && (
40-
<a className={`${buttonStyle}`} href={githubProjectUrl}>
41-
<FaGithub size={"20"} className="mr-2" />
42-
GitHub
43-
</a>
44-
)}
45-
46-
{demoUrl && (
47-
<a className={`${buttonStyle}`} href={demoUrl}>
48-
<MdOutlineRemoveRedEye size={"24"} className="mr-2" /> Demo
49-
</a>
50-
)}
35+
<GithubInfo githubRepoName={githubRepoName} />
36+
37+
<div className="flex grow flex-col justify-end">
38+
<div className="text-center italic text-neutral-300">
39+
{t("devby")} <span className="font-bold">{author}</span>
40+
</div>
41+
<div className="flex justify-center gap-x-4 py-2">
42+
{githubProjectUrl && (
43+
<a className={`${buttonStyle}`} href={githubProjectUrl}>
44+
<FaGithub size={"20"} className="mr-2" />
45+
GitHub
46+
</a>
47+
)}
48+
49+
{demoUrl && (
50+
<a className={`${buttonStyle}`} href={demoUrl}>
51+
<MdOutlineRemoveRedEye size={"24"} className="mr-2" /> Demo
52+
</a>
53+
)}
54+
</div>
5155
</div>
5256
</div>
5357
</div>

src/components/CardsWrapper.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function CardsWrapper() {
1515
demoUrl={card.demo}
1616
author={card.author}
1717
githubProjectUrl={card.github}
18+
githubRepoName={card.githubRepoName}
1819
/>
1920
);
2021
})}

src/components/GithubInfo.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { useGlobalContext } from "../../context/useGlobalContext";
2+
import useProjectInfo from "../../hooks/useProjectInfo";
3+
import { convertDate } from "../../utils/helpers";
4+
5+
export function GithubInfo({ githubRepoName }) {
6+
const { reposData } = useGlobalContext();
7+
const projectInfo = useProjectInfo(reposData, githubRepoName);
8+
9+
if (!projectInfo) return null;
10+
11+
return (
12+
<div className="mb-4 flex justify-center gap-4">
13+
<div className="mt-4 flex flex-col items-center rounded bg-slate-600 px-3 py-1 text-xs font-semibold text-neutral-200">
14+
<span className="font-bold">Last commit</span>
15+
<span>{convertDate(projectInfo?.updated_at)}</span>
16+
</div>
17+
18+
<div className="mt-4 flex flex-col items-center rounded bg-slate-700 px-3 py-1 text-xs font-semibold text-neutral-200">
19+
<span className="font-bold">Language</span>
20+
<span>{projectInfo?.language}</span>
21+
</div>
22+
23+
<div className="mt-4 flex flex-col items-center rounded bg-slate-800 px-3 py-1 text-xs font-semibold text-neutral-200">
24+
<span className="font-bold">Licence</span>
25+
<span>{projectInfo?.license?.key ?? "N/A"}</span>
26+
</div>
27+
</div>
28+
);
29+
}
30+
31+
export default GithubInfo;

utils/helpers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,10 @@ export const normalizeLang = (lang) => {
7171
}
7272
return lang;
7373
};
74+
75+
export function convertDate(dateStr) {
76+
if (!dateStr) return null;
77+
const dateObj = new Date(dateStr);
78+
const formattedDate = `${String(dateObj.getDate()).padStart(2, "0")}/${String(dateObj.getMonth() + 1).padStart(2, "0")}/${dateObj.getFullYear()}`;
79+
return formattedDate;
80+
}

0 commit comments

Comments
 (0)