Skip to content

Commit

Permalink
fix: Fix serving size select default value
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-software committed Oct 20, 2021
1 parent e4bafb4 commit ded7520
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/screens/recipe/recipe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,13 @@ const styles = StyleSheet.create({

export const Recipe = ({ route, navigation }: any) => {
const { recipeId } = route.params;
const [servingCount, setServingCount] = useState<number | undefined>(undefined);
const [selectedIndex, setSelectedIndex] = useState<IndexPath | IndexPath[]>(new IndexPath(0));
const { me } = useContext(UserContext);
const { loading, error, data } = useQuery<recipe, recipeVariables>(
Queries.GET_RECIPE,
{
variables: { recipeId },
onCompleted: (data) => setServingCount(data.recipe.data?.servingCount ?? undefined)
onCompleted: (data) => setSelectedIndex(new IndexPath((data.recipe.data?.servingCount ?? 0) - 1))
}
);

Expand Down Expand Up @@ -122,14 +121,13 @@ export const Recipe = ({ route, navigation }: any) => {
<Text category="h5" style={styles.heading}>
Ingredients
</Text>
{servingCount && recipe.servingCount ? (
{recipe.servingCount ? (
<View style={{ flexDirection: "row", alignItems: "center" }}>
<Text category="label" style={{marginRight: 16 }}>SERVES</Text>
<Select
selectedIndex={selectedIndex}
onSelect={(args) => {
setSelectedIndex(args);
setServingCount(Number(args.toString()))
}}
value={() => <Text>{selectedIndex.toString()}</Text>}
>
Expand All @@ -141,7 +139,7 @@ export const Recipe = ({ route, navigation }: any) => {
) : undefined}
</View>
{recipe.ingredients.length > 0 ? (
<RecipeIngredients ingredients={recipe.ingredients} servingCount={servingCount} defaultServingCount={recipe.servingCount} />
<RecipeIngredients ingredients={recipe.ingredients} servingCount={Number(selectedIndex) + 1} defaultServingCount={recipe.servingCount} />
) : (
<View style={{ paddingVertical: 16 }}>
<EmptyState description="This recipe has no ingredients." />
Expand Down

0 comments on commit ded7520

Please sign in to comment.