From 7c2dcb37cd019a3be87af951a3e65d0abbe35aae Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 20 Jun 2023 11:44:58 +0300 Subject: [PATCH] feat(ProjectListItemCollapsible): support project loading status --- .../ProjectListItem/ProjectListItem.tsx | 22 +++++++++++++++-- src/components/ProjectPage/ProjectPage.tsx | 24 +++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/components/ProjectListItem/ProjectListItem.tsx b/src/components/ProjectListItem/ProjectListItem.tsx index 1c31cbed8..51a70db1b 100644 --- a/src/components/ProjectListItem/ProjectListItem.tsx +++ b/src/components/ProjectListItem/ProjectListItem.tsx @@ -1,4 +1,14 @@ -import React, { Children, FC, MouseEvent, MouseEventHandler, ReactNode, useCallback, useMemo, useState } from 'react'; +import React, { + Children, + FC, + MouseEvent, + MouseEventHandler, + ReactNode, + useCallback, + useEffect, + useMemo, + useState, +} from 'react'; import styled from 'styled-components'; import Link from 'next/link'; import { Badge, Button, EyeIcon, StarFilledIcon, Text, nullable } from '@taskany/bricks'; @@ -38,6 +48,8 @@ interface ProjectListItemCollapsableProps { project: NonNullable; goals?: NonNullable[]; children?: (id: string[], deep?: number) => ReactNode; + onCollapsedChange?: (value: boolean) => void; + loading?: boolean; onTagClick?: React.ComponentProps['onTagClick']; onClickProvider?: (g: NonNullable) => MouseEventHandler; selectedResolver?: (id: string) => boolean; @@ -98,7 +110,9 @@ export const ProjectListItemCollapsable: React.FC { @@ -118,6 +132,10 @@ export const ProjectListItemCollapsable: React.FC { + onCollapsedChange?.(collapsed); + }, [collapsed, onCollapsedChange]); + const onHeaderButtonClick = useCallback((e: MouseEvent) => { e.stopPropagation(); @@ -126,7 +144,7 @@ export const ProjectListItemCollapsable: React.FC diff --git a/src/components/ProjectPage/ProjectPage.tsx b/src/components/ProjectPage/ProjectPage.tsx index be0e9235f..3cc1a6e89 100644 --- a/src/components/ProjectPage/ProjectPage.tsx +++ b/src/components/ProjectPage/ProjectPage.tsx @@ -36,7 +36,6 @@ const PageProjectListItem: FC< } > = ({ queryState, id, ...props }) => { const project = trpc.project.getById.useQuery(id); - const { data: projectDeepInfo } = trpc.project.getDeepInfo.useQuery( { id, @@ -48,12 +47,33 @@ const PageProjectListItem: FC< }, ); + const [fetchChildEnabled, setFetchChildEnabled] = useState(false); + + const childrenQueries = trpc.useQueries((t) => + (project.data?.children.map(({ id }) => id) || []).map((id) => + t.project.getById(id, { enabled: fetchChildEnabled, refetchOnWindowFocus: false }), + ), + ); + + const loading = useMemo(() => childrenQueries.some(({ isLoading }) => isLoading), [childrenQueries]); + + console.log('QQQ QUERIES', id, childrenQueries); const goals = useMemo(() => projectDeepInfo?.goals.filter((g) => g.projectId === id), [projectDeepInfo, id]); + const onCollapsedChange = useCallback((value: boolean) => { + setFetchChildEnabled(!value); + }, []); + if (!project.data) return null; return ( - + {(ids, deep) => ids.map((id) => ) }