<commit_before>import React, { useEffect, Fragment } from 'react';
import firebase from 'firebase/app';
import 'firebase/database';
import ReactGA from 'react-ga';
import { CssBaseline, Grid, LinearProgress } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import Header from './Header';
import MovieCard from './MovieCard';
import { GetState } from './AppState';

const useStyles = makeStyles(theme => ({
  root: {
    marginTop: theme.spacing(8),
    padding: theme.spacing(3)
  },
  movieItem: {
    marginBottom: theme.spacing(3)
  }
}));

const MovieUI = () => {
  const classes = useStyles();
  const [{ movieDetails, movieListings, selectedDate }, dispatch] = GetState();

  useEffect(() => {
    const fetchData = async () => {
      const config = {
        apiKey: 'AIzaSyC_Bv5Apio1PBrO048figZ6i3B_nkccoMw',
        authDomain: 'movies-387bf.firebaseapp.com',
        databaseURL: 'https://movies-387bf.firebaseio.com',
        projectId: 'movies-387bf',
        storageBucket: 'movies-387bf.appspot.com',
        messagingSenderId: '208320671675'
      };
      firebase.initializeApp(config);
      const database = firebase.database();
      const dataSnapshot = await database.ref('/').once('value');
      const firebaseMovieData = dataSnapshot.val();

      dispatch({
        type: 'setMovieListings',
        movieListings: firebaseMovieData['movie-theatres'].chiangmai['9936']
      });

      dispatch({
        type: 'setMovieDetails',
        movieDetails: firebaseMovieData['movie-details']
      });

      dispatch({
        type: 'setSelectedDate',
        newDate: Object.keys(
          firebaseMovieData['movie-theatres'].chiangmai['9936']
        )[0]
      });
    };

    // track app views with Google Analytics
    ReactGA.initialize('UA-63340534-3');
    ReactGA.pageview(window.location.pathname);

    fetchData();
  }, [dispatch]);

  let content;

  if (movieListings && selectedDate) {
    // sort the movies by Rotten Tomatoes score
    const moviesForSelectedDate = Object.keys(movieListings[selectedDate]);
    moviesForSelectedDate.sort((movieTitle1, movieTitle2) =>
      movieDetails[movieTitle1].meterScore <
      movieDetails[movieTitle2].meterScore
        ? 1
        : -1
    );
    content = moviesForSelectedDate.map(movieTitle => (
      <Grid
        item
        xs={12}
        sm={6}
        md={4}
        className={classes.movieItem}
        key={movieTitle}
      >
        <MovieCard
          movieData={movieDetails[movieTitle]}
          showTimes={movieListings[selectedDate][movieTitle]}
        />
      </Grid>
    ));
  } else {
    content = (
      <Grid item xs={8} sm={4}>
        <LinearProgress />
      </Grid>
    );
  }

  // scroll to top of screen before rendering movie data
  window.scrollTo(0, 0);

  return (
    <Fragment>
      <CssBaseline />
      <Header movieTimes={movieListings} />
      <div className={classes.root}>
        <Grid container justify="center">
          {content}
        </Grid>
      </div>
    </Fragment>
  );
};

export default MovieUI;
<commit_msg>adding check if any movie data is available<commit_after>import React, { useEffect, Fragment, useState } from 'react';
import firebase from 'firebase/app';
import 'firebase/database';
import ReactGA from 'react-ga';
import { CssBaseline, Grid, LinearProgress } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import Header from './Header';
import MovieCard from './MovieCard';
import { GetState } from './AppState';

const useStyles = makeStyles(theme => ({
  root: {
    marginTop: theme.spacing(8),
    padding: theme.spacing(3)
  },
  movieItem: {
    marginBottom: theme.spacing(3)
  }
}));

const MovieUI = () => {
  const classes = useStyles();
  const [error, setError] = useState();
  const [{ movieDetails, movieListings, selectedDate }, dispatch] = GetState();

  useEffect(() => {
    const fetchData = async () => {
      const config = {
        apiKey: 'AIzaSyC_Bv5Apio1PBrO048figZ6i3B_nkccoMw',
        authDomain: 'movies-387bf.firebaseapp.com',
        databaseURL: 'https://movies-387bf.firebaseio.com',
        projectId: 'movies-387bf',
        storageBucket: 'movies-387bf.appspot.com',
        messagingSenderId: '208320671675'
      };
      firebase.initializeApp(config);
      const database = firebase.database();
      const dataSnapshot = await database.ref('/').once('value');
      const firebaseMovieData = dataSnapshot.val();

      if (!firebaseMovieData) {
        setError(
          "I'm sorry, but it doesn't look like any movie data is available at present."
        );
        return;
      }

      dispatch({
        type: 'setMovieListings',
        movieListings: firebaseMovieData['movie-theatres'].chiangmai['9936']
      });

      dispatch({
        type: 'setMovieDetails',
        movieDetails: firebaseMovieData['movie-details']
      });

      dispatch({
        type: 'setSelectedDate',
        newDate: Object.keys(
          firebaseMovieData['movie-theatres'].chiangmai['9936']
        )[0]
      });
    };

    // track app views with Google Analytics
    ReactGA.initialize('UA-63340534-3');
    ReactGA.pageview(window.location.pathname);

    fetchData();
  }, [dispatch]);

  if (error) {
    throw new Error(error);
  }

  let content;

  if (movieListings && selectedDate) {
    // sort the movies by Rotten Tomatoes score
    const moviesForSelectedDate = Object.keys(movieListings[selectedDate]);
    moviesForSelectedDate.sort((movieTitle1, movieTitle2) =>
      movieDetails[movieTitle1].meterScore <
      movieDetails[movieTitle2].meterScore
        ? 1
        : -1
    );
    content = moviesForSelectedDate.map(movieTitle => (
      <Grid
        item
        xs={12}
        sm={6}
        md={4}
        className={classes.movieItem}
        key={movieTitle}
      >
        <MovieCard
          movieData={movieDetails[movieTitle]}
          showTimes={movieListings[selectedDate][movieTitle]}
        />
      </Grid>
    ));
  } else {
    content = (
      <Grid item xs={8} sm={4}>
        <LinearProgress />
      </Grid>
    );
  }

  // scroll to top of screen before rendering movie data
  window.scrollTo(0, 0);

  return (
    <Fragment>
      <CssBaseline />
      <Header movieTimes={movieListings} />
      <div className={classes.root}>
        <Grid container justify="center">
          {content}
        </Grid>
      </div>
    </Fragment>
  );
};

export default MovieUI;

{'fraction_non_alphanumeric': 0.13415384615384615, 'fraction_numerical': 0.020307692307692308, 'mean_word_length': 2.6749576031656304, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 43, 'https://': 2, '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': '1069325', 'n_tokens_mistral': 2095, 'n_tokens_neox': 1951, 'n_words': 407}