Save initial home sections for new users
This commit is contained in:
		
							parent
							
								
									987274ad2d
								
							
						
					
					
						commit
						4aea3b96d7
					
				|  | @ -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 /> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user