From e29b1b3889a8d3a0e607a9a16fd51b676c72c115 Mon Sep 17 00:00:00 2001 From: Mirlan Date: Wed, 22 Jul 2020 19:45:50 +0600 Subject: [PATCH] feat(#185): added score store and component (#50) --- public/images/switchOff.svg | 25 ++++++++++++++++ public/images/switchOn.svg | 25 ++++++++++++++++ src/config/lexics/authenticated.tsx | 1 + src/features/App/AuthenticatedApp.tsx | 8 ++--- src/features/ToggleScore/index.tsx | 19 ++++++++++-- src/features/ToggleScore/store.tsx | 28 ++++++++++++++++++ src/features/ToggleScore/styled.tsx | 42 ++++++++++++++++++++++++++- 7 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 public/images/switchOff.svg create mode 100644 public/images/switchOn.svg create mode 100644 src/features/ToggleScore/store.tsx diff --git a/public/images/switchOff.svg b/public/images/switchOff.svg new file mode 100644 index 00000000..102d88b5 --- /dev/null +++ b/public/images/switchOff.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/switchOn.svg b/public/images/switchOn.svg new file mode 100644 index 00000000..9ad123da --- /dev/null +++ b/public/images/switchOn.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/config/lexics/authenticated.tsx b/src/config/lexics/authenticated.tsx index f2515ddd..a440c9a0 100644 --- a/src/config/lexics/authenticated.tsx +++ b/src/config/lexics/authenticated.tsx @@ -1,6 +1,7 @@ export const authenticatedLexics = { basketball: 6960, football: 6958, + hide_score: 12982, hockey: 6959, logout: 4306, player: 630, diff --git a/src/features/App/AuthenticatedApp.tsx b/src/features/App/AuthenticatedApp.tsx index d3fa8cac..e21520c1 100644 --- a/src/features/App/AuthenticatedApp.tsx +++ b/src/features/App/AuthenticatedApp.tsx @@ -1,4 +1,4 @@ -import React, { Fragment } from 'react' +import React from 'react' import { Route, Redirect, @@ -16,13 +16,13 @@ import { PlayerPage } from 'features/PlayerPage' import { TournamentPage } from 'features/TournamentPage' import { LanguageSelect } from 'features/LanguageSelect' import { UserAccount } from 'features/UserAccount' -import { ToggleScore } from 'features/ToggleScore' +import { ScoreStore, ToggleScore } from 'features/ToggleScore' export const AuthenticatedApp = () => { useLexicsConfig(authenticatedLexics) return ( - + @@ -51,6 +51,6 @@ export const AuthenticatedApp = () => { - + ) } diff --git a/src/features/ToggleScore/index.tsx b/src/features/ToggleScore/index.tsx index bd946af6..67736340 100644 --- a/src/features/ToggleScore/index.tsx +++ b/src/features/ToggleScore/index.tsx @@ -1,5 +1,20 @@ import React from 'react' -import { Wrapper } from './styled' +import { useScoreStore } from './store' +import { + Switch, + Title, + Icon, +} from './styled' -export const ToggleScore = () => +export * from './store' + +export const ToggleScore = () => { + const { isVisible, toggle } = useScoreStore() + return ( + + + <Icon isOn={isVisible} /> + </Switch> + ) +} diff --git a/src/features/ToggleScore/store.tsx b/src/features/ToggleScore/store.tsx new file mode 100644 index 00000000..8715bcf1 --- /dev/null +++ b/src/features/ToggleScore/store.tsx @@ -0,0 +1,28 @@ +import type { ReactNode } from 'react' +import React, { + createContext, + useContext, +} from 'react' + +import { useToggle } from 'hooks' + +type ScoreStore = { + isVisible: boolean, + toggle: () => void, +} + +type Props = { children: ReactNode } + +const ScoreContext = createContext({} as ScoreStore) + +export const ScoreStore = ({ children }: Props) => { + const { isOpen, toggle } = useToggle() + + return ( + <ScoreContext.Provider value={{ isVisible: isOpen, toggle }}> + {children} + </ScoreContext.Provider> + ) +} + +export const useScoreStore = () => useContext(ScoreContext) diff --git a/src/features/ToggleScore/styled.tsx b/src/features/ToggleScore/styled.tsx index 8646cd0a..72c0966f 100644 --- a/src/features/ToggleScore/styled.tsx +++ b/src/features/ToggleScore/styled.tsx @@ -1,3 +1,43 @@ import styled from 'styled-components/macro' -export const Wrapper = styled.div`` +import { T9n } from 'features/T9n' + +export const Switch = styled.div` + position: absolute; + right: 99px; + top: 32px; + display: flex; + align-items: center; + cursor: pointer; +` + +export const Title = styled(T9n)` + font-style: normal; + font-weight: 600; + font-size: 14px; + letter-spacing: -0.03em; + color: #999999; + margin-right: 5px; +` + +type IconProps = { + isOn: boolean, +} + +export const Icon = styled.div<IconProps>` + width: 28px; + height: 16px; + color: white; + background-repeat: no-repeat; + ${({ isOn }) => ( + isOn + ? ` + background-image: url(/images/switchOn.svg); + background-position: 0 -1px; + ` + : ` + background-image: url(/images/switchOff.svg); + background-position: -2px -1px; + ` + )}; +`