Save initial home sections for new users

This commit is contained in:
James Grugett 2022-09-17 23:58:18 -05:00
parent 987274ad2d
commit 4aea3b96d7

View File

@ -1,4 +1,4 @@
import React, { ReactNode } from 'react'
import React, { ReactNode, useEffect } from 'react'
import Router from 'next/router'
import {
AdjustmentsIcon,
@ -56,6 +56,18 @@ export default function Home() {
const { sections } = getHomeItems(groups, user?.homeSections ?? [])
useEffect(() => {
if (
user &&
!user.homeSections &&
sections.length > 0 &&
groups.length > 0
) {
// Save initial home sections.
updateUser(user.id, { homeSections: sections.map((s) => s.id) })
}
}, [user, sections, groups])
return (
<Page>
<Toaster />