Skip to content
Snippets Groups Projects
ActionView.tsx 1.67 KiB
Newer Older
  • Learn to ignore specific revisions
  • Guilhem CARRON's avatar
    Guilhem CARRON committed
    import Content from 'components/Content/Content'
    
    import CozyBar from 'components/Header/CozyBar'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import Header from 'components/Header/Header'
    
    import { UserActionState } from 'enums'
    
    import { UserChallenge } from 'models'
    
    import React, { useRef } from 'react'
    
    import { useAppSelector } from 'store/hooks'
    
    import ActionChoose from './ActionChoose/ActionChoose'
    import ActionDone from './ActionDone/ActionDone'
    import ActionOnGoing from './ActionOnGoing/ActionOnGoing'
    
     * http://ecolyo.cozy.tools:8080/#/challenges/action
    
    const ActionView = () => {
    
      const { currentChallenge } = useAppSelector(state => state.ecolyo.challenge)
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
    
      const mainContentRef = useRef<HTMLDivElement>(null)
      const focusMainContent = () => {
        setTimeout(() => mainContentRef.current?.focus(), 0)
      }
    
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      const renderAction = (challenge: UserChallenge) => {
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        switch (challenge.action.state) {
          case UserActionState.ONGOING:
            return <ActionOnGoing userAction={challenge.action} />
    
          case UserActionState.NOTIFICATION:
            return <ActionDone currentChallenge={challenge} />
    
          case UserActionState.UNSTARTED:
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          default:
    
            return (
              <ActionChoose userChallenge={challenge} setFocus={focusMainContent} />
            )
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        }
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      }
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
      return (
        <>
    
          <CozyBar titleKey="common.title_action" displayBackArrow={true} />
    
          <Header desktopTitleKey="common.title_action" displayBackArrow={true} />
    
          <Content>
            <div
              ref={mainContentRef}
              style={{ outline: 'none', margin: 'auto' }}
              tabIndex={-1}
            >
              {currentChallenge && renderAction(currentChallenge)}
            </div>
          </Content>
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        </>
      )
    }
    
    export default ActionView