diff --git a/src/redux/actions/blog.js b/src/redux/actions/blog.js
index 42e911b..0301cbe 100644
--- a/src/redux/actions/blog.js
+++ b/src/redux/actions/blog.js
@@ -6,6 +6,8 @@ const blog = {
await proxy.get("public/blogList", data, { dispatch }),
info: (data) => async (dispatch) =>
await proxy.get("public/blogInfo", data, { dispatch }),
+ active: (data) => async (dispatch) =>
+ await dispatch({ type: "public/active", data }),
};
export default blog;
diff --git a/src/redux/reducers/blog.js b/src/redux/reducers/blog.js
index 7117211..b96dde6 100644
--- a/src/redux/reducers/blog.js
+++ b/src/redux/reducers/blog.js
@@ -35,6 +35,7 @@ const initialState = {
color: "#E63F15",
},
],
+ active: null,
};
export default function blog(state = initialState, action) {
let { type, data } = action;
@@ -47,6 +48,13 @@ export default function blog(state = initialState, action) {
hashtags: [...new Set(data.map((object) => object.tag))],
error: null,
};
+ case "public/active":
+ return {
+ ...state,
+ active : data,
+ loading: false,
+ error: null,
+ };
case "public/blogInfo":
return { ...state, loading: false, error: null, blog: data };
case "blog/loading":
diff --git a/src/router.js b/src/router.js
index a8a1803..11fdab6 100644
--- a/src/router.js
+++ b/src/router.js
@@ -131,7 +131,7 @@ function Router({ isDark, isMobile, headerOptions, dialog, menu, setMenu }) {
title: false,
back: true,
menu: false,
- bookmark: 'productId',
+ bookmark: "productId",
}}
/>
}
@@ -405,7 +405,7 @@ function Router({ isDark, isMobile, headerOptions, dialog, menu, setMenu }) {
/>
}
/>
-
}
/>
diff --git a/src/views/Blog/index.js b/src/views/Blog/index.js
index e01cecb..8cd3a5e 100644
--- a/src/views/Blog/index.js
+++ b/src/views/Blog/index.js
@@ -18,16 +18,22 @@ export const Blog = ({
getInfo,
blog,
setHeaderOptions,
+ headerOptions,
getList,
blogs,
+ activeBlog,
}) => {
useEffect(() => {
- setHeaderOptions({ shown: true, menu: true, back: true, bookmark: true });
+ setHeaderOptions(headerOptions);
getInfo({ id: location.getId() });
if (blogs.length === 0) {
getList();
}
}, []);
+
+ useEffect(() => {
+ getInfo({ id: location.getId() });
+ }, [activeBlog]);
return (
@@ -161,6 +167,7 @@ const mapStateToProps = (state) => ({
isMobile: state.publicApi.isMobile,
blog: state.blog.blog,
blogs: state.blog.list,
+ activeBlog: state.blog.active,
});
const mapDispatchToProps = {
diff --git a/src/views/Blogs/index.js b/src/views/Blogs/index.js
index ea2b0ed..bb4982b 100644
--- a/src/views/Blogs/index.js
+++ b/src/views/Blogs/index.js
@@ -25,9 +25,7 @@ export const Blogs = ({ isMobile, getList, blogs, setHeaderOptions }) => {
} else {
setHeaderOptions({ shown: true });
}
- if (blogs.length === 0) {
- getList();
- }
+ getList();
}, []);
return (
diff --git a/src/views/Blogs/layouts/New.js b/src/views/Blogs/layouts/New.js
index d8511f2..df4259b 100644
--- a/src/views/Blogs/layouts/New.js
+++ b/src/views/Blogs/layouts/New.js
@@ -1,14 +1,16 @@
import React from "react";
import { connect } from "react-redux";
+import {blog} from '../../../redux/actions';
import { Link } from "react-router-dom";
import Avatar from "../../../components/Avatar";
-export const New = ({ blog, isMobile }) => {
+export const New = ({ blog, isMobile, setActive }) => {
return (
setActive(blog?.id)}
>
({
isMobile: state.publicApi.isMobile,
});
-const mapDispatchToProps = {};
+const mapDispatchToProps = {
+ setActive : blog.active
+};
export default connect(mapStateToProps, mapDispatchToProps)(New);
diff --git a/src/views/Home/Portrait/Private/Blogs/index.js b/src/views/Home/Portrait/Private/Blogs/index.js
index 27fdd7e..0e22f28 100644
--- a/src/views/Home/Portrait/Private/Blogs/index.js
+++ b/src/views/Home/Portrait/Private/Blogs/index.js
@@ -1,11 +1,14 @@
import React from "react";
import { Link } from "react-router-dom";
import { connect } from "react-redux";
+import { blog } from "../../../../../redux/actions";
import _ from "lodash";
+
+//assets
import arrowGreenIcon from "../../../../../assets/icons/dropdown-blue.svg";
import arrowWhiteIcon from "../../../../../assets/icons/arrow-left-white.svg";
-function Blogs({ list, isDark }) {
+function Blogs({ list, isDark, setActive }) {
return (
@@ -14,11 +17,7 @@ function Blogs({ list, isDark }) {
خواندنیها
{isDark ? (
-
+
) : (
{list.map((blog, index) => (
-
+
))}
@@ -37,23 +36,24 @@ function Blogs({ list, isDark }) {
);
}
-const Blog = ({ blog }) => {
+const Blog = ({ blog, setActive }) => {
return (
setActive(blog?.id)}
>
@@ -86,4 +86,8 @@ const mapStateToProps = (state) => ({
isDark: state.publicApi.isDark,
});
-export default connect(mapStateToProps, {})(Blogs);
+const mapDispatchToProps = {
+ setActive: blog.active,
+};
+
+export default connect(mapStateToProps, mapDispatchToProps)(Blogs);