|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import React, { useEffect, useState } from "react"; |
1 | 4 | import { Container, Flex, Group, Stack, Text } from "@mantine/core"; |
2 | 5 | import classes from "./compatibility.module.css"; |
3 | 6 | import { AvmBlock } from "@/app/compatibility/avm"; |
4 | 7 | import Image from "next/image"; |
5 | | -import React from "react"; |
6 | 8 | import { Title } from "@mantine/core"; |
7 | 9 | import { List, ListItem } from "@mantine/core"; |
8 | 10 | import { WeeklyContributions } from "@/app/compatibility/weekly_contributions"; |
9 | 11 | import { |
10 | | - fetchReport, |
11 | 12 | getAVM1Progress, |
12 | 13 | getWeeklyContributions, |
13 | 14 | } from "@/app/downloads/github"; |
14 | 15 |
|
15 | | -export default async function Downloads() { |
16 | | - const contributions = await getWeeklyContributions(); |
17 | | - const data = contributions.data.map((item) => { |
18 | | - return { |
19 | | - week: new Date(item.week * 1000).toISOString().split("T")[0], |
20 | | - Commits: item.total, |
| 16 | +interface DataPoint { |
| 17 | + week: string; |
| 18 | + Commits: number; |
| 19 | +} |
| 20 | + |
| 21 | +export default function Downloads() { |
| 22 | + const [data, setData] = useState<DataPoint[]>([]); |
| 23 | + const [avm1ApiDone, setAvm1ApiDone] = useState<number>(0); |
| 24 | + const [avm2ApiDone, setAvm2ApiDone] = useState<number>(0); |
| 25 | + const [avm2ApiStubbed, setAvm2ApiStubbed] = useState<number>(0); |
| 26 | + useEffect(() => { |
| 27 | + const fetchData = async () => { |
| 28 | + try { |
| 29 | + // Fetch weekly contributions |
| 30 | + const contributionsRes = await getWeeklyContributions(); |
| 31 | + const contributionsData = contributionsRes.data.map((item) => ({ |
| 32 | + week: new Date(item.week * 1000).toISOString().split("T")[0], |
| 33 | + Commits: item.total, |
| 34 | + })); |
| 35 | + setData(contributionsData); |
| 36 | + |
| 37 | + // Fetch AVM1 progress |
| 38 | + const avm1ApiRes = await getAVM1Progress(); |
| 39 | + setAvm1ApiDone(avm1ApiRes); |
| 40 | + |
| 41 | + // Fetch report |
| 42 | + const reportReq = await fetch("/compatibility/fetch-report"); |
| 43 | + const reportRes = await reportReq.json(); |
| 44 | + if (reportRes) { |
| 45 | + const { summary } = reportRes; |
| 46 | + const maxPoints = summary.max_points; |
| 47 | + const implPoints = summary.impl_points; |
| 48 | + const stubPenalty = summary.stub_penalty; |
| 49 | + |
| 50 | + const avm2ApiDone = Math.round( |
| 51 | + ((implPoints - stubPenalty) / maxPoints) * 100, |
| 52 | + ); |
| 53 | + setAvm2ApiDone(avm2ApiDone); |
| 54 | + |
| 55 | + const avm2ApiStubbed = Math.round((stubPenalty / maxPoints) * 100); |
| 56 | + setAvm2ApiStubbed(avm2ApiStubbed); |
| 57 | + } |
| 58 | + } catch (error) { |
| 59 | + console.error("Error fetching data", error); |
| 60 | + } |
21 | 61 | }; |
22 | | - }); |
23 | | - const avm1ApiDone = await getAVM1Progress(); |
24 | | - const report = await fetchReport(); |
25 | | - if (!report) { |
26 | | - return; |
27 | | - } |
28 | | - const summary = report.summary; |
29 | | - const maxPoints = summary.max_points; |
30 | | - const implPoints = summary.impl_points; |
31 | | - const stubPenalty = summary.stub_penalty; |
32 | | - const avm2ApiDone = Math.round( |
33 | | - ((implPoints - stubPenalty) / maxPoints) * 100, |
34 | | - ); |
35 | | - const avm2ApiStubbed = Math.round((stubPenalty / maxPoints) * 100); |
| 62 | + |
| 63 | + fetchData(); |
| 64 | + }, []); |
36 | 65 |
|
37 | 66 | return ( |
38 | 67 | <Container size="xl" className={classes.container}> |
|
0 commit comments