>
)}
- {bookmark && (
-
addToFavorite({ [bookmark]: location.getId() })}
- />
- )}
+ {bookmark ? (
+ bookmarkLoading ? (
+
+ ) : isActiveBookmark ? (
+
+ deleteBookmark({
+ id: userFavoriteList?.find(
+ (object) => object?.productId === headerOptions?.productId
+ )?.id,
+ })
+ }
+ />
+ ) : (
+
addToFavorite({ [bookmark]: location.getId() })}
+ />
+ )
+ ) : null}
{menu && (
setOverLayer(true)}
/>
- {isLogin && (
+ {user && (
@@ -256,7 +293,7 @@ function Navbar({
)}
- {!isLogin ? (
+ {!user ? (
({
isDark: state.publicApi.isDark,
isMobile: state.publicApi.isMobile,
headerOptions: state.publicApi.headerOptions,
- isLogin: state.user.status,
+ user: state.user.status,
cartProductsLength: state.userProduct.list?.filter(
(product) => product.condition < 2
)?.length,
+ bookmarkLoading: state.userFavorite.loading,
+ userFavoriteList: state.userFavorite.list,
});
const mapDispatchToProps = {
getCartProducts: userProduct.list,
addToFavorite: userFavorite.add,
+ deleteBookmark: userFavorite.del,
+ getUserFavorite: userFavorite.list
};
export default connect(mapStateToProps, mapDispatchToProps)(Navbar);
diff --git a/src/router.js b/src/router.js
index d39bd49..1677155 100644
--- a/src/router.js
+++ b/src/router.js
@@ -161,7 +161,17 @@ function Router({
path="/products"
exact
element={
-
+
}
/>
}
/>
diff --git a/src/views/Blogs/index.js b/src/views/Blogs/index.js
index 4f420bc..ea58929 100644
--- a/src/views/Blogs/index.js
+++ b/src/views/Blogs/index.js
@@ -20,23 +20,16 @@ export const Blogs = ({
getList,
blogs,
setHeaderOptions,
+ headerOptions,
activeHashtag,
}) => {
useEffect(() => {
- if (isMobile) {
- setHeaderOptions({
- shown: true,
- hamburgerMenu: true,
- qr: true,
- });
- } else {
- setHeaderOptions({ shown: true });
- }
+ setHeaderOptions(headerOptions);
getList();
}, []);
useEffect(() => {
- window.scrollTo(0, 0);
+ window.scroll({ top: 0, behavior: "smooth" });
}, []);
return (
diff --git a/src/views/Product/index.js b/src/views/Product/index.js
index b6cdc50..d1689ee 100644
--- a/src/views/Product/index.js
+++ b/src/views/Product/index.js
@@ -29,6 +29,7 @@ export const Product = ({
userId,
pushToCart,
headerOptions,
+ bookmarkLoading,
setHeaderOptions,
}) => {
const [type, setType] = useState("physical");
@@ -37,7 +38,6 @@ export const Product = ({
useEffect(() => {
getInfo({ id: location.getId(), vod: true });
- setHeaderOptions(headerOptions);
if (!isMobile) {
window.addEventListener("scroll", () => {
if (window.scrollY >= 64) {
@@ -49,6 +49,12 @@ export const Product = ({
}
}, []);
+ useEffect(() => {
+ if (book) {
+ setHeaderOptions({ ...headerOptions, productId: book?.id });
+ window.scroll({ top: 0, behavior: "smooth" });
+ }
+ }, [book]);
return (
<>
{/* Portrait */}
@@ -88,9 +94,11 @@ export const Product = ({
{"فیزیکی - دیجیتالی"}
در دسترس
-
- {book?.rate}
امتیاز
-
+ {book?.rate ? (
+
+ {book?.rate}
امتیاز
+
+ ) : null}
نسخه محصول را انتخاب کنید
@@ -196,6 +204,7 @@ const mapStateToProps = (state) => ({
isMobile: state.publicApi.isMobile,
isDark: state.publicApi.isDark,
userId: state.user.status?.id,
+ bookmarkLoading: state.userFavorite.loading,
});
const mapDispatchToProps = {
diff --git a/src/views/Products/index.js b/src/views/Products/index.js
index 4ba7306..1aefab3 100644
--- a/src/views/Products/index.js
+++ b/src/views/Products/index.js
@@ -23,6 +23,7 @@ export const Products = ({
useEffect(() => {
getList({ vod: true });
setHeaderOptions(headerOptions);
+ window.scroll({top: 0, behavior : 'smooth'});
}, []);
return (
diff --git a/src/views/Products/layouts/Mobile/Main.js b/src/views/Products/layouts/Mobile/Main.js
index b0bf8dd..2f7570f 100644
--- a/src/views/Products/layouts/Mobile/Main.js
+++ b/src/views/Products/layouts/Mobile/Main.js
@@ -137,7 +137,7 @@ export const Main = ({ books, filterOptions, grades }) => {
};
return (
-
+
{filterOptions?.productType === "دوره ویدئویی" && Items(2)}
{filterOptions?.productType === "کتاب دیجیتال" && Items(0)}
{filterOptions?.productType === "کتاب فیزیکی" && Items(1)}
diff --git a/src/views/ShoppingCart/Product/index.js b/src/views/ShoppingCart/Product/index.js
index 82dc283..e03b7b8 100644
--- a/src/views/ShoppingCart/Product/index.js
+++ b/src/views/ShoppingCart/Product/index.js
@@ -10,6 +10,14 @@ import exitIcon from "../../../assets/icons/exit.svg";
import deleteIcon from "../../../assets/icons/delete.svg";
function Product({ product, grades, pushToCart, isMobile, loading }) {
+ const [selectedItem, setSelectedItem] = React.useState(null);
+
+ React.useEffect(() => {
+ if (!loading) {
+ setSelectedItem(null);
+ }
+ }, [loading]);
+
return isMobile ? (
@@ -34,7 +42,8 @@ function Product({ product, grades, pushToCart, isMobile, loading }) {
src={exitIcon}
className="w-4"
alt=""
- onClick={() =>
+ onClick={() => {
+ setSelectedItem(product?.productId);
pushToCart(
{
productId: product?.productId,
@@ -43,26 +52,27 @@ function Product({ product, grades, pushToCart, isMobile, loading }) {
},
{},
{ id: product?.factorId }
- )
- }
+ );
+ }}
/>
- {product.productType === 2 && (
+ {product.productType === 2 ? (
- {loading ? (
+ {loading && selectedItem === product?.productId ? (
) : (
product.count
@@ -72,7 +82,8 @@ function Product({ product, grades, pushToCart, isMobile, loading }) {
<>
{product.count === 1 ? (
+ onClick={() => {
+ setSelectedItem(product?.productId);
pushToCart(
{
productId: product?.productId,
@@ -82,22 +93,23 @@ function Product({ product, grades, pushToCart, isMobile, loading }) {
},
{},
{ id: product?.factorId }
- )
- }
+ );
+ }}
src={deleteIcon}
alt="delete"
- className="border border-blue-800 border-solid p-1 w-8 bg-red-100 rounded-md cursor-pointer"
+ className="border border-red-800 border-solid p-1 w-8 bg-red-100 rounded-md cursor-pointer"
/>
) : (
@@ -105,7 +117,7 @@ function Product({ product, grades, pushToCart, isMobile, loading }) {
>
}
- )}
+ ) : null}
{separate(product.product.price * product.count)} تومان
@@ -147,13 +159,14 @@ function Product({ product, grades, pushToCart, isMobile, loading }) {
@@ -164,7 +177,8 @@ function Product({ product, grades, pushToCart, isMobile, loading }) {
<>
{product.count === 1 ? (
+ onClick={() => {
+ setSelectedItem(product?.productId);
pushToCart(
{
productId: product?.productId,
@@ -173,8 +187,8 @@ function Product({ product, grades, pushToCart, isMobile, loading }) {
},
{},
{ id: product?.factorId }
- )
- }
+ );
+ }}
src={deleteIcon}
alt="delete"
className="border border-red-300 border-solid p-1 w-7 bg-red-100 rounded-md cursor-pointer"
@@ -182,13 +196,14 @@ function Product({ product, grades, pushToCart, isMobile, loading }) {
) : (