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 90e9e9b commit 3af68d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import { useCartStore } from './context/CartContext/CartContext';
const App = () => {
const [cookies] = useCookies(['user']);

const user = cookies.user;
const user = cookies?.user;
const userId = user?.id;
const [currentPage, setCurrentPage] = useState('');
// const { setContext } = useAppContext(); // Assuming useAppContext provides setContext
const { fetchAllCollectionsForUser, selectedCollection } =
Expand All @@ -48,7 +49,7 @@ const App = () => {

useEffect(() => {
if (user) {
fetchAllCollectionsForUser(user.id)
fetchAllCollectionsForUser()
.then(() => {
setIsLoading(false);
})
Expand All @@ -57,7 +58,7 @@ const App = () => {
setIsLoading(false);
});
}
}, [user, fetchAllCollectionsForUser, setIsLoading, selectedCollection]);
}, [userId, fetchAllCollectionsForUser, setIsLoading, selectedCollection]);
// useEffect(() => {
// if (user) {
// fetchAllDecksForUser(user?.id).catch((err) =>
Expand Down
5 changes: 5 additions & 0 deletions src/context/CollectionContext/CollectionContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const CollectionProvider = ({ children }) => {
const [openChooseCollectionDialog, setOpenChooseCollectionDialog] =
useState(false);
const userId = cookies?.user?.id;
console.log('USER ID:', userId);
const lastFetchedTime = useRef(null);

const fetchAndSetCollections = useCallback(async () => {
Expand All @@ -87,6 +88,10 @@ export const CollectionProvider = ({ children }) => {
if (!shouldFetch()) return;

try {
if (!userId) {
console.error('No user ID found.');
return;
}
lastFetchedTime.current = Date.now();
const response = await fetchWrapper(
createApiUrl(`${userId}/collections`),
Expand Down

0 comments on commit 3af68d8

Please sign in to comment.