2022-09-08 06:36:34 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import { useState } from 'react'
|
|
|
|
import { ArrangeHome } from 'web/components/arrange-home'
|
|
|
|
import { Button } from 'web/components/button'
|
|
|
|
import { Col } from 'web/components/layout/col'
|
|
|
|
import { Row } from 'web/components/layout/row'
|
|
|
|
import { Page } from 'web/components/page'
|
|
|
|
import { SiteLink } from 'web/components/site-link'
|
|
|
|
import { Title } from 'web/components/title'
|
|
|
|
import { useTracking } from 'web/hooks/use-tracking'
|
|
|
|
import { useUser } from 'web/hooks/use-user'
|
|
|
|
import { updateUser } from 'web/lib/firebase/users'
|
2022-09-16 21:21:13 +00:00
|
|
|
import { track } from 'web/lib/service/analytics'
|
2022-09-30 17:00:14 +00:00
|
|
|
import { getHomeItems } from '.'
|
2022-09-08 06:36:34 +00:00
|
|
|
|
|
|
|
export default function Home() {
|
|
|
|
const user = useUser()
|
|
|
|
|
|
|
|
useTracking('edit home')
|
|
|
|
|
2022-09-12 05:39:04 +00:00
|
|
|
const [homeSections, setHomeSections] = useState(user?.homeSections ?? [])
|
2022-09-08 06:36:34 +00:00
|
|
|
|
2022-09-12 05:39:04 +00:00
|
|
|
const updateHomeSections = (newHomeSections: string[]) => {
|
2022-09-08 06:36:34 +00:00
|
|
|
if (!user) return
|
|
|
|
updateUser(user.id, { homeSections: newHomeSections })
|
|
|
|
setHomeSections(newHomeSections)
|
|
|
|
}
|
|
|
|
|
2022-09-30 17:00:14 +00:00
|
|
|
const { sections } = getHomeItems(homeSections)
|
2022-09-16 21:12:24 +00:00
|
|
|
|
2022-09-08 06:36:34 +00:00
|
|
|
return (
|
|
|
|
<Page>
|
2022-09-12 05:39:04 +00:00
|
|
|
<Col className="pm:mx-10 gap-4 px-4 pb-6 pt-2">
|
2022-09-08 06:36:34 +00:00
|
|
|
<Row className={'w-full items-center justify-between'}>
|
2022-09-13 22:47:29 +00:00
|
|
|
<Title text="Customize your home page" />
|
2022-09-08 06:36:34 +00:00
|
|
|
<DoneButton />
|
|
|
|
</Row>
|
|
|
|
|
2022-09-30 17:00:14 +00:00
|
|
|
<Col className="flex-1">
|
|
|
|
<ArrangeHome sections={sections} setSectionIds={updateHomeSections} />
|
2022-09-17 23:30:27 +00:00
|
|
|
</Col>
|
2022-09-08 06:36:34 +00:00
|
|
|
</Col>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function DoneButton(props: { className?: string }) {
|
|
|
|
const { className } = props
|
|
|
|
|
|
|
|
return (
|
2022-09-16 21:12:24 +00:00
|
|
|
<SiteLink href="/home">
|
2022-09-13 22:47:29 +00:00
|
|
|
<Button
|
|
|
|
size="lg"
|
|
|
|
color="blue"
|
|
|
|
className={clsx(className, 'flex whitespace-nowrap')}
|
2022-09-16 21:21:13 +00:00
|
|
|
onClick={() => track('done editing home')}
|
2022-09-13 22:47:29 +00:00
|
|
|
>
|
2022-09-08 06:36:34 +00:00
|
|
|
Done
|
|
|
|
</Button>
|
|
|
|
</SiteLink>
|
|
|
|
)
|
|
|
|
}
|