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

Fix timer lockout and remove default slide question

parent 2f84965c
No related branches found
No related tags found
No related merge requests found
Pipeline #46193 passed with warnings
Showing with 23 additions and 36 deletions
...@@ -64,7 +64,7 @@ const SlideDisplay = ({ variant, activeViewTypeId, currentSlideId }: SlideDispla ...@@ -64,7 +64,7 @@ const SlideDisplay = ({ variant, activeViewTypeId, currentSlideId }: SlideDispla
{slide?.timer && ( {slide?.timer && (
<Card style={{ display: 'flex', alignItems: 'center', padding: 10 }}> <Card style={{ display: 'flex', alignItems: 'center', padding: 10 }}>
<TimerIcon fontSize="large" /> <TimerIcon fontSize="large" />
<Timer variant={variant} /> <Timer variant={variant} currentSlideId={currentSlideId} />
</Card> </Card>
)} )}
</SlideDisplayText> </SlideDisplayText>
......
...@@ -70,7 +70,7 @@ const AnswerMatch = ({ variant, activeSlide, competitionId }: AnswerMultipleProp ...@@ -70,7 +70,7 @@ const AnswerMatch = ({ variant, activeSlide, competitionId }: AnswerMultipleProp
}, [teamId]) }, [teamId])
const getButtonStyle = () => { const getButtonStyle = () => {
if (!(timer.value === null || (timer.enabled && timer.value))) { if (activeSlide?.timer !== undefined && !timer.enabled) {
return { fill: '#AAAAAA' } // Buttons are light grey if timer is not on return { fill: '#AAAAAA' } // Buttons are light grey if timer is not on
} }
return {} return {}
...@@ -79,7 +79,7 @@ const AnswerMatch = ({ variant, activeSlide, competitionId }: AnswerMultipleProp ...@@ -79,7 +79,7 @@ const AnswerMatch = ({ variant, activeSlide, competitionId }: AnswerMultipleProp
const onMove = async (previousIndex: number, resultIndex: number) => { const onMove = async (previousIndex: number, resultIndex: number) => {
// moved outside the list // moved outside the list
if (resultIndex < 0 || resultIndex >= sortedAnswers.length || variant !== 'presentation') return if (resultIndex < 0 || resultIndex >= sortedAnswers.length || variant !== 'presentation') return
if (!(timer.value === null || (timer.enabled && timer.value))) return if (activeSlide?.timer !== undefined && !timer.enabled) return
const answersCopy = [...sortedAnswers] const answersCopy = [...sortedAnswers]
const [removed] = answersCopy.splice(previousIndex, 1) const [removed] = answersCopy.splice(previousIndex, 1)
answersCopy.splice(resultIndex, 0, removed) answersCopy.splice(resultIndex, 0, removed)
......
...@@ -48,7 +48,7 @@ const AnswerMultiple = ({ variant, activeSlide, competitionId }: AnswerMultipleP ...@@ -48,7 +48,7 @@ const AnswerMultiple = ({ variant, activeSlide, competitionId }: AnswerMultipleP
const updateAnswer = async (alternative: QuestionAlternative, checked: boolean) => { const updateAnswer = async (alternative: QuestionAlternative, checked: boolean) => {
// TODO: fix. Make list of alternatives and delete & post instead of put to allow multiple boxes checked. // TODO: fix. Make list of alternatives and delete & post instead of put to allow multiple boxes checked.
if (!(activeSlide && (timer.value === null || (timer.enabled && timer.value)))) { if (!activeSlide || (activeSlide?.timer !== undefined && !timer.enabled)) {
return return
} }
const url = `/api/competitions/${competitionId}/teams/${teamId}/answers/question_alternatives/${alternative.id}` const url = `/api/competitions/${competitionId}/teams/${teamId}/answers/question_alternatives/${alternative.id}`
...@@ -91,7 +91,7 @@ const AnswerMultiple = ({ variant, activeSlide, competitionId }: AnswerMultipleP ...@@ -91,7 +91,7 @@ const AnswerMultiple = ({ variant, activeSlide, competitionId }: AnswerMultipleP
<div key={alt.id}> <div key={alt.id}>
<ListItem divider> <ListItem divider>
<GreenCheckbox <GreenCheckbox
disabled={!(timer.value === null || (timer.enabled && timer.value))} disabled={activeSlide?.timer !== undefined && !timer.enabled}
checked={decideChecked(alt)} checked={decideChecked(alt)}
onChange={(event: any) => updateAnswer(alt, event.target.checked)} onChange={(event: any) => updateAnswer(alt, event.target.checked)}
/> />
......
...@@ -50,7 +50,7 @@ const AnswerSingle = ({ variant, activeSlide, competitionId }: AnswerSingleProps ...@@ -50,7 +50,7 @@ const AnswerSingle = ({ variant, activeSlide, competitionId }: AnswerSingleProps
} }
const updateAnswer = async (alternative: QuestionAlternative) => { const updateAnswer = async (alternative: QuestionAlternative) => {
if (!(activeSlide && (timer.value === null || (timer.enabled && timer.value)))) { if (!activeSlide || (activeSlide?.timer !== undefined && !timer.enabled)) {
return return
} }
...@@ -79,7 +79,7 @@ const AnswerSingle = ({ variant, activeSlide, competitionId }: AnswerSingleProps ...@@ -79,7 +79,7 @@ const AnswerSingle = ({ variant, activeSlide, competitionId }: AnswerSingleProps
*/ */
const renderRadioButton = (alt: QuestionAlternative) => { const renderRadioButton = (alt: QuestionAlternative) => {
let disabledStyle let disabledStyle
if (!(timer.value === null || (timer.enabled && timer.value))) { if (activeSlide?.timer !== undefined && !timer.enabled) {
disabledStyle = { fill: '#AAAAAA' } // Buttons are light grey if timer is not on disabledStyle = { fill: '#AAAAAA' } // Buttons are light grey if timer is not on
} }
if (variant === 'presentation') { if (variant === 'presentation') {
......
...@@ -39,7 +39,7 @@ const AnswerText = ({ activeSlide, competitionId }: AnswerTextProps) => { ...@@ -39,7 +39,7 @@ const AnswerText = ({ activeSlide, competitionId }: AnswerTextProps) => {
setTimerHandle(undefined) setTimerHandle(undefined)
} }
//Only updates answer if the timer is on //Only updates answer if the timer is on
if (timer.value === null || (timer.enabled && timer.value)) { if (activeSlide?.timer !== undefined && !timer.enabled) {
//Only updates answer 100ms after last input was made //Only updates answer 100ms after last input was made
setTimerHandle(window.setTimeout(() => updateAnswer(answer), 100)) setTimerHandle(window.setTimeout(() => updateAnswer(answer), 100))
} }
...@@ -79,7 +79,7 @@ const AnswerText = ({ activeSlide, competitionId }: AnswerTextProps) => { ...@@ -79,7 +79,7 @@ const AnswerText = ({ activeSlide, competitionId }: AnswerTextProps) => {
</ListItem> </ListItem>
<ListItem style={{ height: '100%' }}> <ListItem style={{ height: '100%' }}>
<TextField <TextField
disabled={team === undefined || !(timer.value === null || (timer.enabled && timer.value))} disabled={team === undefined || (activeSlide?.timer !== undefined && !timer.enabled)}
defaultValue={getDefaultString()} defaultValue={getDefaultString()}
style={{ height: '100%' }} style={{ height: '100%' }}
variant="outlined" variant="outlined"
......
...@@ -4,9 +4,10 @@ import { useAppDispatch, useAppSelector } from '../../../hooks' ...@@ -4,9 +4,10 @@ import { useAppDispatch, useAppSelector } from '../../../hooks'
type TimerProps = { type TimerProps = {
variant: 'editor' | 'presentation' variant: 'editor' | 'presentation'
currentSlideId?: number
} }
const Timer = ({ variant }: TimerProps) => { const Timer = ({ variant, currentSlideId }: TimerProps) => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const timer = useAppSelector((state) => state.presentation.timer) const timer = useAppSelector((state) => state.presentation.timer)
const [remainingTimer, setRemainingTimer] = useState<number>(0) const [remainingTimer, setRemainingTimer] = useState<number>(0)
...@@ -22,6 +23,8 @@ const Timer = ({ variant }: TimerProps) => { ...@@ -22,6 +23,8 @@ const Timer = ({ variant }: TimerProps) => {
const displayTime = `${remainingDisplayMinutes}:${remainingDisplaySeconds}` const displayTime = `${remainingDisplayMinutes}:${remainingDisplaySeconds}`
const [timerIntervalId, setTimerIntervalId] = useState<NodeJS.Timeout | null>(null) const [timerIntervalId, setTimerIntervalId] = useState<NodeJS.Timeout | null>(null)
const slideTimer = useAppSelector((state) => { const slideTimer = useAppSelector((state) => {
if (currentSlideId && variant === 'presentation')
return state.presentation.competition.slides.find((slide) => slide.id === currentSlideId)?.timer
if (variant === 'presentation') if (variant === 'presentation')
return state.presentation.competition.slides.find((slide) => slide.id === state.presentation.activeSlideId)?.timer return state.presentation.competition.slides.find((slide) => slide.id === state.presentation.activeSlideId)?.timer
return state.editor.competition.slides.find((slide) => slide.id === state.editor.activeSlideId)?.timer return state.editor.competition.slides.find((slide) => slide.id === state.editor.activeSlideId)?.timer
......
...@@ -38,7 +38,7 @@ class SlidesList(Resource): ...@@ -38,7 +38,7 @@ class SlidesList(Resource):
def post(self, competition_id): def post(self, competition_id):
""" Posts a new slide to the specified competition. """ """ Posts a new slide to the specified competition. """
item_slide = dbc.add.slide_without_question(competition_id) item_slide = dbc.add.slide(competition_id)
return item_response(schema.dump(item_slide)) return item_response(schema.dump(item_slide))
......
...@@ -125,20 +125,7 @@ def slide(competition_id): ...@@ -125,20 +125,7 @@ def slide(competition_id):
# Add slide # Add slide
item_slide = db_add(Slide(order, competition_id)) item_slide = db_add(Slide(order, competition_id))
return item_slide return dbc.utils.refresh(item_slide)
def slide_without_question(competition_id):
""" Adds a slide to the provided competition. """
# Get the last order from given competition
order = dbc.utils.count(Slide, {"competition_id": competition_id})
# Add slide
item_slide = db_add(Slide(order, competition_id))
item_slide = dbc.utils.refresh(item_slide)
return item_slide
def competition(name, year, city_id): def competition(name, year, city_id):
......
...@@ -4,7 +4,8 @@ This file contains functionality to copy and duplicate data to the database. ...@@ -4,7 +4,8 @@ This file contains functionality to copy and duplicate data to the database.
from app.database.controller import add, get, search, utils from app.database.controller import add, get, search, utils
from app.database.models import Question from app.database.models import Question
from app.database.types import IMAGE_COMPONENT_ID, QUESTION_COMPONENT_ID, TEXT_COMPONENT_ID from app.database.types import (IMAGE_COMPONENT_ID, QUESTION_COMPONENT_ID,
TEXT_COMPONENT_ID)
def _alternative(item_old, question_id): def _alternative(item_old, question_id):
...@@ -90,7 +91,7 @@ def slide_to_competition(item_slide_old, item_competition): ...@@ -90,7 +91,7 @@ def slide_to_competition(item_slide_old, item_competition):
Does not copy team, question answers. Does not copy team, question answers.
""" """
item_slide_new = add.slide_without_question(item_competition.id) item_slide_new = add.slide(item_competition.id)
# Copy all fields # Copy all fields
item_slide_new.title = item_slide_old.title item_slide_new.title = item_slide_old.title
......
...@@ -9,7 +9,8 @@ import pytest ...@@ -9,7 +9,8 @@ import pytest
from app.core import sockets from app.core import sockets
from tests import app, client, db from tests import app, client, db
from tests.test_helpers import add_default_values, change_order_test, delete, get, post, put from tests.test_helpers import (add_default_values, change_order_test, delete,
get, post, put)
# @pytest.mark.skip(reason="Takes long time") # @pytest.mark.skip(reason="Takes long time")
...@@ -398,14 +399,13 @@ def test_question_api(client): ...@@ -398,14 +399,13 @@ def test_question_api(client):
slide_order = 1 slide_order = 1
response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers) response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers)
assert response.status_code == codes.OK assert response.status_code == codes.OK
assert body["count"] == 2 assert body["count"] == 0
# Get questions from another competition that should have some questions # Get questions from another competition that should have some questions
CID = 3 CID = 3
num_questions = 3
response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers) response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers)
assert response.status_code == codes.OK assert response.status_code == codes.OK
assert body["count"] == num_questions assert body["count"] == 0
# Add question # Add question
name = "Nytt namn" name = "Nytt namn"
...@@ -417,7 +417,6 @@ def test_question_api(client): ...@@ -417,7 +417,6 @@ def test_question_api(client):
{"name": name, "type_id": type_id}, {"name": name, "type_id": type_id},
headers=headers, headers=headers,
) )
num_questions = 4
assert response.status_code == codes.OK assert response.status_code == codes.OK
assert item_question["name"] == name assert item_question["name"] == name
assert item_question["type_id"] == type_id assert item_question["type_id"] == type_id
...@@ -425,7 +424,7 @@ def test_question_api(client): ...@@ -425,7 +424,7 @@ def test_question_api(client):
# Checks number of questions # Checks number of questions
response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers) response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers)
assert response.status_code == codes.OK assert response.status_code == codes.OK
assert body["count"] == num_questions assert body["count"] == 1
""" """
# Delete question # Delete question
response, _ = delete(client, f"/api/competitions/{CID}/slides/{slide_order}/questions/{QID}", headers=headers) response, _ = delete(client, f"/api/competitions/{CID}/slides/{slide_order}/questions/{QID}", headers=headers)
......
...@@ -41,10 +41,7 @@ def add_default_values(): ...@@ -41,10 +41,7 @@ def add_default_values():
# Add competitions # Add competitions
item_competition = dbc.add.competition("Tom tävling", 2012, item_city.id) item_competition = dbc.add.competition("Tom tävling", 2012, item_city.id)
item_question = dbc.add.question("hej", 5, 1, item_competition.slides[0].id)
item_team1 = dbc.add.team("Hej lag 3", item_competition.id) item_team1 = dbc.add.team("Hej lag 3", item_competition.id)
item_team2 = dbc.add.team("Hej lag 4", item_competition.id)
db.session.add(Code("111111", 1, item_competition.id, item_team1.id)) # Team db.session.add(Code("111111", 1, item_competition.id, item_team1.id)) # Team
db.session.add(Code("222222", 2, item_competition.id)) # Judge db.session.add(Code("222222", 2, item_competition.id)) # Judge
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment