Skip to content

Commit

Permalink
Merge pull request #6 from ShadowDraco/finishing
Browse files Browse the repository at this point in the history
fix effects for getting data
  • Loading branch information
Ethan Storm committed Jul 13, 2023
2 parents 94bc235 + 14dd393 commit 370da2d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
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);
}
}
);

0 comments on commit 370da2d

Please sign in to comment.