<commit_before>import {Box, Flex} from '@chakra-ui/core'
import dynamic from 'next/dynamic'
import React from 'react'

import Sidebar from '../components/sidebar'
import useRouteChanging from '../hooks/use-route-changing'
import withAuth from '../with-auth'
import withRedux from '../with-redux'

// Cannot be rendered server side
const LeafletContext = dynamic(() => import('../components/map/context'), {
  ssr: false
})
const Map = dynamic(() => import('../components/map'), {ssr: false})

// Created to prevent prop drilling `setMapChildren`
export const MapChildrenContext = React.createContext(() => {})

/**
 * Components are rendered this way so that the map does not get unmounted
 * and remounted on each page change. There is probably a better way to do this
 * but I have not figured out a better solution yet.
 */
export default withAuth(
  withRedux(function MapLayout(p) {
    const [routeChanging] = useRouteChanging()
    const [mapChildren, setMapChildren] = React.useState()
    const [leafletContext, setLeafletContext] = React.useState()

    return (
      <Flex pointerEvents={routeChanging ? 'none' : 'inherit'}>
        <style jsx global>{`
          body {
            height: 100vh;
            overflow: hidden;
            width: 100vw;
          }
        `}</style>
        <Sidebar />
        <Box
          borderRight='1px solid #ddd'
          bg='#fff'
          opacity={routeChanging ? 0.4 : 1}
          minWidth='321px'
        >
          <LeafletContext value={leafletContext}>
            <MapChildrenContext.Provider value={setMapChildren}>
              {p.children}
            </MapChildrenContext.Provider>
          </LeafletContext>
        </Box>
        <Box flexGrow='1' opacity={routeChanging ? 0.4 : 1} position='relative'>
          <Map setLeafletContext={setLeafletContext}>{mapChildren}</Map>
        </Box><commit_msg>Ensure map is loaded before rendering main content<commit_after>import {Box, Flex} from '@chakra-ui/core'
import dynamic from 'next/dynamic'
import React from 'react'

import FullSpinner from 'lib/components/full-spinner'
import Sidebar from 'lib/components/sidebar'
import useRouteChanging from 'lib/hooks/use-route-changing'
import withAuth from 'lib/with-auth'
import withRedux from 'lib/with-redux'

// Cannot be rendered server side
const LeafletContext = dynamic(() => import('lib/components/map/context'), {
  ssr: false
})
const Map = dynamic(() => import('lib/components/map'), {ssr: false})

// Created to prevent prop drilling `setMapChildren`
export const MapChildrenContext = React.createContext(() => {})

/**
 * Components are rendered this way so that the map does not get unmounted
 * and remounted on each page change. There is probably a better way to do this
 * but I have not figured out a better solution yet.
 */
export default withAuth(
  withRedux(function MapLayout(p) {
    const [routeChanging] = useRouteChanging()
    const [mapChildren, setMapChildren] = React.useState()
    const [leafletContext, setLeafletContext] = React.useState(null)

    return (
      <Flex pointerEvents={routeChanging ? 'none' : 'inherit'}>
        <style jsx global>{`
          body {
            height: 100vh;
            overflow: hidden;
            width: 100vw;
          }
        `}</style>
        <Sidebar />
        <Box
          borderRight='1px solid #ddd'
          bg='#fff'
          opacity={routeChanging ? 0.4 : 1}
          minWidth='321px'
        >
          {leafletContext ? (
            <LeafletContext value={leafletContext}>
              <MapChildrenContext.Provider value={setMapChildren}>
                {p.children}
              </MapChildrenContext.Provider>
            </LeafletContext>
          ) : (
            <FullSpinner />
          )}
        </Box>
        <Box flexGrow='1' opacity={routeChanging ? 0.4 : 1} position='relative'>
          <Map setLeafletContext={setLeafletContext}>{mapChildren}</Map>
        </Box>
{'fraction_non_alphanumeric': 0.11886697015680324, 'fraction_numerical': 0.008598887202832575, 'mean_word_length': 2.720602069614299, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1731916', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1111, 'n_words': 320}