Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | 520x 18x 18x 18x 18x 18x 9x 9x 9x 9x 3x 9x 9x 18x 9x | import { ReactElement, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { AssignmentRun } from "shared/types/models/result";
import { getDateAndTime } from "shared/utils/timeFormatter";
import { Loading } from "client/components/Loading";
import { RaisedCard } from "client/components/RaisedCard";
import { getResults } from "client/services/resultsServices";
export const DashboardView = (): ReactElement => {
const { t } = useTranslation();
const [assignmentRuns, setAssignmentRuns] = useState<AssignmentRun[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const [loadingError, setLoadingError] = useState<boolean>(false);
useEffect(() => {
const loadResults = async (): Promise<void> => {
const response = await getResults();
Iif (response.status === "error") {
setLoadingError(true);
} else {
setAssignmentRuns(
[...response.assignmentRuns].sort((a, b) =>
b.assignmentTime.localeCompare(a.assignmentTime),
),
);
}
setLoading(false);
};
// eslint-disable-next-line @typescript-eslint/no-floating-promises
loadResults();
}, []);
if (loading) {
return <Loading />;
}
return (
<div>
<h2>{t("dashboardView.title")}</h2>
{loadingError && <p>{t("dashboardView.loadingError")}</p>}
{!loadingError && assignmentRuns.length === 0 && (
<p>{t("dashboardView.noResults")}</p>
)}
{assignmentRuns.map((assignmentRun) => (
<RaisedCard
key={assignmentRun.assignmentTime}
data-testid="assignment-run"
>
<h3>{getDateAndTime(assignmentRun.assignmentTime)}</h3>
<p>
{t("dashboardView.algorithm")}: {assignmentRun.algorithm}
</p>
{assignmentRun.message && (
<p>
{t("dashboardView.message")}: {assignmentRun.message}
</p>
)}
</RaisedCard>
))}
</div>
);
};
|