From 4aea3b96d7b4fddabe49dadb2ea6e15953b35181 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sat, 17 Sep 2022 23:58:18 -0500 Subject: [PATCH] Save initial home sections for new users --- web/pages/home/index.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/web/pages/home/index.tsx b/web/pages/home/index.tsx index fe27a2a0..8246f2f1 100644 --- a/web/pages/home/index.tsx +++ b/web/pages/home/index.tsx @@ -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 (