<commit_before>import { makeStyles } from "@material-ui/core/styles";
import { useSnackbar } from "notistack";
import { useEffect, useState } from "react";
import { FirebaseStore } from "../store";
import { Movie } from "../tmdb/types";
import MovieCard from "./MovieCard";

function MovieListLoading() {
  return <div>Loading...</div>;
}

function MovieListEmpty() {
  return <div>No movies added yet.</div>;
}

const useStyles = makeStyles({
  container: {
    display: "grid",
    gap: "0.5em 0.5em",
    gridAutoRows: "231px",
    gridTemplateColumns: "repeat(auto-fill, 154px)",
  },
});

export default function MovieList() {
  const classes = useStyles();
  const [movies, setMovies] = useState<Array<Movie>>([]);
  const [isLoading, setIsLoading] = useState<boolean>(true);
  const { enqueueSnackbar } = useSnackbar();
  const { db, userId } = FirebaseStore.useState((s) => ({
    db: s.firestore,
    userId: s.user!.uid,
  }));

  const removeMovie = (movieId: number) => {
    db!
      .collection("/users/" + userId + "/movies")
      .doc(movieId.toString())
      .delete()
      .then(() =>
        enqueueSnackbar("Movie was removed successfully.", {
          autoHideDuration: 3000,
          variant: "success",
        })
      )
      .catch(() =>
        enqueueSnackbar("Error occurred when removing the movie.", {
          autoHideDuration: 3000,
          variant: "error",
        })
      );
  };

  useEffect(() => {
    db!
      .collection("/users/" + userId + "/movies")
      .orderBy("title")
      .onSnapshot((querySnapshot) => {
        setIsLoading(false);
        if (!querySnapshot.empty) {
          setMovies(
            querySnapshot.docs.map((doc) => {
              return { id: parseInt(doc.id), ...doc.data() } as Movie;
            })
          );
        }
      });
  }, [db, userId]);

  if (isLoading) return <MovieListLoading />;
  if (!isLoading && movies.length === 0) return <MovieListEmpty />;
<commit_msg>fixed issue when removing the last movie in list #133<commit_after>import { makeStyles } from "@material-ui/core/styles";
import { useSnackbar } from "notistack";
import { useEffect, useState } from "react";
import { FirebaseStore } from "../store";
import { Movie } from "../tmdb/types";
import MovieCard from "./MovieCard";

function MovieListLoading() {
  return <div>Loading...</div>;
}

function MovieListEmpty() {
  return <div>No movies added yet.</div>;
}

const useStyles = makeStyles({
  container: {
    display: "grid",
    gap: "0.5em 0.5em",
    gridAutoRows: "231px",
    gridTemplateColumns: "repeat(auto-fill, 154px)",
  },
});

export default function MovieList() {
  const classes = useStyles();
  const [movies, setMovies] = useState<Array<Movie>>([]);
  const [isLoading, setIsLoading] = useState<boolean>(true);
  const { enqueueSnackbar } = useSnackbar();
  const { db, userId } = FirebaseStore.useState((s) => ({
    db: s.firestore,
    userId: s.user!.uid,
  }));

  const removeMovie = (movieId: number) => {
    db!
      .collection("/users/" + userId + "/movies")
      .doc(movieId.toString())
      .delete()
      .then(() =>
        enqueueSnackbar("Movie was removed successfully.", {
          autoHideDuration: 3000,
          variant: "success",
        })
      )
      .catch(() =>
        enqueueSnackbar("Error occurred when removing the movie.", {
          autoHideDuration: 3000,
          variant: "error",
        })
      );
  };

  useEffect(() => {
    db!
      .collection("/users/" + userId + "/movies")
      .orderBy("title")
      .onSnapshot((querySnapshot) => {
        setIsLoading(false);
        setMovies(
          querySnapshot.docs.map((doc) => {
            return { id: parseInt(doc.id), ...doc.data() } as Movie;
          })
        );
      });
  }, [db, userId]);

  if (isLoading) return <MovieListLoading />;
  if (!isLoading && movies.length === 0) return <MovieListEmpty />;

{'fraction_non_alphanumeric': 0.16726251276813076, 'fraction_numerical': 0.010469867211440245, 'mean_word_length': 2.664172123479888, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 35, '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': '3859805', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1215, 'n_words': 279}