Skip to content

Commit 0b971ea

Browse files
Bruno BachBruno Bach
authored andcommitted
Finalizaçao do Proffy 1.0
1 parent 7449f6f commit 0b971ea

File tree

26 files changed

+941
-85
lines changed

26 files changed

+941
-85
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

mobile/App.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
import { StatusBar } from 'expo-status-bar';
22
import React from 'react';
3-
import { AppLoading } from 'expo';
4-
3+
import {AppLoading} from 'expo';
54
import { Archivo_400Regular, Archivo_700Bold, useFonts } from '@expo-google-fonts/archivo';
65
import { Poppins_400Regular, Poppins_600SemiBold } from '@expo-google-fonts/poppins';
6+
import AppStack from './src/routes/appStack';
7+
78

8-
import AppStack from './src/routes/AppStack';
99

1010
export default function App() {
11-
let [fontsLoaded] = useFonts({
11+
// carregando fonts
12+
let [fontsloaded] = useFonts({
1213
Archivo_400Regular,
13-
Archivo_700Bold,
14+
Archivo_700Bold,
1415
Poppins_400Regular,
15-
Poppins_600SemiBold
16+
Poppins_600SemiBold,
1617
});
1718

18-
if (!fontsLoaded) {
19-
return <AppLoading />;
19+
if (!fontsloaded) {
20+
return <AppLoading />
2021
} else {
2122
return (
2223
<>
23-
<AppStack />
24-
<StatusBar style="light" />
24+
<AppStack />
25+
<StatusBar style="light" />
2526
</>
26-
);
27+
)
2728
}
2829
}
30+

mobile/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"dependencies": {
1111
"@expo-google-fonts/archivo": "^0.1.0",
1212
"@expo-google-fonts/poppins": "^0.1.0",
13+
"@react-native-community/async-storage": "~1.11.0",
1314
"@react-native-community/masked-view": "0.1.10",
1415
"@react-navigation/bottom-tabs": "^5.8.0",
1516
"@react-navigation/native": "^5.7.3",
1617
"@react-navigation/stack": "^5.9.0",
18+
"axios": "^0.19.2",
1719
"expo": "~38.0.8",
1820
"expo-font": "~8.2.1",
1921
"expo-status-bar": "^1.0.2",

mobile/src/@types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// para utilizar png no mobile
12
declare module '*.png';
Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
1-
import React from 'react';
1+
import React, { ReactNode } from 'react';
22
import { View, Image, Text } from 'react-native';
33
import { BorderlessButton } from 'react-native-gesture-handler';
4+
import { useNavigation } from '@react-navigation/native';
45

56
import backIcon from '../../assets/images/icons/back.png';
67
import logoImg from '../../assets/images/logo.png';
78

89
import styles from './styles';
9-
import { useNavigation } from '@react-navigation/native';
10+
1011

1112
interface PageHeaderProps {
1213
title: string;
14+
headerRight?: ReactNode; // ReactNode um componente como um variavel
1315
}
1416

15-
const PageHeader: React.FC<PageHeaderProps> = ({ title }) => {
17+
const PageHeader: React.FC<PageHeaderProps> = ({title, headerRight, children}) => {
18+
1619
const { navigate } = useNavigation();
1720

18-
function handleGoBack() {
21+
// retorna para landing page
22+
function hadleGoBack() {
1923
navigate('Landing');
2024
}
2125

2226
return (
2327
<View style={styles.container}>
2428
<View style={styles.topBar}>
25-
<BorderlessButton onPress={handleGoBack}>
26-
<Image source={backIcon} resizeMode='contain' />
29+
30+
<BorderlessButton onPress={hadleGoBack}>
31+
<Image source={backIcon} resizeMode="contain" />
2732
</BorderlessButton>
2833

29-
<Image source={logoImg} resizeMode='contain' />
34+
<Image source={logoImg} resizeMode="contain"/>
35+
</View>
36+
37+
<View style={styles.header}>
38+
<Text style={styles.title}>{title}</Text>
39+
40+
{headerRight}
3041
</View>
42+
3143

32-
<Text style={styles.title}>{title}</Text>
44+
{children}
45+
3346
</View>
34-
);
47+
)
3548
}
3649

3750
export default PageHeader;

mobile/src/components/PageHeader/styles.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@ import { StyleSheet } from 'react-native';
33
const styles = StyleSheet.create({
44
container: {
55
padding: 40,
6-
backgroundColor: '#8257e5'
6+
backgroundColor: '#8257e5',
77
},
88

99
topBar: {
1010
flexDirection: 'row',
1111
alignItems: 'center',
12-
justifyContent: 'space-between'
12+
justifyContent: 'space-between',
13+
},
14+
15+
header: {
16+
flexDirection: 'row',
17+
alignItems: 'center',
18+
justifyContent: 'space-between',
1319
},
1420

1521
title: {
1622
fontFamily: 'Archivo_700Bold',
17-
color: '#FFF',
23+
color: '#fff',
1824
fontSize: 24,
1925
lineHeight: 32,
2026
maxWidth: 160,
21-
marginVertical: 40
27+
marginVertical: 40,
2228
}
23-
});
29+
})
2430

2531
export default styles;
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import React, { useState } from 'react';
2+
3+
import { View, Image, Text, Linking } from 'react-native';
4+
5+
import { RectButton } from 'react-native-gesture-handler';
6+
7+
import heartOutlineIcon from '../../assets/images/icons/heart-outline.png';
8+
9+
import AsyncStorage from '@react-native-community/async-storage';
10+
11+
import unfavoriteIcon from '../../assets/images/icons/unfavorite.png';
12+
13+
import whatsappIcon from '../../assets/images/icons/whatsapp.png';
14+
15+
import styles from './styles';
16+
import Favorites from '../../pages/Favorites';
17+
import { api } from '../../services/api';
18+
19+
export interface Teacher {
20+
id: number;
21+
avatar: string;
22+
bio: string;
23+
cost: number;
24+
name: string;
25+
subject: string;
26+
whatsapp: string;
27+
}
28+
29+
interface TeacherItemProps {
30+
teacher: Teacher;
31+
favorited: boolean;
32+
}
33+
34+
35+
36+
const TeatcherItem: React.FC<TeacherItemProps> = ( { teacher, favorited } ) => {
37+
38+
const [isFavorited, setIsFavorited] = useState(favorited);
39+
40+
// whatsapp deep-link
41+
function handleLinkToWhatsapp () {
42+
43+
api.post('connections', {
44+
user_id: teacher.id,
45+
});
46+
47+
Linking.openURL(`whatsapp://send?phone=${teacher.whatsapp}`)
48+
}
49+
50+
async function handleToggleFavorite() {
51+
52+
const favorites = await AsyncStorage.getItem('favorites');
53+
54+
let favoritesArray = [];
55+
56+
if (favorites) {
57+
favoritesArray = JSON.parse(favorites);
58+
}
59+
60+
if(isFavorited) {
61+
// remover dos favoritos
62+
const favoriteIndex = favoritesArray.findIndex((teacherItem: Teacher) => {
63+
return teacherItem.id === teacher.id;
64+
})
65+
66+
// indidce, e quantas posições remover
67+
favoritesArray.splice(favoriteIndex , 1);
68+
69+
setIsFavorited(false);
70+
} else {
71+
// adidionar aos favoritos
72+
73+
74+
favoritesArray.push(teacher);
75+
76+
setIsFavorited(true);
77+
}
78+
79+
await AsyncStorage.setItem('favorites', JSON.stringify(favoritesArray));
80+
}
81+
82+
return (
83+
<View style={styles.container}>
84+
<View style={styles.profile}>
85+
<Image
86+
style={styles.avatar}
87+
source={{ uri: teacher.avatar }}
88+
/>
89+
90+
<View style={styles.profileInfo}>
91+
<Text style={styles.name}>{teacher.name}</Text>
92+
<Text style={styles.subject}>{teacher.subject}</Text>
93+
</View>
94+
</View>
95+
96+
<Text style={styles.bio}>
97+
{teacher.bio}
98+
</Text>
99+
100+
<View style={styles.footer}>
101+
<Text style={styles.price}>
102+
Preço/hora {' '}
103+
<Text style={styles.priceValue}>
104+
R$ {teacher.cost}
105+
</Text>
106+
</Text>
107+
108+
<View style={styles.buttonsContainer}>
109+
<RectButton
110+
onPress={handleToggleFavorite}
111+
style={[
112+
styles.favoriteButton,
113+
isFavorited ? styles.favorited : {}]} >
114+
{ isFavorited
115+
? <Image source={unfavoriteIcon} />
116+
: <Image source={heartOutlineIcon} />}
117+
</RectButton>
118+
119+
<RectButton onPress={handleLinkToWhatsapp} style={styles.contactButton} >
120+
<Image source={whatsappIcon} />
121+
<Text style={styles.contactButtonText}>Entrar em contato</Text>
122+
</RectButton>
123+
</View>
124+
</View>
125+
</View>
126+
)
127+
};
128+
129+
export default TeatcherItem;

0 commit comments

Comments
 (0)