Skip to content

Commit dffa2f5

Browse files
committed
Add hover and link on contributors, connect contributor list to GitHub
1 parent b70fe1e commit dffa2f5

File tree

3 files changed

+80
-31
lines changed

3 files changed

+80
-31
lines changed

components/datapack.tsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
1-
import { Avatar, Box, Button, Card, CardContent, CardMedia, Checkbox, Chip, Collapse, Divider, FormControlLabel, Grid, Link, List, ListItem, ListItemButton, ListItemIcon, ListItemText, ListSubheader, Stack, Switch, Typography } from "@mui/material";
1+
import {
2+
Avatar,
3+
Box,
4+
Button,
5+
Card,
6+
CardContent,
7+
CardMedia,
8+
Checkbox,
9+
Chip,
10+
Collapse,
11+
Divider,
12+
FormControlLabel,
13+
Grid,
14+
Link,
15+
List,
16+
ListItem,
17+
ListItemButton,
18+
ListItemIcon,
19+
ListItemText,
20+
ListSubheader,
21+
Stack,
22+
Switch,
23+
Tooltip,
24+
Typography
25+
} from "@mui/material";
226
import React, { useState, useEffect, MouseEvent, useCallback } from "react";
327
import useTranslation from 'next-translate/useTranslation'
428
import { TransitionGroup } from "react-transition-group";
529
import { faFileArchive } from "@fortawesome/free-solid-svg-icons";
630
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
31+
import {Contributor} from "../lib/datapacks";
732

833
interface IDictionary {
934
[index: string]: boolean;
@@ -161,8 +186,12 @@ export default function Datapack({ data, minHeight }: any) {
161186
<CardContent>
162187
<Typography variant="h3" gutterBottom>{t('datapack.contributors')}</Typography>
163188
<Box sx={{ mt: 2, display: 'flex', flexWrap: 'wrap', '& > *': { mr: "8px!important" as "8px", mb: "8px!important" as "8px" } }}>
164-
{Object.keys(data.contributors).map((email: string) => (
165-
<Avatar key={email} src={data.contributors[email]} alt={email} />
189+
{data.contributors?.map((contributor: Contributor) => (
190+
<Tooltip key={contributor.id} title={contributor.login}>
191+
<Link href={contributor.url}>
192+
<Avatar src={contributor.avatar_url} alt={contributor.login} />
193+
</Link>
194+
</Tooltip>
166195
))}
167196
</Box>
168197
<Box sx={{ mt: 3, display: 'flex', flexWrap: 'wrap', '& > *': { mr: 1, mb: 1 } }}>

lib/datapacks.tsx

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -159,37 +159,57 @@ export function getReleases(): IDictionary {
159159
return canals
160160
}
161161

162-
export async function getContributors() {
162+
export interface Contributor {
163+
login: string,
164+
avatar_url: string,
165+
url: string,
166+
id: number
167+
}
163168

164-
interface EmailAvatar {
165-
[index: string]: string;
166-
}
169+
export async function getContributors(): Promise<Contributor[] | undefined> {
167170

168-
const contributorsFile = 'datapacks/contributors.json'
169-
let contributors = {} as EmailAvatar
170171
try {
171-
let contributorsRaw = fs.readFileSync(path.resolve(contributorsFile), { encoding: 'utf8' })
172-
contributors = JSON.parse(contributorsRaw)
173-
} catch (e) {
174-
try {
175-
let avatars = {} as EmailAvatar
176-
let emails: string[] | undefined = process.env.CONTRIBUTORS?.split(';')
177-
if (emails) {
178-
for (const email of emails) {
179-
await axios.get(`https://gitlab.com/api/v4/avatar?email=${email}&size=64`)
180-
.then(response => {
181-
avatars[email] = response.data.avatar_url;
182-
})
183-
}
184-
fs.writeFileSync(path.resolve(contributorsFile), JSON.stringify(avatars));
185-
contributors = avatars;
186-
}
187-
188-
} catch (error) {
189-
contributors = {}
190-
}
172+
let contributors: Contributor[] = []
173+
console.log("query")
174+
const req1 = axios.get<Contributor[]>(`https://api.github.com/repos/Gunivers/Glib/contributors`)
175+
const req2 = axios.get<Contributor[]>(`https://api.github.com/repos/Gunivers/Glib-Manager/contributors`)
176+
await axios.all([req1, req2])
177+
.then(value => contributors = [...value[0].data, ...value[1].data])
178+
return Array.from(contributors.reduce((entryMap, e: Contributor) =>
179+
entryMap.set(e.id, [...entryMap.get(e.id)||[], e]),
180+
new Map<number, Contributor[]>())
181+
.values()).flatMap(contributors => contributors[0])
182+
.map(contributor => { return { url: `https://github.com/${contributor.login}`, login: contributor.login, avatar_url: contributor.avatar_url, id: contributor.id}})
183+
// return contributors
184+
} catch {
185+
return undefined
191186
}
192-
return contributors
187+
188+
// const contributorsFile = 'datapacks/contributors.json'
189+
// //let contributors = {} as Contributor
190+
// try {
191+
// let contributorsRaw = fs.readFileSync(path.resolve(contributorsFile), { encoding: 'utf8' })
192+
// contributors = JSON.parse(contributorsRaw)
193+
// } catch (e) {
194+
// try {
195+
// let avatars = {} as Contributor
196+
// let emails: string[] | undefined = process.env.CONTRIBUTORS?.split(';')
197+
// if (emails) {
198+
// for (const email of emails) {
199+
// await axios.get(`https://gitlab.com/api/v4/avatar?email=${email}&size=64`)
200+
// .then(response => {
201+
// avatars[email] = response.data.avatar_url;
202+
// })
203+
// }
204+
// fs.writeFileSync(path.resolve(contributorsFile), JSON.stringify(avatars));
205+
// contributors = avatars;
206+
// }
207+
//
208+
// } catch (error) {
209+
// contributors = {}
210+
// }
211+
// }
212+
// return contributors
193213
}
194214

195215
export async function getGlib() {

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "es6",
44
"lib": [
55
"dom",
66
"dom.iterable",

0 commit comments

Comments
 (0)