import { useGlobal } from "reactn";
import firebase from "../config/firebase";
import useDataFromRef from "./useDataFromRef";

export default function useUserLikedProjects() {
  const [currentUID] = useGlobal("currentUID");

  const { data, loading } = useDataFromRef({
    ref:
      currentUID
        ? firebase
            .firestore()
            .collection("projects")
            .where("likedBy", "array-contains", currentUID)
        : null,
    simpleRef: false,
    listener: true,
    condition: !!currentUID,
    refreshArray: [currentUID],
  });

  return { projects: Array.isArray(data) ? data : [], loading };
}

