reza added vote and comment action active

master
Reza_ashrafi 3 years ago
parent ab08b4cacd
commit 64f995c2e5
  1. 3
      src/redux/actions/index.js
  2. 11
      src/redux/actions/vote.js
  3. 3
      src/redux/reducers/index.js
  4. 24
      src/redux/reducers/vote.js
  5. 4
      src/redux/store.js
  6. 2
      src/screens/Product/components/Book.js
  7. 45
      src/screens/Product/components/Rates.js

@ -15,4 +15,5 @@ export {default as userFavorite} from "./userFavorite";
export { default as transport } from "./transport";
export { default as activation } from "./activation";
export { default as form } from "./form";
export { default as comment } from "./comment";
export { default as comment } from "./comment";
export { default as vote } from "./vote";

@ -0,0 +1,11 @@
import proxy from "../proxy";
const vote = {
add:
(data = {}, data2) =>
async (dispatch) => {
await proxy.post("userVote/add", data, { dispatch });
},
};
export default vote;

@ -14,4 +14,5 @@ export { default as userFavorite } from "./userFavorite";
export { default as transport } from "./transport";
export { default as activation } from "./activation";
export { default as form } from "./form";
export { default as comment } from "./comment";
export { default as comment } from "./comment";
export { default as vote } from "./vote";

@ -0,0 +1,24 @@
import { asyncApiAwesomeAlert } from "../../utils/AsyncWrappers";
const initialState = {
loading: false,
error: null,
};
export default function vote(state = initialState, action) {
let { type, data } = action;
switch (type) {
case "userVote/add":
asyncAwesomeAlert("نتیجه", "رای شما با موفقیت ثبت شد.", {
showCancelButton: false,
});
return { ...state, loading: false, error: null };
case "userVote/loading":
return { ...state, loading: true };
case "userVote/error":
toast.error(data.message);
return { ...state, loading: false, error: data.message };
default:
return state;
}
}

@ -19,6 +19,7 @@ import transport from "./reducers/transport"
import comment from './reducers/comment';
import form from "./reducers/form";
import userFavorite from "./reducers/userFavorite";
import vote from "./reducers/vote";
const persistConfig = {
key: "root",
@ -54,7 +55,8 @@ const store = createStore(
transport,
comment,
form,
userFavorite
userFavorite,
vote
})
),
initialState,

@ -464,7 +464,7 @@ function Book({
</Text>
<Entypo name="chevron-small-left" size={20} color="#196EC0" />
</View>
<Rates rate={book?.rate || 4} />
<Rates rate={book?.rate || 4} productId={book?.product[1]?.id} />
<Comments comments={book?.comments} productId={book?.product[1]?.id} />
</>
)}

@ -1,6 +1,9 @@
import React from "react";
import { View, Text, Dimensions, Appearance } from "react-native";
import { Rating } from 'react-native-ratings';
import { Rating } from "react-native-ratings";
import { connect } from "react-redux";
import { vote } from "../../../redux/actions";
import { asyncAwesomeAlert } from "../../../utils/AsyncWrappers";
//assets
import tw from "tailwind-rn";
@ -9,12 +12,11 @@ import Colors from "../../../constants/Colors";
const width = Dimensions.get("window").width;
export default function Rates({ rate }) {
function Rates({ rate, productId, addVote, isBuyed }) {
const ratingCompleted = (rating) => {
return;
}
};
return (
<View style={tw("flex flex-row-reverse")}>
<View style={[tw("flex items-center justify-center"), { width: "25%" }]}>
@ -26,17 +28,27 @@ export default function Rates({ rate }) {
{rate}
</Text>
<Rating
type='star'
type="star"
ratingCount={5}
imageSize={15}
onFinishRating={(rating) => ratingCompleted(rating)}
onFinishRating={(rating) =>
isBuyed
? addVote({ productId, vote: rating })
: asyncAwesomeAlert(
"خطا",
"شما این محصول رو خریداری نکرده اید.",
{
showCancelButton: false,
}
)
}
/>
<Text
style={{
fontSize: fontSize.sm,
color: "#707070",
fontFamily: "light",
marginTop : 5
marginTop: 5,
}}
>
{`از بین ${1150} نفر`}
@ -59,8 +71,8 @@ export default function Rates({ rate }) {
const Progress = ({ data, ...props }) => {
const colorScheme = React.useMemo(() => {
return Appearance.getColorScheme();
},[props.useless]);
return Appearance.getColorScheme();
}, [props.useless]);
return (
<View style={[tw("flex flex-1 flex-row items-center py-1.5")]}>
@ -82,7 +94,10 @@ const Progress = ({ data, ...props }) => {
<View
style={[
tw("h-full rounded-md"),
{ width: data.value + "%", backgroundColor: Colors.theme1[colorScheme].greenCF },
{
width: data.value + "%",
backgroundColor: Colors.theme1[colorScheme].greenCF,
},
]}
></View>
</View>
@ -100,3 +115,11 @@ const Progress = ({ data, ...props }) => {
</View>
);
};
const mapStateToProps = (state) => ({});
const mapDispatchToProps = {
addVote: vote.add,
};
export default connect(mapStateToProps, mapDispatchToProps)(Rates);

Loading…
Cancel
Save