Skip to content
Snippets Groups Projects
Commit 554db4fe authored by Albin Henriksson's avatar Albin Henriksson
Browse files

Resolve "Disable timer when info slide"

parent 7ec5112f
No related branches found
No related tags found
1 merge request!152Resolve "Disable timer when info slide"
Pipeline #45708 passed with warnings
......@@ -33,7 +33,9 @@ const SlideSettings: React.FC = () => {
<SettingsList>
{activeSlide && <SlideType activeSlide={activeSlide} competitionId={competitionId} />}
<Divider />
{activeSlide && <Timer activeSlide={activeSlide} competitionId={competitionId} />}
{activeSlide && Boolean(activeSlide.questions[0]) && (
<Timer activeSlide={activeSlide} competitionId={competitionId} />
)}
</SettingsList>
{activeSlide?.questions[0] && <QuestionSettings activeSlide={activeSlide} competitionId={competitionId} />}
......
......@@ -53,7 +53,6 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => {
closeSlideTypeDialog()
if (activeSlide) {
if (activeSlide.questions?.[0] && activeSlide.questions[0].type_id !== selectedSlideType) {
deleteQuestionComponent(questionComponentId)
if (selectedSlideType === 0) {
// Change slide type from a question type to information
await axios
......@@ -78,13 +77,13 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => {
total_score: 0,
type_id: selectedSlideType,
})
.then(() => {
.then(({ data }) => {
dispatch(getEditorCompetition(competitionId))
removeQuestionComponent().then(() => createQuestionComponent())
removeQuestionComponent().then(() => createQuestionComponent(data.id))
})
.catch(console.log)
}
} else if (activeSlide.questions[0].type_id === 0 && selectedSlideType !== 0) {
} else if (!activeSlide.questions[0] && selectedSlideType !== 0) {
// Change slide type from information to a question type
await axios
.post(`/api/competitions/${competitionId}/slides/${activeSlide.id}/questions`, {
......@@ -92,16 +91,16 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => {
total_score: 0,
type_id: selectedSlideType,
})
.then(() => {
.then(({ data }) => {
dispatch(getEditorCompetition(competitionId))
createQuestionComponent()
createQuestionComponent(data.id)
})
.catch(console.log)
}
}
}
const createQuestionComponent = async () => {
const createQuestionComponent = async (question_id: number) => {
await axios
.post(`/api/competitions/${competitionId}/slides/${activeSlide.id}/components`, {
x: 0,
......@@ -110,7 +109,7 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => {
h: 250,
type_id: 3,
view_type_id: 1,
question_id: activeSlide.questions[0].id,
question_id,
})
.then(() => {
dispatch(getEditorCompetition(competitionId))
......@@ -127,14 +126,6 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => {
}
}
const deleteQuestionComponent = (componentId: number | undefined) => {
if (componentId) {
axios
.delete(`/api/competitions/${competitionId}/slides/${activeSlide.id}/components/${componentId}`)
.catch(console.log)
}
}
return (
<FirstItem>
<ListItem>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment