Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
teknikattan-scoring-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tddd96-grupp1
teknikattan-scoring-system
Merge requests
!92
Resolve "Refactor/minimize editor code"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Refactor/minimize editor code"
118-refactor-minimize-editor-code
into
dev
Overview
0
Commits
26
Pipelines
4
Changes
10
Merged
Emil Wahlqvist
requested to merge
118-refactor-minimize-editor-code
into
dev
3 years ago
Overview
0
Commits
26
Pipelines
4
Changes
10
Expand
Closes
#118 (closed)
0
0
Merge request reports
Compare
dev
version 3
79a76f30
3 years ago
version 2
5effacbb
3 years ago
version 1
b3d60d9e
3 years ago
dev (base)
and
latest version
latest version
06a128a3
26 commits,
3 years ago
version 3
79a76f30
25 commits,
3 years ago
version 2
5effacbb
24 commits,
3 years ago
version 1
b3d60d9e
23 commits,
3 years ago
10 files
+
665
−
474
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
10
Search (e.g. *.vue) (Ctrl+P)
client/src/pages/presentationEditor/components/Alternatives.tsx
0 → 100644
+
136
−
0
Options
import
{
Checkbox
,
ListItem
,
ListItemText
,
withStyles
}
from
'
@material-ui/core
'
import
{
CheckboxProps
}
from
'
@material-ui/core/Checkbox
'
import
{
green
,
grey
}
from
'
@material-ui/core/colors
'
import
CloseIcon
from
'
@material-ui/icons/Close
'
import
axios
from
'
axios
'
import
React
from
'
react
'
import
{
getEditorCompetition
}
from
'
../../../actions/editor
'
import
{
useAppDispatch
,
useAppSelector
}
from
'
../../../hooks
'
import
{
QuestionAlternative
}
from
'
../../../interfaces/ApiModels
'
import
{
RichSlide
}
from
'
../../../interfaces/ApiRichModels
'
import
{
AddButton
,
Center
,
Clickable
,
SettingsList
,
TextInput
,
WhiteBackground
}
from
'
./styled
'
type
AlternativeProps
=
{
activeSlide
:
RichSlide
competitionId
:
string
}
const
Alternatives
=
({
activeSlide
,
competitionId
}:
AlternativeProps
)
=>
{
const
dispatch
=
useAppDispatch
()
const
competition
=
useAppSelector
((
state
)
=>
state
.
editor
.
competition
)
const
activeSlideId
=
useAppSelector
((
state
)
=>
state
.
editor
.
activeSlideId
)
const
GreenCheckbox
=
withStyles
({
root
:
{
color
:
grey
[
900
],
'
&$checked
'
:
{
color
:
green
[
600
],
},
},
checked
:
{},
})((
props
:
CheckboxProps
)
=>
<
Checkbox
color
=
"default"
{
...
props
}
/>)
const
numberToBool
=
(
num
:
number
)
=>
{
if
(
num
===
0
)
return
false
else
return
true
}
const
updateAlternativeValue
=
async
(
alternative
:
QuestionAlternative
)
=>
{
if
(
activeSlide
&&
activeSlide
.
questions
[
0
])
{
let
newValue
:
number
if
(
alternative
.
value
===
0
)
{
newValue
=
1
}
else
newValue
=
0
await
axios
.
put
(
`/api/competitions/
${
competitionId
}
/slides/
${
activeSlide
?.
id
}
/questions/
${
activeSlide
?.
questions
[
0
].
id
}
/alternatives/
${
alternative
.
id
}
`
,
{
value
:
newValue
}
)
.
then
(()
=>
{
dispatch
(
getEditorCompetition
(
competitionId
))
})
.
catch
(
console
.
log
)
}
}
const
updateAlternativeText
=
async
(
alternative_id
:
number
,
newText
:
string
)
=>
{
if
(
activeSlide
&&
activeSlide
.
questions
[
0
])
{
await
axios
.
put
(
`/api/competitions/
${
competitionId
}
/slides/
${
activeSlide
?.
id
}
/questions/
${
activeSlide
?.
questions
[
0
].
id
}
/alternatives/
${
alternative_id
}
`
,
{
text
:
newText
}
)
.
then
(()
=>
{
dispatch
(
getEditorCompetition
(
competitionId
))
})
.
catch
(
console
.
log
)
}
}
const
addAlternative
=
async
()
=>
{
if
(
activeSlide
&&
activeSlide
.
questions
[
0
])
{
await
axios
.
post
(
`/api/competitions/
${
competitionId
}
/slides/
${
activeSlide
?.
id
}
/questions/
${
activeSlide
?.
questions
[
0
].
id
}
/alternatives`
,
{
text
:
''
,
value
:
0
}
)
.
then
(()
=>
{
dispatch
(
getEditorCompetition
(
competitionId
))
})
.
catch
(
console
.
log
)
}
}
const
handleCloseAnswerClick
=
async
(
alternative_id
:
number
)
=>
{
if
(
activeSlide
&&
activeSlide
.
questions
[
0
])
{
await
axios
.
delete
(
`/api/competitions/
${
competitionId
}
/slides/
${
activeSlideId
}
/questions/
${
activeSlide
?.
questions
[
0
].
id
}
/alternatives/
${
alternative_id
}
`
)
.
then
(()
=>
{
dispatch
(
getEditorCompetition
(
competitionId
))
})
.
catch
(
console
.
log
)
}
}
return
(
<
SettingsList
>
<
WhiteBackground
>
<
ListItem
divider
>
<
Center
>
<
ListItemText
primary
=
"Svarsalternativ"
secondary
=
"(Fyll i rutan höger om textfältet för att markera korrekt svar)"
/>
</
Center
>
</
ListItem
>
{
activeSlide
&&
activeSlide
.
questions
[
0
]
&&
activeSlide
.
questions
[
0
].
alternatives
&&
activeSlide
.
questions
[
0
].
alternatives
.
map
((
alt
)
=>
(
<
div
key
=
{
alt
.
id
}
>
<
ListItem
divider
>
<
TextInput
id
=
"outlined-basic"
defaultValue
=
{
alt
.
text
}
onChange
=
{
(
event
)
=>
updateAlternativeText
(
alt
.
id
,
event
.
target
.
value
)
}
variant
=
"outlined"
/>
<
GreenCheckbox
checked
=
{
numberToBool
(
alt
.
value
)
}
onChange
=
{
()
=>
updateAlternativeValue
(
alt
)
}
/>
<
Clickable
>
<
CloseIcon
onClick
=
{
()
=>
handleCloseAnswerClick
(
alt
.
id
)
}
/>
</
Clickable
>
</
ListItem
>
</
div
>
))
}
<
ListItem
button
onClick
=
{
addAlternative
}
>
<
Center
>
<
AddButton
variant
=
"button"
>
Lägg till svarsalternativ
</
AddButton
>
</
Center
>
</
ListItem
>
</
WhiteBackground
>
</
SettingsList
>
)
}
export
default
Alternatives
Loading