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
Commits
dfe27307
Commit
dfe27307
authored
4 years ago
by
Albin Henriksson
Browse files
Options
Downloads
Patches
Plain Diff
Fix move slides on front-end
parent
fbba2902
No related branches found
No related tags found
1 merge request
!132
Resolve "Fix move slides on backend"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/src/pages/presentationEditor/PresentationEditorPage.tsx
+39
-9
39 additions, 9 deletions
...t/src/pages/presentationEditor/PresentationEditorPage.tsx
with
39 additions
and
9 deletions
client/src/pages/presentationEditor/PresentationEditorPage.tsx
+
39
−
9
View file @
dfe27307
...
@@ -10,6 +10,7 @@ import { getCities } from '../../actions/cities'
...
@@ -10,6 +10,7 @@ import { getCities } from '../../actions/cities'
import
{
getEditorCompetition
,
setEditorSlideId
,
setEditorViewId
}
from
'
../../actions/editor
'
import
{
getEditorCompetition
,
setEditorSlideId
,
setEditorViewId
}
from
'
../../actions/editor
'
import
{
getTypes
}
from
'
../../actions/typesAction
'
import
{
getTypes
}
from
'
../../actions/typesAction
'
import
{
useAppDispatch
,
useAppSelector
}
from
'
../../hooks
'
import
{
useAppDispatch
,
useAppSelector
}
from
'
../../hooks
'
import
{
RichSlide
}
from
'
../../interfaces/ApiRichModels
'
import
{
renderSlideIcon
}
from
'
../../utils/renderSlideIcon
'
import
{
renderSlideIcon
}
from
'
../../utils/renderSlideIcon
'
import
{
RemoveMenuItem
}
from
'
../admin/styledComp
'
import
{
RemoveMenuItem
}
from
'
../admin/styledComp
'
import
{
Content
,
InnerContent
}
from
'
../views/styled
'
import
{
Content
,
InnerContent
}
from
'
../views/styled
'
...
@@ -50,6 +51,7 @@ interface CompetitionParams {
...
@@ -50,6 +51,7 @@ interface CompetitionParams {
const
PresentationEditorPage
:
React
.
FC
=
()
=>
{
const
PresentationEditorPage
:
React
.
FC
=
()
=>
{
const
{
competitionId
}:
CompetitionParams
=
useParams
()
const
{
competitionId
}:
CompetitionParams
=
useParams
()
const
dispatch
=
useAppDispatch
()
const
dispatch
=
useAppDispatch
()
const
[
slides
,
setSlides
]
=
useState
<
RichSlide
[]
>
([])
const
activeSlideId
=
useAppSelector
((
state
)
=>
state
.
editor
.
activeSlideId
)
const
activeSlideId
=
useAppSelector
((
state
)
=>
state
.
editor
.
activeSlideId
)
const
activeViewTypeId
=
useAppSelector
((
state
)
=>
state
.
editor
.
activeViewTypeId
)
const
activeViewTypeId
=
useAppSelector
((
state
)
=>
state
.
editor
.
activeViewTypeId
)
const
competition
=
useAppSelector
((
state
)
=>
state
.
editor
.
competition
)
const
competition
=
useAppSelector
((
state
)
=>
state
.
editor
.
competition
)
...
@@ -60,6 +62,10 @@ const PresentationEditorPage: React.FC = () => {
...
@@ -60,6 +62,10 @@ const PresentationEditorPage: React.FC = () => {
dispatch
(
getCities
())
dispatch
(
getCities
())
},
[])
},
[])
useEffect
(()
=>
{
setSlides
(
competition
.
slides
)
},
[
competition
])
const
setActiveSlideId
=
(
id
:
number
)
=>
{
const
setActiveSlideId
=
(
id
:
number
)
=>
{
dispatch
(
setEditorSlideId
(
id
))
dispatch
(
setEditorSlideId
(
id
))
}
}
...
@@ -111,16 +117,38 @@ const PresentationEditorPage: React.FC = () => {
...
@@ -111,16 +117,38 @@ const PresentationEditorPage: React.FC = () => {
}
}
const
onDragEnd
=
async
(
result
:
DropResult
)
=>
{
const
onDragEnd
=
async
(
result
:
DropResult
)
=>
{
// dropped outside the list
// dropped outside the list
or same place
if
(
!
result
.
destination
)
{
if
(
!
result
.
destination
||
result
.
destination
.
index
===
result
.
source
.
index
)
{
return
return
}
}
const
draggedIndex
=
result
.
source
.
index
const
draggedIndex
=
result
.
source
.
index
const
draggedSlideId
=
competition
.
slides
.
find
((
slide
)
=>
slide
.
order
===
draggedIndex
)?.
id
const
draggedSlideId
=
slides
.
find
((
slide
)
=>
slide
.
order
===
draggedIndex
)?.
id
const
slidesCopy
=
slides
const
diff
=
result
.
destination
.
index
-
result
.
source
.
index
slides
.
map
((
slide
)
=>
{
if
(
slide
.
order
===
draggedIndex
&&
result
.
destination
)
{
slide
.
order
=
result
.
destination
.
index
}
else
if
(
result
.
destination
&&
diff
>
0
&&
slide
.
order
>
result
.
source
.
index
&&
slide
.
order
<=
result
.
destination
.
index
)
{
slide
.
order
=
slide
.
order
-
1
}
else
if
(
result
.
destination
&&
diff
<
0
&&
slide
.
order
<
result
.
source
.
index
&&
slide
.
order
>=
result
.
destination
.
index
)
{
slide
.
order
=
slide
.
order
+
1
}
})
setSlides
(
slidesCopy
)
if
(
draggedSlideId
)
{
if
(
draggedSlideId
)
{
await
axios
await
axios
.
put
(
`/api/competitions/
${
competitionId
}
/slides/
${
draggedSlideId
}
/order`
,
{
order
:
result
.
destination
.
index
})
.
put
(
`/api/competitions/
${
competitionId
}
/slides/
${
draggedSlideId
}
/order`
,
{
order
:
result
.
destination
.
index
})
.
then
(()
=>
dispatch
(
getEditorCompetition
(
competitionId
)))
.
catch
(
console
.
log
)
.
catch
(
console
.
log
)
}
}
}
}
...
@@ -161,21 +189,23 @@ const PresentationEditorPage: React.FC = () => {
...
@@ -161,21 +189,23 @@ const PresentationEditorPage: React.FC = () => {
<
DragDropContext
onDragEnd
=
{
onDragEnd
}
>
<
DragDropContext
onDragEnd
=
{
onDragEnd
}
>
<
Droppable
droppableId
=
"droppable"
>
<
Droppable
droppableId
=
"droppable"
>
{
(
provided
)
=>
(
{
(
provided
)
=>
(
<
div
key
=
{
provided
.
innerRef
.
toString
()
}
ref
=
{
provided
.
innerRef
}
{
...
provided
.
droppableProps
}
>
<
div
ref
=
{
provided
.
innerRef
}
{
...
provided
.
droppableProps
}
>
{
competition
.
slides
&&
{
slides
competition
.
slides
.
map
((
slide
,
index
)
=>
(
.
sort
((
a
,
b
)
=>
(
a
.
order
>
b
.
order
?
1
:
-
1
))
<
Draggable
key
=
{
slide
.
order
}
draggableId
=
{
slide
.
id
.
toString
()
}
index
=
{
index
}
>
.
map
((
slide
,
index
)
=>
(
<
Draggable
key
=
{
slide
.
id
}
draggableId
=
{
slide
.
id
.
toString
()
}
index
=
{
index
}
>
{
(
provided
,
snapshot
)
=>
(
{
(
provided
,
snapshot
)
=>
(
<
div
ref
=
{
provided
.
innerRef
}
{
...
provided
.
draggableProps
}
{
...
provided
.
dragHandleProps
}
>
<
div
ref
=
{
provided
.
innerRef
}
{
...
provided
.
draggableProps
}
{
...
provided
.
dragHandleProps
}
>
<
SlideListItem
<
SlideListItem
divider
divider
key
=
{
slide
.
order
}
button
button
selected
=
{
slide
.
id
===
activeSlideId
}
selected
=
{
slide
.
id
===
activeSlideId
}
onClick
=
{
()
=>
setActiveSlideId
(
slide
.
id
)
}
onClick
=
{
()
=>
setActiveSlideId
(
slide
.
id
)
}
onContextMenu
=
{
(
event
)
=>
handleRightClick
(
event
,
slide
.
id
)
}
onContextMenu
=
{
(
event
)
=>
handleRightClick
(
event
,
slide
.
id
)
}
>
>
{
renderSlideIcon
(
slide
)
}
{
renderSlideIcon
(
slide
)
}
<
ListItemText
primary
=
{
`Sida
${
slide
.
order
+
1
}
`
}
/>
<
ListItemText
primary
=
{
`Sida
${
slide
.
id
}
`
}
/>
</
SlideListItem
>
</
SlideListItem
>
</
div
>
</
div
>
)
}
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment