Skip to content

Commit 5f18802

Browse files
feat: loading for creating assign
1 parent 84c2a4e commit 5f18802

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

peachide/src/app/classes/Assignment.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ export default function Assignment({ courseId }: AssignmentProps) {
8585
}
8686
}, [courseId]);
8787

88+
const [envLoading, setEnvLoading] = useState(false);
89+
8890
const handleStartAssignment = async (assignmentId: string) => {
91+
setError(null);
92+
setEnvLoading(true);
8993
var result: any;
9094
try {
9195
const formData = new FormData();
@@ -104,11 +108,13 @@ export default function Assignment({ courseId }: AssignmentProps) {
104108
result = await response.json();
105109
if (result.message == "Require group" && !(courseId in myGroups)) {
106110
setError('You need to join a group to start this assignment.');
111+
setEnvLoading(false);
107112
return;
108113
}
109114
} catch (error) {
110115
console.error('Error starting assignment environment:', error);
111116
setError('Failed to start assignment environment. Please try again later.');
117+
setEnvLoading(false);
112118
return;
113119
}
114120
const environmentId = result.environment_id;
@@ -121,8 +127,38 @@ export default function Assignment({ courseId }: AssignmentProps) {
121127
icon: "CodeXml"
122128
}
123129
]);
130+
setEnvLoading(false);
124131
};
125132

133+
// Loading popout overlay
134+
if (envLoading) {
135+
return (
136+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40">
137+
<Card className="p-8 flex flex-col items-center gap-4 shadow-2xl">
138+
<div className="animate-spin mb-2">
139+
<svg className="h-10 w-10 text-primary" viewBox="0 0 24 24" fill="none">
140+
<circle
141+
className="opacity-25"
142+
cx="12"
143+
cy="12"
144+
r="10"
145+
stroke="currentColor"
146+
strokeWidth="4"
147+
/>
148+
<path
149+
className="opacity-75"
150+
fill="currentColor"
151+
d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"
152+
/>
153+
</svg>
154+
</div>
155+
<h3 className="text-lg font-semibold">Preparing your coding environment...</h3>
156+
<p className="text-muted-foreground text-center text-sm">This may take a few moments. Please wait.</p>
157+
</Card>
158+
</div>
159+
);
160+
}
161+
126162
// Sort assignments: active ones by deadline (earliest first), then completed ones
127163
const sortedAssignments = data?.assignments
128164
? [...data.assignments].sort((a, b) => {

0 commit comments

Comments
 (0)