Created
November 16, 2018 07:21
-
-
Save kitze/479f0fc52d537bffd8eeed21118e8f29 to your computer and use it in GitHub Desktop.
do example
This file contains hidden or 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
import React, { useContext } from "react"; | |
//styles | |
import * as S from "./styles"; | |
import * as A from "styles/shared-components"; | |
//components | |
import Header from "components/Header"; | |
import { AuthContext } from "components/Auth"; | |
import SpinnerComponent from "components/Spinner"; | |
import { getAllUnlockedModules, getAllUserModules } from "utils/get-courses"; | |
function Home() { | |
const { user } = useContext(AuthContext); | |
return ( | |
<S.Home> | |
<Header /> | |
<S.Content> | |
{do { | |
if (!(user && user.createdAt)) { | |
<SpinnerComponent />; | |
} else { | |
if (!user.enabled) { | |
<div> | |
Your account is not enabled yet, please take a break 🍵️😎️ | |
</div>; | |
} else { | |
const coursesForUser = getAllUserModules(user); | |
const unlockedModules = getAllUnlockedModules(user); | |
const noCourses = coursesForUser.length === 0; | |
if (noCourses) { | |
<div>No courses available, please try again in a second.</div>; | |
} else { | |
<S.List> | |
{coursesForUser.map(course => { | |
let disabled = !unlockedModules.includes(course.title); | |
return ( | |
<S.Item | |
key={course} | |
disabled={disabled} | |
to={disabled ? "" : `/lab/${course}.slug`} | |
> | |
{course.title} | |
</S.Item> | |
); | |
})} | |
</S.List>; | |
} | |
} | |
} | |
}} | |
</S.Content> | |
</S.Home> | |
); | |
} | |
export default Home; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey @kitze, I noticed you were asking @kentcdodds to refactor this without
do
. These days I've enjoyed using tons of small components all over the place..