Patched the module badges on the training view
This commit is contained in:
@@ -85,7 +85,7 @@ const Training: React.FC<{ user: User }> = ({ user }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const postStats = async () => {
|
const postStats = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post<{id: string}>(`/api/training`, stats);
|
const response = await axios.post<{ id: string }>(`/api/training`, stats);
|
||||||
return response.data.id;
|
return response.data.id;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setIsNewContentLoading(false);
|
setIsNewContentLoading(false);
|
||||||
@@ -93,7 +93,7 @@ const Training: React.FC<{ user: User }> = ({ user }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (isNewContentLoading) {
|
if (isNewContentLoading) {
|
||||||
postStats().then( id => {
|
postStats().then(id => {
|
||||||
setTrainingStats([]);
|
setTrainingStats([]);
|
||||||
if (id) {
|
if (id) {
|
||||||
router.push(`/training/${id}`)
|
router.push(`/training/${id}`)
|
||||||
@@ -220,6 +220,7 @@ const Training: React.FC<{ user: User }> = ({ user }) => {
|
|||||||
const trainingContentContainer = (timestamp: string) => {
|
const trainingContentContainer = (timestamp: string) => {
|
||||||
if (!groupedByTrainingContent) return <></>;
|
if (!groupedByTrainingContent) return <></>;
|
||||||
const trainingContent: ITrainingContent = groupedByTrainingContent[timestamp];
|
const trainingContent: ITrainingContent = groupedByTrainingContent[timestamp];
|
||||||
|
const uniqueModules = [...new Set(trainingContent.exams.map(exam => exam.module))];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -236,11 +237,9 @@ const Training: React.FC<{ user: User }> = ({ user }) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<div className="w-full flex flex-row gap-1">
|
<div className="w-full flex flex-row gap-1">
|
||||||
{Object.values(groupedByTrainingContent || {}).flatMap((content) =>
|
{uniqueModules.map((module) => (
|
||||||
content.exams.map(({ module, id }) => (
|
<ModuleBadge key={module} module={module} />
|
||||||
<ModuleBadge key={id} module={module} />
|
))}
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -270,7 +269,7 @@ const Training: React.FC<{ user: User }> = ({ user }) => {
|
|||||||
{(isNewContentLoading || isLoading ? (
|
{(isNewContentLoading || isLoading ? (
|
||||||
<div className="absolute left-1/2 top-1/2 flex h-fit w-fit -translate-x-1/2 -translate-y-1/2 animate-pulse flex-col items-center gap-12">
|
<div className="absolute left-1/2 top-1/2 flex h-fit w-fit -translate-x-1/2 -translate-y-1/2 animate-pulse flex-col items-center gap-12">
|
||||||
<span className="loading loading-infinity w-32 bg-mti-green-light" />
|
<span className="loading loading-infinity w-32 bg-mti-green-light" />
|
||||||
{ isNewContentLoading && (<span className="text-center text-2xl font-bold text-mti-green-light">
|
{isNewContentLoading && (<span className="text-center text-2xl font-bold text-mti-green-light">
|
||||||
Assessing your exams, please be patient...
|
Assessing your exams, please be patient...
|
||||||
</span>)}
|
</span>)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user