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

fix effects for getting data #6

Merged
merged 1 commit into from
Jul 13, 2023
Merged
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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_UNSPLASH_URL = https://source.unsplash.com/random?
VITE_API_URL = https://api-js401.herokuapp.com/api/v1
3 changes: 1 addition & 2 deletions src/components/ActiveProduct/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export default function ActiveProduct({ product }) {
const params = useParams();

useEffect(() => {
if (typeof product === undefined) {
console.log('\n\nNO TEST ACTIVE PRODUCT ', product);
if (typeof product !== undefined) {
try {
dispatch(setCurrentProduct()).then(data =>
dispatch(
Expand Down
3 changes: 1 addition & 2 deletions src/components/Categories/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export default function Categories({ testCategories }) {
const dispatch = useDispatch();

useEffect(() => {
if (typeof testCategories === undefined) {
console.log('\n\nNO TEST CATEGORY ', testCategories);
if (typeof testCategories !== undefined) {
try {
dispatch(fetchCategories()).then(data => {
dispatch(updateCategories(data));
Expand Down
2 changes: 1 addition & 1 deletion src/components/Products/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { addToCart } from '../../redux/reducers/cart';

export default function Products({ testCategories, testProducts }) {
useEffect(() => {
if (typeof testProducts === undefined) {
if (typeof testProducts !== undefined) {
try {
dispatch(fetchProducts()).then(data => dispatch(getProducts(data)));
} catch (error) {
Expand Down
12 changes: 6 additions & 6 deletions src/redux/reducers/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export const fetchCategories = createAsyncThunk(
'updateCategories',
async () => {
try {
const response = await axios.get(
`${import.meta.env.VITE_API_URL}/categories`
);
return response.data;
} catch(error) {
console.error('Error fetching Categories', error)
const response = await axios.get(
`${import.meta.env.VITE_API_URL}/categories`
);
return response.data;
} catch (error) {
console.error('Error fetching Categories', error);
}
}
);