-
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.
- Loading branch information
1 parent
ed9ab44
commit 8e73ddd
Showing
12 changed files
with
562 additions
and
1,626 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
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,68 @@ | ||
import { useUser } from '@auth0/nextjs-auth0' | ||
import styled from 'styled-components' | ||
import { designTokens } from '@components/Theme/designTokens' | ||
import Card from '@components/Card' | ||
import { LoadingSmall } from '@components/LoadingBox' | ||
import Link from 'next/link' | ||
|
||
const ProfileInfo = styled.div` | ||
display: flex; | ||
align-items: center; | ||
@media screen and (max-width: ${designTokens.breakpoints[4]}) { | ||
margin-bottom: ${designTokens.space[3]}; | ||
} | ||
` | ||
|
||
const ProfileContainer = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
@media screen and (max-width: ${designTokens.breakpoints[4]}) { | ||
flex-direction: column; | ||
align-items: flex-start; | ||
} | ||
` | ||
|
||
const ProfileAvatar = styled.div` | ||
width: ${designTokens.space[6]}; | ||
height: ${designTokens.space[6]}; | ||
border-radius: 999px; | ||
margin-right: ${designTokens.space[3]}; | ||
background: url(${props => props.bg}); | ||
background-repeat: no-repeat; | ||
background-size: cover; | ||
` | ||
|
||
const Profile = () => { | ||
const { user, isLoading } = useUser() | ||
return( | ||
<Card> | ||
{ | ||
isLoading && (<LoadingSmall/>) | ||
} | ||
{ | ||
user && ( | ||
<ProfileContainer> | ||
<ProfileInfo> | ||
<ProfileAvatar bg={user.picture}/> | ||
<div> | ||
<h5 style={{ marginTop: '0', marginBottom: designTokens.space[1] }}>{user.name}</h5> | ||
<small>{user.email}</small> | ||
</div> | ||
</ProfileInfo> | ||
<Link href="/api/auth/logout"> | ||
<a className="link">Logout</a> | ||
</Link> | ||
</ProfileContainer> | ||
) | ||
} | ||
{ | ||
!user && ( | ||
<span>No profile</span> | ||
) | ||
} | ||
</Card> | ||
) | ||
} | ||
|
||
export default Profile |
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,175 @@ | ||
import React, { useEffect } from 'react' | ||
import styled from 'styled-components' | ||
import { designTokens } from '@components/Theme/designTokens' | ||
import { Label, ItemTitle, Body } from '@components/Typography' | ||
import Chip from '@components/Chip' | ||
|
||
const WordleContainer = styled.div` | ||
border: 1px solid var(--grey200); | ||
padding: ${designTokens.space[3]}; | ||
display: grid; | ||
grid-template-columns: auto ${designTokens.space[8]}; | ||
grid-column-gap: ${designTokens.space[4]}; | ||
margin-bottom: ${designTokens.space[4]}; | ||
` | ||
|
||
const ResultContainer = styled.div` | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
grid-row-gap: ${designTokens.space[1]}; | ||
` | ||
|
||
const Row = styled.div` | ||
display: grid; | ||
grid-column-gap: ${designTokens.space[1]}; | ||
grid-template-columns: repeat(5, ${designTokens.space[3]}); | ||
` | ||
|
||
const Block = styled.span` | ||
width: ${designTokens.space[3]}; | ||
height: ${designTokens.space[3]}; | ||
background: ${props => props.type === 'correct' ? '#0BB409' : props.type === 'present' ? '#FBCC1B' : 'var(--grey300)'}; | ||
display: inline-block; | ||
` | ||
|
||
const Header = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: flex-start; | ||
` | ||
|
||
const Emoji = styled.label` | ||
font-size: ${designTokens.fontSizes[2]}; | ||
` | ||
|
||
const AnaylticsContainer = styled.div` | ||
display: grid; | ||
border: 1px solid var(--grey200); | ||
padding: ${designTokens.space[3]}; | ||
grid-template-columns: 1fr; | ||
grid-row-gap: ${designTokens.space[1]}; | ||
margin-bottom: ${designTokens.space[4]}; | ||
` | ||
|
||
const WordleResult = ({result}) => { | ||
|
||
return( | ||
<ResultContainer> | ||
{ | ||
result.map((item, i) => ( | ||
<Row key={i}> | ||
{ | ||
item.map((letter, i) => ( | ||
<Block type={letter} key={i} title={letter}/> | ||
)) | ||
} | ||
</Row> | ||
)) | ||
} | ||
</ResultContainer> | ||
) | ||
} | ||
|
||
const Evaluation = ({ value }) => { | ||
|
||
const getProgress = () => { | ||
switch (value) { | ||
case 'X': | ||
return '🤬' | ||
case '6': | ||
return '🥵' | ||
case '5': | ||
return '😑' | ||
case '4': | ||
return '😐' | ||
case '3': | ||
return '😃' | ||
case '2': | ||
return '🤠' | ||
case '1': | ||
return '🤯' | ||
default: | ||
return '' | ||
} | ||
} | ||
|
||
if(value === 'X') { | ||
return( | ||
<div> | ||
<Emoji>{getProgress()}</Emoji> | ||
<Label subtle>Unsuccessful</Label> | ||
</div> | ||
) | ||
} else { | ||
return ( | ||
<div> | ||
<Emoji>{getProgress()}</Emoji> | ||
<Label subtle>{value} attempts</Label> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
const Wordle = ({wordle}) => { | ||
|
||
const formatDate = (input) => { | ||
const date = new Date(input).toLocaleDateString('en-us', { | ||
year: 'numeric', | ||
month: 'long', | ||
day: 'numeric', | ||
}) | ||
|
||
return date | ||
} | ||
|
||
return( | ||
<WordleContainer> | ||
<Header> | ||
<div> | ||
<ItemTitle>Wordle {wordle.matchNumber}</ItemTitle> | ||
<Label subtle>{formatDate(wordle.date)}</Label> | ||
</div> | ||
<Evaluation value={wordle.eval}/> | ||
</Header> | ||
<WordleResult result={wordle.result} /> | ||
</WordleContainer> | ||
) | ||
} | ||
|
||
export const WordleAnalytics = ({data}) => { | ||
|
||
const getSum = () => { | ||
const attempts = [] | ||
|
||
data.map(item => { | ||
if(item.eval === 'X') { | ||
attempts.push(0) | ||
} else { | ||
attempts.push(parseInt(item.eval)) | ||
} | ||
}) | ||
|
||
console.log(attempts) | ||
|
||
const arraySum = (ar) => { | ||
var sum = 0; | ||
for (var i = 0; i < ar.length; i++) { | ||
sum += ar[i]; | ||
} | ||
return sum; | ||
} | ||
|
||
const average = arraySum(attempts)/data.length | ||
|
||
return average | ||
} | ||
|
||
return( | ||
<AnaylticsContainer> | ||
<Label subtle>Average # of Attempts</Label> | ||
<h4>{getSum()} Attempts</h4> | ||
</AnaylticsContainer> | ||
) | ||
} | ||
|
||
export default Wordle |
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
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,3 @@ | ||
import { handleAuth } from '@auth0/nextjs-auth0' | ||
|
||
export default handleAuth() |
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,64 @@ | ||
const { Client } = require('@notionhq/client'); | ||
|
||
const notion = new Client({ auth: process.env.NOTION_API_KEY }); | ||
|
||
export default async (req,res) => { | ||
|
||
const response = await notion.databases.query({ | ||
database_id: process.env.NOTION_WORDLE, | ||
sorts: [ | ||
{ | ||
property: 'Date', | ||
direction: 'descending', | ||
}, | ||
], | ||
}); | ||
|
||
const wordles = [] | ||
|
||
response.results.map(item => { | ||
const firstLine = item.properties.Result.title[0].plain_text.split('\n')[0]; | ||
const match = firstLine.split(' ')[1]; | ||
const result = firstLine.split(' ')[2]; | ||
const evaulation = item.properties.Result.title[0].plain_text.replace(/(?:\r\n|\r|\n)/g, '<br>'); | ||
|
||
const evaulations = [] | ||
const results = item.properties.Result.title[0].plain_text.split('\n').slice(1) | ||
|
||
const parsed = () => { | ||
const answers = [] | ||
results.map(item => { | ||
|
||
const replaced = item.replace(/⬛/g, '0').replace(/🟨/g, '1').replace(/🟩/g, '2') | ||
|
||
const guess = replaced.split('') | ||
|
||
const parsedGuess = [] | ||
|
||
guess.map(a => { | ||
if(a === '0') { | ||
parsedGuess.push('absent') | ||
} else if(a === '1') { | ||
parsedGuess.push('present') | ||
} else if(a === '2') { | ||
parsedGuess.push('correct') | ||
} | ||
}) | ||
|
||
answers.push(parsedGuess) | ||
}) | ||
|
||
return answers | ||
} | ||
|
||
wordles.push({ | ||
id: item.id, | ||
result: parsed(), | ||
date: item.properties.Date.date.start, | ||
matchNumber: match, | ||
eval: result.split('')[0] | ||
}) | ||
}) | ||
|
||
res.status(200).json({ wordles }); | ||
} |
Oops, something went wrong.