-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Components renamed and little refactor
- Loading branch information
Showing
13 changed files
with
136 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { PropTypes } from 'prop-types' | ||
|
||
import Button from 'components/Button' | ||
import { LogInIcon, LogOutIcon } from 'components/icons' | ||
import Loading from 'components/Loading' | ||
import { useAuth } from 'contexts/AuthContext' | ||
import { useModal } from 'contexts/ModalContext' | ||
|
||
const AuthButtons = ({ children }) => { | ||
const { isAuthed, isLoading, signIn, signOut } = useAuth() | ||
const { renderModal } = useModal() | ||
|
||
const handleSignOut = () => renderModal( | ||
'Do you want to sign out?', | ||
signOut | ||
) | ||
|
||
if (isLoading) { | ||
return <Button grow secondary><Loading small /></Button> | ||
} | ||
|
||
if (!isAuthed) { | ||
return <Button grow primary onClick={signIn}><LogInIcon /></Button> | ||
} | ||
|
||
return ( | ||
<> | ||
{children} | ||
<Button grow secondary onClick={handleSignOut}><LogOutIcon /></Button> | ||
</> | ||
) | ||
} | ||
|
||
AuthButtons.propTypes = { | ||
children: PropTypes.node, | ||
} | ||
|
||
export default AuthButtons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { DrawArea } from 'react-drawarea' | ||
import { useLocation } from 'wouter' | ||
|
||
import AuthButtons from 'components/AuthButtons' | ||
import Button from 'components/Button' | ||
import CalcButtons from 'components/CalcButtons' | ||
import { ChartIcon } from 'components/icons' | ||
import Numbers from 'components/Numbers' | ||
import Result from 'components/Result' | ||
import { ROUTE_STATS } from 'constants/routes' | ||
import { useAttempts } from 'contexts/AttemptsContext' | ||
import { useModal } from 'contexts/ModalContext' | ||
import useCalc from 'hooks/useCalc' | ||
|
||
import styles from 'styles/components/Main.module.css' | ||
|
||
const Calc = () => { | ||
const [, setLocation] = useLocation() | ||
const { renderModal } = useModal() | ||
const { isStoring } = useAttempts() | ||
const { isCompleted, isSolved, numbers, result, complete, solve, restart } = useCalc() | ||
|
||
const handleStats = () => isCompleted | ||
? setLocation(ROUTE_STATS) | ||
: renderModal( | ||
'Numbers will be discarded. Are you sure?', | ||
() => setLocation(ROUTE_STATS) | ||
) | ||
|
||
return ( | ||
<> | ||
<header className={styles.header}> | ||
<AuthButtons> | ||
<Button grow primary onClick={handleStats}><ChartIcon /></Button> | ||
</AuthButtons> | ||
</header> | ||
<DrawArea | ||
className={styles.canvas} | ||
thickness={10} | ||
color='#ba324f' | ||
disabled={isSolved} | ||
> | ||
{isSolved && <Result value={result} />} | ||
<Numbers isSolved={isSolved} numbers={numbers} /> | ||
<div className={styles.footer}> | ||
<CalcButtons | ||
isCompleted={isCompleted} | ||
isLoading={isStoring} | ||
isSolved={isSolved} | ||
handleRestart={restart} | ||
handleSolve={solve} | ||
handleSuccess={complete} | ||
/> | ||
</div> | ||
</DrawArea> | ||
</> | ||
) | ||
} | ||
|
||
export default Calc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export const ROUTE_MAIN = '/' | ||
export const ROUTE_CALC = '/' | ||
export const ROUTE_STATS = '/stats' | ||
|
||
export const ROUTES = { | ||
MAIN: ROUTE_MAIN, | ||
CALC: ROUTE_CALC, | ||
STATS: ROUTE_STATS, | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
.header { | ||
display: flex; | ||
justify-content: flex-end; | ||
z-index: 1; | ||
} | ||
|
||
.canvas { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
} | ||
|
||
.footer { | ||
display: flex; | ||
z-index: 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
04a0243
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: