Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add #14

Merged
merged 1 commit into from
Nov 25, 2023
Merged

add #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading