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

Resolve "Fix redux actions in editor"

parent 2345d4f7
No related branches found
No related tags found
1 merge request!71Resolve "Fix redux actions in editor"
Pipeline #41304 failed
import { Divider, Typography } from '@material-ui/core' import { CircularProgress, Divider, Typography } from '@material-ui/core'
import AppBar from '@material-ui/core/AppBar' import AppBar from '@material-ui/core/AppBar'
import CssBaseline from '@material-ui/core/CssBaseline' import CssBaseline from '@material-ui/core/CssBaseline'
import Drawer from '@material-ui/core/Drawer' import Drawer from '@material-ui/core/Drawer'
...@@ -13,7 +13,14 @@ import { useAppDispatch, useAppSelector } from '../../hooks' ...@@ -13,7 +13,14 @@ import { useAppDispatch, useAppSelector } from '../../hooks'
import { Content } from '../views/styled' import { Content } from '../views/styled'
import SettingsPanel from './components/SettingsPanel' import SettingsPanel from './components/SettingsPanel'
import SlideEditor from './components/SlideEditor' import SlideEditor from './components/SlideEditor'
import { PresentationEditorContainer, SlideListItem, ToolBarContainer, ViewButton, ViewButtonGroup } from './styled' import {
CenteredSpinnerContainer,
PresentationEditorContainer,
SlideListItem,
ToolBarContainer,
ViewButton,
ViewButtonGroup,
} from './styled'
function createSlide(name: string) { function createSlide(name: string) {
return { name } return { name }
...@@ -66,6 +73,7 @@ const PresentationEditorPage: React.FC = () => { ...@@ -66,6 +73,7 @@ const PresentationEditorPage: React.FC = () => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const activeSlideId = useAppSelector((state) => state.editor.activeSlideId) const activeSlideId = useAppSelector((state) => state.editor.activeSlideId)
const competition = useAppSelector((state) => state.editor.competition) const competition = useAppSelector((state) => state.editor.competition)
const competitionLoading = useAppSelector((state) => state.editor.loading)
// TODO: wait for dispatch to finish // TODO: wait for dispatch to finish
useEffect(() => { useEffect(() => {
dispatch(getEditorCompetition(id)) dispatch(getEditorCompetition(id))
...@@ -131,7 +139,13 @@ const PresentationEditorPage: React.FC = () => { ...@@ -131,7 +139,13 @@ const PresentationEditorPage: React.FC = () => {
}} }}
anchor="right" anchor="right"
> >
<SettingsPanel></SettingsPanel> {!competitionLoading ? (
<SettingsPanel />
) : (
<CenteredSpinnerContainer>
<CircularProgress />
</CenteredSpinnerContainer>
)}
</Drawer> </Drawer>
<Content leftDrawerWidth={leftDrawerWidth} rightDrawerWidth={rightDrawerWidth}> <Content leftDrawerWidth={leftDrawerWidth} rightDrawerWidth={rightDrawerWidth}>
......
...@@ -64,7 +64,6 @@ const CompetitionSettings: React.FC = () => { ...@@ -64,7 +64,6 @@ const CompetitionSettings: React.FC = () => {
const { id }: CompetitionParams = useParams() const { id }: CompetitionParams = useParams()
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const competition = useAppSelector((state) => state.editor.competition) const competition = useAppSelector((state) => state.editor.competition)
const updateCompetitionName = async (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => { const updateCompetitionName = async (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => {
await axios await axios
.put(`/competitions/${id}`, { name: event.target.value }) .put(`/competitions/${id}`, { name: event.target.value })
......
...@@ -23,3 +23,10 @@ export const SlideListItem = styled(ListItem)` ...@@ -23,3 +23,10 @@ export const SlideListItem = styled(ListItem)`
export const PresentationEditorContainer = styled.div` export const PresentationEditorContainer = styled.div`
height: 100%; height: 100%;
` `
export const CenteredSpinnerContainer = styled.div`
display: flex;
align-items: center;
justify-content: center;
height: 100%;
`
...@@ -5,6 +5,7 @@ import { RichCompetition } from '../interfaces/ApiRichModels' ...@@ -5,6 +5,7 @@ import { RichCompetition } from '../interfaces/ApiRichModels'
interface EditorState { interface EditorState {
competition: RichCompetition competition: RichCompetition
activeSlideId: number activeSlideId: number
loading: boolean
} }
const initialState: EditorState = { const initialState: EditorState = {
...@@ -17,6 +18,7 @@ const initialState: EditorState = { ...@@ -17,6 +18,7 @@ const initialState: EditorState = {
teams: [], teams: [],
}, },
activeSlideId: 0, activeSlideId: 0,
loading: true,
} }
export default function (state = initialState, action: AnyAction) { export default function (state = initialState, action: AnyAction) {
...@@ -25,6 +27,7 @@ export default function (state = initialState, action: AnyAction) { ...@@ -25,6 +27,7 @@ export default function (state = initialState, action: AnyAction) {
return { return {
competition: action.payload as RichCompetition, competition: action.payload as RichCompetition,
activeSlideId: action.payload.slides[0].id as number, activeSlideId: action.payload.slides[0].id as number,
loading: false,
} }
case Types.SET_EDITOR_SLIDE_ID: case Types.SET_EDITOR_SLIDE_ID:
return { return {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment