Skip to content

User & Metadata Loading #5347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton';
import styled from '@emotion/styled';
import { motion } from 'framer-motion';
import { ANIMATION, BACKGROUND_LIGHT, GRAY_SCALE } from 'twenty-ui';

import { DESKTOP_NAV_DRAWER_WIDTHS } from '@/ui/navigation/navigation-drawer/constants/DesktopNavDrawerWidths';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import { MainNavigationDrawerItemsSkeletonLoader } from '~/loading/components/MainNavigationDrawerItemsSkeletonLoader';

const StyledAnimatedContainer = styled(motion.div)`
display: flex;
justify-content: end;
`;

const StyledItemsContainer = styled.div`
display: flex;
flex-direction: column;
gap: 32px;
margin-bottom: auto;
overflow-y: auto;
height: calc(100vh - 32px);
min-width: 216px;
max-width: 216px;
`;

const StyledSkeletonContainer = styled.div`
display: flex;
flex-direction: column;
gap: 32px;
`;

const StyledSkeletonTitleContainer = styled.div`
display: flex;
flex-direction: column;
gap: 6px;
margin-left: 12px;
margin-top: 8px;
`;

export const LeftPanelSkeletonLoader = () => {
const isMobile = useIsMobile();
const mobileWidth = isMobile ? 0 : '100%';
const desktopWidth = !mobileWidth ? 12 : DESKTOP_NAV_DRAWER_WIDTHS.menu;

return (
<StyledAnimatedContainer
initial={false}
animate={{
width: isMobile ? mobileWidth : desktopWidth,
opacity: isMobile ? 0 : 1,
}}
transition={{
duration: ANIMATION.duration.fast,
}}
>
<StyledItemsContainer>
<StyledSkeletonContainer>
<StyledSkeletonTitleContainer>
<SkeletonTheme
baseColor={GRAY_SCALE.gray15}
highlightColor={BACKGROUND_LIGHT.transparent.lighter}
borderRadius={4}
>
<Skeleton width={96} height={16} />
</SkeletonTheme>
</StyledSkeletonTitleContainer>
<MainNavigationDrawerItemsSkeletonLoader length={4} />
<MainNavigationDrawerItemsSkeletonLoader title length={2} />
<MainNavigationDrawerItemsSkeletonLoader title length={3} />
</StyledSkeletonContainer>
</StyledItemsContainer>
</StyledAnimatedContainer>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton';
import styled from '@emotion/styled';
import { BACKGROUND_LIGHT, GRAY_SCALE } from 'twenty-ui';

const StyledSkeletonContainer = styled.div`
display: flex;
flex-direction: column;
gap: 6px;
margin-left: 12px;
margin-top: 8px;
`;

export const MainNavigationDrawerItemsSkeletonLoader = ({
title,
length,
}: {
title?: boolean;
length: number;
}) => {
return (
<StyledSkeletonContainer>
<SkeletonTheme
baseColor={GRAY_SCALE.gray15}
highlightColor={BACKGROUND_LIGHT.transparent.lighter}
borderRadius={4}
>
{title && <Skeleton width={48} height={13} />}
{Array.from({ length }).map((_, index) => (
<Skeleton key={index} width={196} height={16} />
))}
</SkeletonTheme>
</StyledSkeletonContainer>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton';
import styled from '@emotion/styled';
import {
BACKGROUND_LIGHT,
BORDER_COMMON,
BORDER_LIGHT,
GRAY_SCALE,
MOBILE_VIEWPORT,
} from 'twenty-ui';

const StyledMainContainer = styled.div`
background: ${BACKGROUND_LIGHT.noisy};
box-sizing: border-box;
display: flex;
flex: 1 1 auto;
flex-direction: row;
gap: 8px;
min-height: 0;
padding-left: 0;
width: 100%;

@media (max-width: ${MOBILE_VIEWPORT}px) {
padding-left: 12px;
padding-bottom: 0;
}
`;

const StyledPanel = styled.div`
background: ${BACKGROUND_LIGHT.primary};
border: 1px solid ${BORDER_LIGHT.color.medium};
border-radius: ${BORDER_COMMON.radius.md};
height: 100%;
overflow: auto;
width: 100%;
`;

const StyledHeaderContainer = styled.div`
flex: 1;
`;
const StyledRightPanelContainer = styled.div`
display: flex;
flex-direction: column;
width: 100%;
`;

const StyledRightPanelFlexContainer = styled.div`
display: flex;
margin-top: 12px;
margin-bottom: 14px;
`;

const StyledSkeletonHeaderLoader = () => {
return (
<StyledHeaderContainer>
<SkeletonTheme
baseColor={GRAY_SCALE.gray15}
highlightColor={BACKGROUND_LIGHT.transparent.lighter}
borderRadius={4}
>
<Skeleton height={16} width={104} />
</SkeletonTheme>
</StyledHeaderContainer>
);
};

const StyledSkeletonAddLoader = () => {
return (
<SkeletonTheme
baseColor={GRAY_SCALE.gray15}
highlightColor={BACKGROUND_LIGHT.transparent.lighter}
borderRadius={4}
>
<Skeleton width={132} height={16} />
</SkeletonTheme>
);
};

const RightPanelSkeleton = () => (
<StyledMainContainer>
<StyledPanel></StyledPanel>
</StyledMainContainer>
);

export const RightPanelSkeletonLoader = () => (
<StyledRightPanelContainer>
<StyledRightPanelFlexContainer>
<StyledSkeletonHeaderLoader />
<StyledSkeletonAddLoader />
</StyledRightPanelFlexContainer>
<RightPanelSkeleton />
</StyledRightPanelContainer>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import styled from '@emotion/styled';
import { BACKGROUND_LIGHT, MOBILE_VIEWPORT } from 'twenty-ui';

import { DESKTOP_NAV_DRAWER_WIDTHS } from '@/ui/navigation/navigation-drawer/constants/DesktopNavDrawerWidths';
import { LeftPanelSkeletonLoader } from '~/loading/components/LeftPanelSkeletonLoader';
import { RightPanelSkeletonLoader } from '~/loading/components/RightPanelSkeletonLoader';

const StyledContainer = styled.div`
background: ${BACKGROUND_LIGHT.noisy};
box-sizing: border-box;
display: flex;
flex-direction: row;
gap: 12px;
height: 100vh;
min-width: ${DESKTOP_NAV_DRAWER_WIDTHS.menu}px;
width: 100%;
padding: 12px 8px 12px;
overflow: hidden;

@media (max-width: ${MOBILE_VIEWPORT}px) {
width: 100%;
}
`;

export const UserOrMetadataLoader = () => {
return (
<StyledContainer>
<LeftPanelSkeletonLoader />
<RightPanelSkeletonLoader />
</StyledContainer>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useRecoilValue } from 'recoil';

import { isCurrentUserLoadedState } from '@/auth/states/isCurrentUserLoadingState';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';

export const useUserOrMetadataLoading = () => {
const isCurrentUserLoaded = useRecoilValue(isCurrentUserLoadedState);
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);

return !isCurrentUserLoaded || objectMetadataItems.length === 0;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useRecoilValue } from 'recoil';
import { ObjectMetadataItemsLoadEffect } from '@/object-metadata/components/ObjectMetadataItemsLoadEffect';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { RelationPickerScope } from '@/object-record/relation-picker/scopes/RelationPickerScope';
import { UserOrMetadataLoader } from '~/loading/components/UserOrMetadataLoader';

export const ObjectMetadataItemsProvider = ({
children,
Expand All @@ -15,10 +16,12 @@ export const ObjectMetadataItemsProvider = ({
return (
<>
<ObjectMetadataItemsLoadEffect />
{shouldDisplayChildren && (
{shouldDisplayChildren ? (
<RelationPickerScope relationPickerScopeId="relation-picker">
{children}
</RelationPickerScope>
) : (
<UserOrMetadataLoader />
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import React from 'react';
import { useRecoilValue } from 'recoil';

import { isCurrentUserLoadedState } from '@/auth/states/isCurrentUserLoadingState';
import { UserOrMetadataLoader } from '~/loading/components/UserOrMetadataLoader';

export const UserProvider = ({ children }: React.PropsWithChildren) => {
const isCurrentUserLoaded = useRecoilValue(isCurrentUserLoadedState);

return !isCurrentUserLoaded ? <></> : <>{children}</>;
return !isCurrentUserLoaded ? <UserOrMetadataLoader /> : <>{children}</>;
};
Loading