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