reza added vote and comment action active

master
Reza_ashrafi 3 years ago
parent ab08b4cacd
commit 64f995c2e5
  1. 1
      src/redux/actions/index.js
  2. 11
      src/redux/actions/vote.js
  3. 1
      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. 43
      src/screens/Product/components/Rates.js

@ -16,3 +16,4 @@ export { default as transport } from "./transport";
export { default as activation } from "./activation"; export { default as activation } from "./activation";
export { default as form } from "./form"; 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;

@ -15,3 +15,4 @@ export { default as transport } from "./transport";
export { default as activation } from "./activation"; export { default as activation } from "./activation";
export { default as form } from "./form"; 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 comment from './reducers/comment';
import form from "./reducers/form"; import form from "./reducers/form";
import userFavorite from "./reducers/userFavorite"; import userFavorite from "./reducers/userFavorite";
import vote from "./reducers/vote";
const persistConfig = { const persistConfig = {
key: "root", key: "root",
@ -54,7 +55,8 @@ const store = createStore(
transport, transport,
comment, comment,
form, form,
userFavorite userFavorite,
vote
}) })
), ),
initialState, initialState,

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

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

Loading…
Cancel
Save