forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User & Metadata Loading (twentyhq#5347)
### Description User & Metadata Loading ### Refs twentyhq#4456 ### Demo https://github.com/twentyhq/twenty/assets/140154534/4c20fca6-feaf-45f6-ac50-6532d2ebf050 Fixes twentyhq#4456 --------- Co-authored-by: gitstart-twenty <[email protected]> Co-authored-by: v1b3m <[email protected]> Co-authored-by: Thiago Nascimbeni <[email protected]> Co-authored-by: Charles Bochet <[email protected]>
- Loading branch information
1 parent
74d7479
commit 10abd7f
Showing
7 changed files
with
249 additions
and
2 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
packages/twenty-front/src/loading/components/LeftPanelSkeletonLoader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
34 changes: 34 additions & 0 deletions
34
packages/twenty-front/src/loading/components/MainNavigationDrawerItemsSkeletonLoader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
92 changes: 92 additions & 0 deletions
92
packages/twenty-front/src/loading/components/RightPanelSkeletonLoader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); |
32 changes: 32 additions & 0 deletions
32
packages/twenty-front/src/loading/components/UserOrMetadataLoader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/twenty-front/src/loading/hooks/useUserOrMetadataLoading.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters