Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusef Almamari committed Aug 4, 2024
1 parent c13b950 commit c26a470
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .env.development

This file was deleted.

2 changes: 0 additions & 2 deletions .env.production

This file was deleted.

14 changes: 1 addition & 13 deletions src/pages/home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as citationEngine from "../../utils/citationEngine";
import { addNewBib } from "../../data/store/slices/bibsSlice";
import { useAuth } from "../../context/AuthContext";
import { CoBibsSearchDialog } from "./HomeTools";
import { useModal } from "../../context/ModalContext.tsx";
import { useEnhancedDispatch } from "../../hooks/hooks.tsx";
import { ChipSet, Fab, Icon, List, TopBar } from "../../components/ui/MaterialComponents";
import { timeAgo } from "../../utils/utils.ts";
Expand All @@ -21,7 +20,6 @@ export default function Home() {
const { currentUser } = useAuth();
const navigate = useNavigate();
const dispatch = useEnhancedDispatch();
const modal = useModal();

useEffect(() => {
if (tryingToJoinBib) {
Expand All @@ -36,17 +34,7 @@ export default function Home() {
}

function openCoBibsSearchDialog() {
if (currentUser) setCoBibsSearchDialogVisible(true);
else {
modal.open({
title: "Login required",
message: "You need to log in first to use this feature.",
actions: [
["Log in", () => navigate("/login"), { autoFocus: true }],
["Cancel", () => modal.close()],
],
});
}
setCoBibsSearchDialogVisible(true);
}

const sortedBibliographies = Array.from(bibliographies).sort((a, b) => {
Expand Down
29 changes: 28 additions & 1 deletion src/pages/home/HomeTools.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import db from "../../data/db/firebase/firebase";
import { useAuth } from "../../context/AuthContext";
import { mergeWithCurrentBibs } from "../../data/store/slices/bibsSlice";
import { useToast } from "../../context/ToastContext.tsx";
import { useModal } from "../../context/ModalContext.tsx";

export function CoBibsSearchDialog({ setIsVisible, tryingToJoinBib }) {
const [searchResult, setSearchResult] = useState(null);
Expand All @@ -21,6 +22,30 @@ export function CoBibsSearchDialog({ setIsVisible, tryingToJoinBib }) {
const dispatch = useDispatch();
const toast = useToast();
const navigate = useNavigate();
const modal = useModal();

useEffect(() => {
if (!currentUser) {
modal.open({
showCloseIcon: false,
title: "Login required",
message: "You need to log in first to use this feature.",
actions: [
["Log in", () => navigate("/login"), { autoFocus: true }],
[
"Cancel",
() => {
setIsVisible(false);
modal.close();
},
],
],
});

return undefined;
}
return undefined;
}, []);

async function searchForBib(bibId) {
setSearchError(null);
Expand All @@ -41,7 +66,9 @@ export function CoBibsSearchDialog({ setIsVisible, tryingToJoinBib }) {
}

useEffect(() => {
searchForBib(tryingToJoinBib);
if (tryingToJoinBib) {
searchForBib(tryingToJoinBib);
}
}, [tryingToJoinBib]);

async function handleSearch(event) {
Expand Down

0 comments on commit c26a470

Please sign in to comment.