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

Disable timer for info slides and fix info slide bug

parent 164f6615
No related branches found
No related tags found
1 merge request!152Resolve "Disable timer when info slide"
...@@ -59,11 +59,11 @@ const SlideDisplay = ({ variant, activeViewTypeId, currentSlideId }: SlideDispla ...@@ -59,11 +59,11 @@ const SlideDisplay = ({ variant, activeViewTypeId, currentSlideId }: SlideDispla
<SlideEditorContainer> <SlideEditorContainer>
<SlideEditorContainerRatio> <SlideEditorContainerRatio>
<SlideEditorPaper ref={editorPaperRef}> <SlideEditorPaper ref={editorPaperRef}>
<SlideDisplayText scale={scale}> <SlideDisplayText $scale={scale}>
{variant === 'editor' && slide?.timer ? `Tid kvar: ${slide?.timer}` : ''} {variant === 'editor' && slide?.timer ? `Tid kvar: ${slide?.timer}` : ''}
{variant === 'presentation' && <Timer />} {variant === 'presentation' && <Timer />}
</SlideDisplayText> </SlideDisplayText>
<SlideDisplayText scale={scale} right> <SlideDisplayText $scale={scale} $right>
{slide && `Sida: ${slide?.order + 1} / ${totalSlides}`} {slide && `Sida: ${slide?.order + 1} / ${totalSlides}`}
</SlideDisplayText> </SlideDisplayText>
{(competitionBackgroundImage || slideBackgroundImage) && ( {(competitionBackgroundImage || slideBackgroundImage) && (
......
...@@ -33,7 +33,9 @@ const SlideSettings: React.FC = () => { ...@@ -33,7 +33,9 @@ const SlideSettings: React.FC = () => {
<SettingsList> <SettingsList>
{activeSlide && <SlideType activeSlide={activeSlide} competitionId={competitionId} />} {activeSlide && <SlideType activeSlide={activeSlide} competitionId={competitionId} />}
<Divider /> <Divider />
{activeSlide && <Timer activeSlide={activeSlide} competitionId={competitionId} />} {activeSlide && Boolean(activeSlide.questions[0]) && (
<Timer activeSlide={activeSlide} competitionId={competitionId} />
)}
</SettingsList> </SettingsList>
{activeSlide?.questions[0] && <QuestionSettings activeSlide={activeSlide} competitionId={competitionId} />} {activeSlide?.questions[0] && <QuestionSettings activeSlide={activeSlide} competitionId={competitionId} />}
......
...@@ -53,7 +53,6 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => { ...@@ -53,7 +53,6 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => {
closeSlideTypeDialog() closeSlideTypeDialog()
if (activeSlide) { if (activeSlide) {
if (activeSlide.questions?.[0] && activeSlide.questions[0].type_id !== selectedSlideType) { if (activeSlide.questions?.[0] && activeSlide.questions[0].type_id !== selectedSlideType) {
deleteQuestionComponent(questionComponentId)
if (selectedSlideType === 0) { if (selectedSlideType === 0) {
// Change slide type from a question type to information // Change slide type from a question type to information
await axios await axios
...@@ -78,13 +77,13 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => { ...@@ -78,13 +77,13 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => {
total_score: 0, total_score: 0,
type_id: selectedSlideType, type_id: selectedSlideType,
}) })
.then(() => { .then(({ data }) => {
dispatch(getEditorCompetition(competitionId)) dispatch(getEditorCompetition(competitionId))
removeQuestionComponent().then(() => createQuestionComponent()) removeQuestionComponent().then(() => createQuestionComponent(data.id))
}) })
.catch(console.log) .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 // Change slide type from information to a question type
await axios await axios
.post(`/api/competitions/${competitionId}/slides/${activeSlide.id}/questions`, { .post(`/api/competitions/${competitionId}/slides/${activeSlide.id}/questions`, {
...@@ -92,16 +91,16 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => { ...@@ -92,16 +91,16 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => {
total_score: 0, total_score: 0,
type_id: selectedSlideType, type_id: selectedSlideType,
}) })
.then(() => { .then(({ data }) => {
dispatch(getEditorCompetition(competitionId)) dispatch(getEditorCompetition(competitionId))
createQuestionComponent() createQuestionComponent(data.id)
}) })
.catch(console.log) .catch(console.log)
} }
} }
} }
const createQuestionComponent = async () => { const createQuestionComponent = async (question_id: number) => {
await axios await axios
.post(`/api/competitions/${competitionId}/slides/${activeSlide.id}/components`, { .post(`/api/competitions/${competitionId}/slides/${activeSlide.id}/components`, {
x: 0, x: 0,
...@@ -110,7 +109,7 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => { ...@@ -110,7 +109,7 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => {
h: 250, h: 250,
type_id: 3, type_id: 3,
view_type_id: 1, view_type_id: 1,
question_id: activeSlide.questions[0].id, question_id,
}) })
.then(() => { .then(() => {
dispatch(getEditorCompetition(competitionId)) dispatch(getEditorCompetition(competitionId))
...@@ -127,14 +126,6 @@ const SlideType = ({ activeSlide, competitionId }: SlideTypeProps) => { ...@@ -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 ( return (
<FirstItem> <FirstItem>
<ListItem> <ListItem>
......
...@@ -147,14 +147,14 @@ export const SettingsItemContainer = styled.div` ...@@ -147,14 +147,14 @@ export const SettingsItemContainer = styled.div`
` `
interface SlideDisplayTextProps { interface SlideDisplayTextProps {
scale: number $scale: number
right?: boolean $right?: boolean
} }
export const SlideDisplayText = styled(Typography)<SlideDisplayTextProps>` export const SlideDisplayText = styled(Typography)<SlideDisplayTextProps>`
position: absolute; position: absolute;
top: 5px; top: 5px;
left: ${(props) => (props.right ? undefined : 5)}px; left: ${(props) => (props.$right ? undefined : 5)}px;
right: ${(props) => (props.right ? 5 : undefined)}px; right: ${(props) => (props.$right ? 5 : undefined)}px;
font-size: ${(props) => 24 * props.scale}px; font-size: ${(props) => 24 * props.$scale}px;
` `
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment