({
children,
hasMessage,
examInProgress,
fetchState,
flashMessage,
isOnline,
isServerOnline,
isSignedIn,
removeFlashMessage,
showFooter = true,
isChallenge = false,
isDailyChallenge = false,
dailyChallengeParam,
usesMultifileEditor,
block,
superBlock,
theme,
user,
pathname,
fetchUser,
initializeTheme
}: DefaultLayoutProps)
| 122 | } |
| 123 | |
| 124 | function DefaultLayout({ |
| 125 | children, |
| 126 | hasMessage, |
| 127 | examInProgress, |
| 128 | fetchState, |
| 129 | flashMessage, |
| 130 | isOnline, |
| 131 | isServerOnline, |
| 132 | isSignedIn, |
| 133 | removeFlashMessage, |
| 134 | showFooter = true, |
| 135 | isChallenge = false, |
| 136 | isDailyChallenge = false, |
| 137 | dailyChallengeParam, |
| 138 | usesMultifileEditor, |
| 139 | block, |
| 140 | superBlock, |
| 141 | theme, |
| 142 | user, |
| 143 | pathname, |
| 144 | fetchUser, |
| 145 | initializeTheme |
| 146 | }: DefaultLayoutProps): JSX.Element { |
| 147 | const { t } = useTranslation(); |
| 148 | const isMobileLayout = useMediaQuery({ maxWidth: MAX_MOBILE_WIDTH }); |
| 149 | const isProject = /project$/.test(block as string); |
| 150 | const isRenderBreadcrumbOnMobile = |
| 151 | isMobileLayout && (isProject || !usesMultifileEditor); |
| 152 | const isRenderBreadcrumb = !isMobileLayout || isRenderBreadcrumbOnMobile; |
| 153 | const isExSmallViewportHeight = useMediaQuery({ |
| 154 | maxHeight: EX_SMALL_VIEWPORT_HEIGHT |
| 155 | }); |
| 156 | |
| 157 | useEffect(() => { |
| 158 | initializeTheme(); |
| 159 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 160 | }, []); |
| 161 | |
| 162 | useEffect(() => { |
| 163 | // componentDidMount |
| 164 | if (!isSignedIn) { |
| 165 | fetchUser(); |
| 166 | } |
| 167 | window.addEventListener('online', updateOnlineStatus); |
| 168 | window.addEventListener('offline', updateOnlineStatus); |
| 169 | |
| 170 | return () => { |
| 171 | // componentWillUnmount. |
| 172 | window.removeEventListener('online', updateOnlineStatus); |
| 173 | window.removeEventListener('offline', updateOnlineStatus); |
| 174 | }; |
| 175 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 176 | }, []); |
| 177 | |
| 178 | const updateOnlineStatus = () => { |
| 179 | const isOnline = |
| 180 | isBrowser() && 'navigator' in window ? window.navigator.onLine : null; |
| 181 | return typeof isOnline === 'boolean' ? onlineStatusChange(isOnline) : null; |
nothing calls this directly
no test coverage detected