Fakultas Ilmu Komputer UI

Commit 0029cee5 authored by Abraham Rudolf Brahmana's avatar Abraham Rudolf Brahmana
Browse files

feat: Add visual feedback to rate ecosystem

parent 7f1462a2
Pipeline #89052 passed with stage
in 10 minutes and 51 seconds
import React from "react";
import { View, StyleSheet } from "react-native";
import React, { useState } from "react";
import { View, StyleSheet, ActivityIndicator } from "react-native";
import { Rating } from "react-native-ratings";
import Colors from "../constants/Colors";
import SmallButton from "./button/SmallButton";
import Spacer from "./Spacer/Spacer";
type props = {
rating: number;
setRating: React.Dispatch<React.SetStateAction<number>>;
onSubmit: () => void;
onSubmit: () => Promise<void>;
setIsRating: React.Dispatch<React.SetStateAction<boolean>>;
};
const RatingForm = ({ rating, setRating, onSubmit }: props) => {
const RatingForm = ({ rating, setRating, onSubmit, setIsRating }: props) => {
const [isSubmitting, setIsSubmitting] = useState(false);
const onPressHandler = async () => {
setIsSubmitting(true);
await onSubmit();
setIsSubmitting(false);
setIsRating(false);
};
return (
<View style={styles.container}>
<Rating
......@@ -19,11 +30,19 @@ const RatingForm = ({ rating, setRating, onSubmit }: props) => {
style={{ paddingVertical: 10 }}
/>
<Spacer variant={"l"} />
<SmallButton
text={"Submit Rating"}
onPress={onSubmit}
colors={"primary"}
/>
{!isSubmitting ? (
<SmallButton
text={"Submit Rating"}
onPress={() => onPressHandler()}
colors={"primary"}
/>
) : (
<ActivityIndicator
size={"large"}
animating={true}
color={Colors.button.primary.bg}
/>
)}
</View>
);
};
......
......@@ -179,8 +179,9 @@ const EcosystemDetailScreen = ({
<RatingForm
rating={currentRating}
setRating={setCurrentRating}
onSubmit={() => {
rateEcosystem(id, user.id, currentRating);
setIsRating={setIsRating}
onSubmit={async () => {
await rateEcosystem(id, user.id, currentRating);
}}
/>
)}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment