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

Fix client

parent 8426bb18
No related branches found
No related tags found
2 merge requests!92Resolve "Refactor/minimize editor code",!88Resolve "Restructure api routes"
Pipeline #41844 passed with warnings
This commit is part of merge request !88. Comments created here will be created in the context of that merge request.
......@@ -36,7 +36,7 @@ import {
const initialState = {
mouseX: null,
mouseY: null,
slideOrder: null,
slideId: null,
}
const leftDrawerWidth = 150
......@@ -111,15 +111,15 @@ const PresentationEditorPage: React.FC = () => {
const [contextState, setContextState] = React.useState<{
mouseX: null | number
mouseY: null | number
slideOrder: null | number
slideId: null | number
}>(initialState)
const handleRightClick = (event: React.MouseEvent<HTMLDivElement>, slideOrder: number) => {
const handleRightClick = (event: React.MouseEvent<HTMLDivElement>, slideId: number) => {
event.preventDefault()
setContextState({
mouseX: event.clientX - 2,
mouseY: event.clientY - 4,
slideOrder: slideOrder,
slideId: slideId,
})
}
......@@ -128,13 +128,13 @@ const PresentationEditorPage: React.FC = () => {
}
const handleRemoveSlide = async () => {
await axios.delete(`/competitions/${id}/slides/${contextState.slideOrder}`)
await axios.delete(`/competitions/${id}/slides/${contextState.slideId}`)
dispatch(getEditorCompetition(id))
setContextState(initialState)
}
const handleDuplicateSlide = async () => {
await axios.post(`/competitions/${id}/slides/${contextState.slideOrder}/copy`)
await axios.post(`/competitions/${id}/slides/${contextState.slideId}/copy`)
dispatch(getEditorCompetition(id))
setContextState(initialState)
}
......@@ -214,7 +214,7 @@ const PresentationEditorPage: React.FC = () => {
key={slide.id}
selected={slide.id === activeSlideId}
onClick={() => setActiveSlideId(slide.id)}
onContextMenu={(event) => handleRightClick(event, slide.order)}
onContextMenu={(event) => handleRightClick(event, slide.id)}
>
{renderSlideIcon(slide)}
<ListItemText primary={`Sida ${slide.order + 1}`} />
......
......@@ -20,15 +20,13 @@ const RndComponent = ({ component }: ImageComponentProps) => {
const competitionId = useAppSelector((state) => state.editor.competition.id)
const slideId = useAppSelector((state) => state.editor.activeSlideId)
const handleUpdatePos = (pos: Position) => {
// TODO: change path to /slides/${slideId}
axios.put(`/competitions/${competitionId}/slides/0/components/${component.id}`, {
axios.put(`/competitions/${competitionId}/slides/${slideId}/components/${component.id}`, {
x: pos.x,
y: pos.y,
})
}
const handleUpdateSize = (size: Size) => {
// TODO: change path to /slides/${slideId}
axios.put(`/competitions/${competitionId}/slides/0/components/${component.id}`, {
axios.put(`/competitions/${competitionId}/slides/${slideId}/components/${component.id}`, {
w: size.w,
h: size.h,
})
......
......@@ -133,7 +133,7 @@ const SlideSettings: React.FC = () => {
if (selectedSlideType === 0) {
// Change slide type from a question type to information
await axios
.delete(`/competitions/${id}/slides/${activeSlide.order}/questions/${activeSlide.questions[0].id}`)
.delete(`/competitions/${id}/slides/${activeSlide.id}/questions/${activeSlide.questions[0].id}`)
.then(() => {
dispatch(getEditorCompetition(id))
})
......@@ -141,10 +141,10 @@ const SlideSettings: React.FC = () => {
} else {
// Change slide type from question type to another question type
await axios
.delete(`/competitions/${id}/slides/${activeSlide.order}/questions/${activeSlide.questions[0].id}`)
.delete(`/competitions/${id}/slides/${activeSlide.id}/questions/${activeSlide.questions[0].id}`)
.catch(console.log)
await axios
.post(`/competitions/${id}/slides/${activeSlide.order}/questions`, {
.post(`/competitions/${id}/slides/${activeSlide.id}/questions`, {
name: 'Ny fråga',
total_score: 0,
type_id: selectedSlideType,
......@@ -158,7 +158,7 @@ const SlideSettings: React.FC = () => {
} else if (selectedSlideType !== 0) {
// Change slide type from information to a question type
await axios
.post(`/competitions/${id}/slides/${activeSlide.order}/questions`, {
.post(`/competitions/${id}/slides/${activeSlide.id}/questions`, {
name: 'Ny fråga',
total_score: 0,
type_id: selectedSlideType,
......@@ -208,10 +208,10 @@ const SlideSettings: React.FC = () => {
const addAlternative = async () => {
if (activeSlide && activeSlide.questions[0]) {
await axios
.post(
`/competitions/${id}/slides/${activeSlide?.order}/questions/${activeSlide?.questions[0].id}/alternatives`,
{ text: '', value: 0 }
)
.post(`/competitions/${id}/slides/${activeSlide?.id}/questions/${activeSlide?.questions[0].id}/alternatives`, {
text: '',
value: 0,
})
.then(() => {
dispatch(getEditorCompetition(id))
})
......@@ -237,7 +237,7 @@ const SlideSettings: React.FC = () => {
const handleAddText = async () => {
if (activeSlide) {
await axios.post(`/competitions/${id}/slides/${activeSlide?.order}/components`, {
await axios.post(`/competitions/${id}/slides/${activeSlide?.id}/components`, {
type_id: 1,
data: { text: 'Ny text' },
w: 315,
......@@ -261,7 +261,7 @@ const SlideSettings: React.FC = () => {
setTimer(+event.target.value)
if (activeSlide) {
await axios
.put(`/competitions/${id}/slides/${activeSlide.order}`, { timer: event.target.value })
.put(`/competitions/${id}/slides/${activeSlide.id}`, { timer: event.target.value })
.then(() => {
dispatch(getEditorCompetition(id))
})
......
......@@ -20,6 +20,7 @@ const TextComponentEdit = ({ component }: ImageComponentProps) => {
const competitionId = useAppSelector((state) => state.editor.competition.id)
const [content, setContent] = useState('')
const [timerHandle, setTimerHandle] = React.useState<number | undefined>(undefined)
const activeSlideId = useAppSelector((state) => state.editor.activeSlideId)
const dispatch = useAppDispatch()
useEffect(() => {
......@@ -36,7 +37,7 @@ const TextComponentEdit = ({ component }: ImageComponentProps) => {
setTimerHandle(
window.setTimeout(async () => {
console.log('Content was updated on server. id: ', component.id)
await axios.put(`/competitions/${competitionId}/slides/0/components/${component.id}`, {
await axios.put(`/competitions/${competitionId}/slides/${activeSlideId}/components/${component.id}`, {
data: { ...component.data, text: a },
})
dispatch(getEditorCompetition(id))
......@@ -45,7 +46,7 @@ const TextComponentEdit = ({ component }: ImageComponentProps) => {
}
const handleDeleteText = async (componentId: number) => {
await axios.delete(`/competitions/${id}/slides/0/components/${componentId}`)
await axios.delete(`/competitions/${id}/slides/${activeSlideId}/components/${componentId}`)
dispatch(getEditorCompetition(id))
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment