Skip to content

Commit

Permalink
inline content of home page
Browse files Browse the repository at this point in the history
  • Loading branch information
ducaale committed Dec 19, 2023
1 parent 14a6c2b commit 1e43cb3
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 117 deletions.
114 changes: 0 additions & 114 deletions src/components/home/Home.tsx

This file was deleted.

115 changes: 112 additions & 3 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,114 @@
import { Home } from '../components/home/Home'
import { useState, useEffect } from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import styled from 'styled-components'
import { lighten, darken } from 'polished'

export default function HomePage() {
return <Home />
import { Logo } from '../components/core/Logo'
import { PrimaryButton, Button } from '../components/core/Button'
import { colors } from '../theme'

const Wrapper = styled.div`
height: 100vh;
display: grid;
grid-template-rows: 1fr 75px;
`

const Main = styled.main`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
`

const Footer = styled.footer`
background: ${darken(0.02, colors.background)};
border-top: 1px solid ${colors.borders};
padding: 0 50px;
display: flex;
justify-content: space-between;
align-items: center;
gap: 2em;
font-size: 0.8em;
color: ${lighten(0.3, colors.background)};
@media screen and (max-width: 850px) {
padding: 0 15px;
}
a {
text-decoration: none;
color: ${lighten(0.3, colors.background)};
&:hover {
text-decoration: underline;
}
}
`

const Copyright = styled.span`
flex: 1;
`

const HiddenInput = styled.input`
display: none;
`

export default function Home() {
const router = useRouter()
const [hasSession, setHasSession] = useState(false)

useEffect(() => {
if (typeof window !== 'undefined') {
setHasSession(!!localStorage.getItem('jsonResume'))
}
}, [])

const startNewSession = () => {
window.localStorage.clear()
router.push('/generator')
}

const handleFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
const reader = new FileReader()
reader.addEventListener('load', (e) => {
// TODO: validate JSON schema using Zod
const jsonResume = JSON.parse(e.target?.result as string)
localStorage.setItem('jsonResume', JSON.stringify(jsonResume))
router.push('/generator')
})

if (e.target.files) {
reader.readAsText(e.target.files[0])
}
}

return (
<Wrapper>
<Main>
<Logo marginBottom="0.75em" />
<PrimaryButton onClick={startNewSession}>Make New Resume</PrimaryButton>
{hasSession && (
<Link href="/generator" style={{ textDecoration: 'none' }}>
<Button>Continue Session</Button>
</Link>
)}
<Button as="label" htmlFor="import-json">
Import JSON
</Button>
<HiddenInput
id="import-json"
type="file"
accept="application/json"
onChange={handleFileUpload}
/>
</Main>
<Footer>
<Copyright>© 2022 Saad Quadri</Copyright>
<Link href="/about">About</Link>
<a href="https://github.com/saadq/resumake">Source</a>
<a href="https://github.com/saadq/resumake/issues">Issues</a>
</Footer>
</Wrapper>
)
}

0 comments on commit 1e43cb3

Please sign in to comment.