Skip to content

Commit

Permalink
Feature/ listando usuarios nos detalhes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
AGoretti committed Nov 20, 2020
1 parent fa4db7c commit 020810d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
6 changes: 5 additions & 1 deletion mobile/DiarioSaude/src/components/userItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ export interface User {
Name: string;
}

interface UserProp {
user: User;
}

const UserItem: React.FC<User> = ({ Name }) => {
return (
<View style={styles.container}>
<View style={styles.profile}>
<View style={styles.profileInfo}>
<Text style={styles.name}>André Goretti</Text>
<Text style={styles.name}>{Name}</Text>
</View>
<View style={styles.buttonsContainer}>
<RectButton style={styles.favoriteButton}>
Expand Down
47 changes: 41 additions & 6 deletions mobile/DiarioSaude/src/pages/GroupDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import React, { useEffect, useState } from "react";
import { View, Text, TouchableHighlight, Modal, TextInput } from "react-native";
import {
View,
Text,
TouchableHighlight,
Modal,
TextInput,
Group
} from "react-native";
import UserItem, { User } from "../../components/userItem";
import {
RectButton,
Expand All @@ -9,35 +16,63 @@ import { useNavigation, useFocusEffect } from "@react-navigation/core";
import AsyncStorage from "@react-native-community/async-storage";
import api from "../../services/api";
import styles from "./styles";
import { any } from "prop-types";

function GroupDeatils() {
const [id, setId] = useState();
const [group, setGroup] = useState();
const [modalVisible, setModalVisible] = useState(false);
const [CuserID, setCuserid] = useState();
const [users, setUsers] = useState([]);
const [usersNames, setUsersNames] = useState([]);

const { goBack } = useNavigation();

useEffect(() => {
if (users.length > 0) {
var temp = [];
users.map(user => {
// console.log(user);
if (group.users.includes(user._id)) {
temp.push(user.name);
}
});
setUsersNames(temp);
console.log(usersNames);
}
}, [users]);

useEffect(() => {
async function loadStorageData() {
const storagedId = await AsyncStorage.getItem("@DiarioSaude:Id");

setId(storagedId);
}
loadStorageData();

api
.get(`/group/${id}`)
.then(response => {
console.log(response.data);
// console.log(response.data);
setGroup(response.data);
return 1;
})
.then(response => {
api.get("/users").then(response => {
// console.log(typeof response.data.users);
setUsers(response.data.users);
});
})
.catch(error => {});

loadStorageData();
// api.get("/users").then(response => {
// console.log(response.data.users);
// setUsers(response.data.users);
// });
}, [id]);

function handleTest() {
console.log(group);
console.log(usersNames);
setModalVisible(true);
}

Expand Down Expand Up @@ -103,8 +138,8 @@ function GroupDeatils() {
</TouchableHighlight>
</Modal>
<Text>{group.groupName}</Text>
{group.users.map((name: string, index: number) => {
return <UserItem name={name} key={index} />;
{usersNames.map((name: string, index: number) => {
return <UserItem Name={name} key={index} />;
})}
<RectButton
onPress={() => {
Expand Down

0 comments on commit 020810d

Please sign in to comment.