Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
reedoooo committed Nov 25, 2023
1 parent 920b840 commit 4ce1e93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { useDeckStore } from './context/DeckContext/DeckContext';
import { useCartStore } from './context/CartContext/CartContext';
import LoginDialog from './components/dialogs/LoginDialog';
const App = () => {
// const { getRandomCardImages } = useCardImages(); // Add this line
// const [cookies] = useCookies(['user']);

// const user = cookies?.user;
Expand All @@ -47,22 +48,20 @@ const App = () => {
const { allDecks, fetchAllDecksForUser, selectedDeck } = useDeckStore();
const { fetchUserCart, cartData } = useCartStore();
const { isLoading, setIsLoading } = useUtilityContext();
// Callback function when login is successful
const handleLoginSuccess = (isLoggedIn, userId) => {
// Close the dialog and perform other actions if needed
setShowLoginDialog(false);
console.log('isLoggedIn', isLoggedIn);
console.log('userId', userId);
// ... any other logic post-login
};
// const { getRandomCardImages } = useCardImages(); // Add this line

// useEffect(() => {
// getRandomCardImages(10); // Fetch 10 random images on app start
// }, []); // Add this useEffect
useEffect(() => {
// Open the login dialog if there's no userId
if (!userId) {
setIsLoading(false);
setShowLoginDialog(true);
} else {
setShowLoginDialog(false);
Expand All @@ -82,6 +81,10 @@ const App = () => {
}
}, [userId, fetchAllCollectionsForUser, setIsLoading, selectedCollection]);
// useEffect(() => {
// console.log('Checking userId in useEffect:', userId);
// setShowLoginDialog(!userId);
// }, [userId]);
// useEffect(() => {
// if (user) {
// fetchAllDecksForUser(user?.id).catch((err) =>
// console.error('Failed to get all decks:', err)
Expand Down Expand Up @@ -121,6 +124,10 @@ const App = () => {
<SplashPage />
) : (
<React.Fragment>
{console.log(
'Login Dialog should be:',
showLoginDialog ? 'Open' : 'Closed'
)}
<LoginDialog
open={showLoginDialog}
onClose={() => setShowLoginDialog(false)}
Expand Down
5 changes: 4 additions & 1 deletion src/components/dialogs/LoginDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ function LoginDialog({ open, onClose, onLogin }) {
const [name, setName] = useState('');
const [roleData, setRoleData] = useState('admin'); // Adjusted to handle string value
const { toggleColorMode, mode } = useMode();
const [cookies, setCookie, removeCookie] = useCookies(['isLoggedIn']);
const [cookies, setCookie, removeCookie] = useCookies([
'isLoggedIn',
'userId',
]);
const setLoginState = (isLoggedIn, userId) => {
const expires = new Date();
expires.setMinutes(expires.getMinutes() + 45);
Expand Down

0 comments on commit 4ce1e93

Please sign in to comment.