11import React , { Suspense , useEffect , useLayoutEffect , useState } from 'react'
22import 'react-contexify/dist/ReactContexify.css'
33import 'src/assets/App.css'
4- import { Header } from 'src/components/Layout'
4+ import { DNDLayout , Header } from 'src/components/Layout'
55import { BookmarksSidebar } from 'src/features/bookmarks'
66import { MarketingBanner } from 'src/features/MarketingBanner'
77import { setupAnalytics , setupIdentification , trackPageView } from 'src/lib/analytics'
88import { useUserPreferences } from 'src/stores/preferences'
99import { diffBetweenTwoDatesInDays } from 'src/utils/DateUtils'
10- import { AppContentLayout , ScrollCardsNavigator } from './components/Layout'
10+ import { AppContentLayout } from './components/Layout'
1111import { isWebOrExtensionVersion } from './utils/Environment'
1212import { getAppVersion } from './utils/Os'
1313
1414const OnboardingModal = React . lazy ( ( ) =>
1515 import ( 'src/features/onboarding' ) . then ( ( module ) => ( { default : module . OnboardingModal } ) )
1616)
1717
18+ const intersectionCallback = ( entries ) => {
19+ entries . forEach ( ( entry ) => {
20+ if ( ! entry . isIntersecting ) {
21+ document . documentElement . classList . remove ( 'dndState' )
22+ } else {
23+ document . documentElement . classList . add ( 'dndState' )
24+ }
25+ } )
26+ }
27+
1828function App ( ) {
1929 const [ showSideBar , setShowSideBar ] = useState ( false )
2030 const [ showSettings , setShowSettings ] = useState ( false )
2131 const [ showOnboarding , setShowOnboarding ] = useState ( true )
22- const { onboardingCompleted, firstSeenDate, markOnboardingAsCompleted, maxVisibleCards } =
23- useUserPreferences ( )
32+ const {
33+ onboardingCompleted,
34+ firstSeenDate,
35+ markOnboardingAsCompleted,
36+ maxVisibleCards,
37+ isDNDModeActive,
38+ DNDDuration,
39+ setDNDDuration,
40+ } = useUserPreferences ( )
2441
2542 useLayoutEffect ( ( ) => {
2643 if ( ! onboardingCompleted && getAppVersion ( ) <= '1.15.9' ) {
@@ -32,16 +49,40 @@ function App() {
3249 // eslint-disable-next-line react-hooks/exhaustive-deps
3350 } , [ onboardingCompleted , firstSeenDate ] )
3451
35- useEffect ( ( ) => {
52+ useLayoutEffect ( ( ) => {
3653 document . documentElement . style . setProperty ( '--max-visible-cards' , maxVisibleCards )
3754 } , [ maxVisibleCards ] )
3855
3956 useEffect ( ( ) => {
57+ document . body . classList . remove ( 'preload' )
4058 setupAnalytics ( )
4159 setupIdentification ( )
42- trackPageView ( 'home' )
4360 } , [ ] )
4461
62+ useEffect ( ( ) => {
63+ trackPageView ( 'home' , isDNDModeActive ( ) )
64+ if ( ! isDNDModeActive ( ) && DNDDuration !== 'never' ) {
65+ setDNDDuration ( 'never' )
66+ }
67+ } , [ DNDDuration , isDNDModeActive , setDNDDuration ] )
68+
69+ useLayoutEffect ( ( ) => {
70+ let dndContent = document . querySelector ( '.DNDContent' )
71+ let observer = new IntersectionObserver ( intersectionCallback , {
72+ threshold : 0.1 ,
73+ } )
74+
75+ if ( dndContent ) {
76+ observer . observe ( dndContent )
77+ } else {
78+ document . documentElement . classList . remove ( 'dndState' )
79+ }
80+
81+ return ( ) => {
82+ observer . disconnect ( )
83+ }
84+ } , [ DNDDuration ] )
85+
4586 return (
4687 < >
4788 < MarketingBanner />
@@ -61,8 +102,11 @@ function App() {
61102 showSettings = { showSettings }
62103 setShowSettings = { setShowSettings }
63104 />
64- < ScrollCardsNavigator />
65- < AppContentLayout setShowSettings = { setShowSettings } />
105+
106+ < div className = "layoutLayers hideScrollBar" >
107+ { isDNDModeActive ( ) && < DNDLayout /> }
108+ < AppContentLayout setShowSettings = { setShowSettings } />
109+ </ div >
66110 < BookmarksSidebar showSidebar = { showSideBar } onClose = { ( ) => setShowSideBar ( false ) } />
67111 </ div >
68112 </ >
0 commit comments