Skip to content

Commit

Permalink
feat(frontend): image creation and quiz creation connected to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
alitariksahin committed Dec 15, 2024
1 parent 1a7ba62 commit 15d928e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 20 deletions.
1 change: 1 addition & 0 deletions frontend/src/components/common/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const convertQuizResponseToQuiz = (quizResponse: QuizResponse): Quiz => {
tags: quizResponse.tags,
timestamp: formatTimeAgo(quizResponse.created_at),
created_at: quizResponse.created_at,
picture: quizResponse.title_image,
level: quizResponse.level,
times_taken: quizResponse.times_taken,
},
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/quiz/create-quiz-metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function CreateQuizMetadata({
description,
level,
tags: tagNames,
title_image: file,
});
}, [title, description, level, tags]);

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/quiz/quiz-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default function QuizCard({
</div>
<Divider className="mt-1.5 bg-zinc-200" />
</CardHeader>
<div className="flex flex-row justify-between items-center mb-5">
<div className="flex flex-row justify-between items-center mb-4 ml-4 mr-4">
{picture ? (
<img
src={picture}
Expand All @@ -157,6 +157,7 @@ export default function QuizCard({
height: "200px",
objectFit: "cover",
objectPosition: "center",
borderRadius: "10px",
}}
onClick={() => navigate(`/quiz/${id}/details`)}
/>
Expand Down
30 changes: 24 additions & 6 deletions frontend/src/pages/quiz-creation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,41 @@ export default function QuizCreation() {
const handleSubmit = () => {
setIsLoading(true);
const token = getToken("access");
const formData: QuizCreationModel = {
quiz: quizHeader,
questions: quizQuestions,
};
const formData = new FormData();

// Add quiz details
formData.append("title", quizHeader.title);
formData.append("description", quizHeader.description);
formData.append("level", quizHeader.level);
formData.append("tags", JSON.stringify(quizHeader.tags));

// Add title image if exists
if (quizHeader.title_image) {
formData.append("title_image", quizHeader.title_image);
}

formData.append(
`questions`,
JSON.stringify(
quizQuestions,
)
);
console.log("Form data:", formData);

axios
.post(`${BASE_URL}/quiz/create/`, formData, {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
"Content-Type": "multipart/form-data",
},
})
.then((response) => {
console.log(response);
navigate("/quizzes");
})
.catch((error) => {
console.log(error);
console.error(error);
setIsLoading(false);
});
};

Expand Down
Loading

0 comments on commit 15d928e

Please sign in to comment.