Added checking on Like Component if the request is valid
This commit is contained in:
parent
cc557f7898
commit
4babb19614
3 changed files with 17 additions and 12 deletions
|
|
@ -43,7 +43,6 @@ export function StoreProvider({ children }) {
|
||||||
setLoadingApiKey(true);
|
setLoadingApiKey(true);
|
||||||
try {
|
try {
|
||||||
const res = await checkHasApiKey();
|
const res = await checkHasApiKey();
|
||||||
console.log(res);
|
|
||||||
setHasApiKey(res?.has_api_key ?? false);
|
setHasApiKey(res?.has_api_key ?? false);
|
||||||
setValidApiKey(res?.is_valid ?? false);
|
setValidApiKey(res?.is_valid ?? false);
|
||||||
setLoadingApiKey(false);
|
setLoadingApiKey(false);
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import {
|
||||||
} from "../../../components/ui/card";
|
} from "../../../components/ui/card";
|
||||||
import { alertContext } from "../../../contexts/alertContext";
|
import { alertContext } from "../../../contexts/alertContext";
|
||||||
import { FlowsContext } from "../../../contexts/flowsContext";
|
import { FlowsContext } from "../../../contexts/flowsContext";
|
||||||
|
import { StoreContext } from "../../../contexts/storeContext";
|
||||||
import { getComponent, postLikeComponent } from "../../../controllers/API";
|
import { getComponent, postLikeComponent } from "../../../controllers/API";
|
||||||
import { storeComponent } from "../../../types/store";
|
import { storeComponent } from "../../../types/store";
|
||||||
import cloneFLowWithParent from "../../../utils/storeUtils";
|
import cloneFLowWithParent from "../../../utils/storeUtils";
|
||||||
|
|
@ -32,6 +33,7 @@ export const MarketCardComponent = ({
|
||||||
const { addFlow } = useContext(FlowsContext);
|
const { addFlow } = useContext(FlowsContext);
|
||||||
const [loadingLike, setLoadingLike] = useState(false);
|
const [loadingLike, setLoadingLike] = useState(false);
|
||||||
const { setSuccessData, setErrorData } = useContext(alertContext);
|
const { setSuccessData, setErrorData } = useContext(alertContext);
|
||||||
|
const { setValidApiKey } = useContext(StoreContext);
|
||||||
const [liked_by_user, setLiked_by_user] = useState(data.liked_by_user);
|
const [liked_by_user, setLiked_by_user] = useState(data.liked_by_user);
|
||||||
const [likes_count, setLikes_count] = useState(data.liked_by_count ?? 0);
|
const [likes_count, setLikes_count] = useState(data.liked_by_count ?? 0);
|
||||||
|
|
||||||
|
|
@ -64,20 +66,24 @@ export const MarketCardComponent = ({
|
||||||
}
|
}
|
||||||
console.log(data.id);
|
console.log(data.id);
|
||||||
postLikeComponent(data.id)
|
postLikeComponent(data.id)
|
||||||
.catch((error) => {
|
|
||||||
setLoadingLike(false);
|
|
||||||
console.error(error);
|
|
||||||
setLiked_by_user(temp);
|
|
||||||
setLikes_count(tempNum);
|
|
||||||
setErrorData({
|
|
||||||
title: `Error on liking ${name}.`,
|
|
||||||
list: [error["response"]["data"]["detail"]],
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setLoadingLike(false);
|
setLoadingLike(false);
|
||||||
setLikes_count(response.likes_count);
|
setLikes_count(response.likes_count);
|
||||||
setLiked_by_user(response.liked_by_user);
|
setLiked_by_user(response.liked_by_user);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
setLoadingLike(false);
|
||||||
|
setLikes_count(tempNum);
|
||||||
|
setLiked_by_user(temp);
|
||||||
|
if (error.response.status === 403 || error.response.status === 401) {
|
||||||
|
setValidApiKey(false);
|
||||||
|
} else {
|
||||||
|
console.error(error);
|
||||||
|
setErrorData({
|
||||||
|
title: `Error on liking ${name}.`,
|
||||||
|
list: [error["response"]["data"]["detail"]],
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ export default function StorePage(): JSX.Element {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err.response.status === 403) {
|
if (err.response.status === 403 || err.response.status === 401) {
|
||||||
setValidApiKey(false);
|
setValidApiKey(false);
|
||||||
} else {
|
} else {
|
||||||
setSearchData([]);
|
setSearchData([]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue