Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alterações de imagens e correções gerais #1

Merged
merged 12 commits into from
Nov 25, 2022
Merged
Binary file modified assets/Categoria/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/Restaurante/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/Restaurante/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions constants/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ declare global {
var tipoRestaurante: string
var indexes: number[]
var restaurantes: any[]
var restaurantesFiltrados: any[]

// getters
function getToken(): string
Expand Down
32 changes: 32 additions & 0 deletions constants/modules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const letters = [
['a', 'b', 'c', 'd'],
['e', 'f', 'g', 'h'],
['i', 'j', 'k', 'l'],
['m', 'n', 'o', 'p'],
['q', 'r', 's', 't'],
['u', 'v', 'w', 'x', 'y', 'z']
]

const getFirstLetter = (name: string): string => {
return name.charAt(0).toLowerCase()
}

const getLetterIndex = (name: string): number => {
const letter = getFirstLetter(name)

let index = 0
letters.forEach((array: string[], i: number) => {
if (array.includes(letter)) {
if (typeof i === 'number') {
index = i
}
}
})
return index
}

const getLetter = (name: string): string => {
return letters[getLetterIndex(getFirstLetter(name))][0]
}

export { getLetter, getLetterIndex, getFirstLetter }
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"linux": "NODE_OPTIONS=--openssl-legacy-provider expo start --web",
"windows": "set NODE_OPTIONS=--openssl-legacy-provider && npx expo start --web"
"bash": "NODE_OPTIONS=--openssl-legacy-provider expo start --web",
"cmd": "set NODE_OPTIONS=--openssl-legacy-provider npx expo start --web",
"powershell": "$env:NODE_OPTIONS=--openssl-legacy-provider; expo start --web"
},
"dependencies": {
"@expo/vector-icons": "^13.0.0",
Expand Down
37 changes: 30 additions & 7 deletions screens/HomeScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from 'react-native'
import 'react-native-gesture-handler'
import '../../constants/globals'
import { getLetterIndex } from '../../constants/modules'
import styles from './style'

Notifications.setNotificationHandler({
Expand All @@ -27,7 +28,6 @@ Notifications.setNotificationHandler({
})

const HomeScreen = ({ navigation }: any): JSX.Element => {
const exampleImage: string = require('../../assets/example.jpeg')
const carousel01 = require('../../assets/Carousel/Carroca01.jpg')
const carousel02 = require('../../assets/Carousel/Carroca02.jpg')
const carousel03 = require('../../assets/Carousel/Carroca03.jpg')
Expand All @@ -49,16 +49,27 @@ const HomeScreen = ({ navigation }: any): JSX.Element => {
const [notification, setNotification] = React.useState(false)
const notificationListener = React.useRef<any>()
const responseListener = React.useRef<any>()
const [hasAlreadyNotified, setHasAlreadyNotified] =
React.useState<boolean>(false)
const [hasAlreadyFetched, setHasAlreadyFetched] =
React.useState<boolean>(false)

React.useEffect(() => {
navigation.addListener('focus', (): void => {
refreshScreen()
forceRemount()
if (hasAlreadyFetched === false) {
refreshScreen()

setHasAlreadyFetched(!hasAlreadyFetched)
}

try {
if (global.isLogged) {
if (global.user.id != null) {
checkNotifications()
if (global.user.id != null && global.user.id != undefined) {
if (hasAlreadyNotified === false) {
checkNotifications()

setHasAlreadyNotified(!hasAlreadyFetched)
}
}
}
} catch (err) {
Expand Down Expand Up @@ -187,12 +198,18 @@ const HomeScreen = ({ navigation }: any): JSX.Element => {
],
{ cancelable: false }
)

setHasAlreadyNotified(true)
} else {
console.log(json.message)

setHasAlreadyNotified(false)
}
})
.catch((error) => {
console.error(error)

setHasAlreadyNotified(false)
})
}

Expand Down Expand Up @@ -227,6 +244,8 @@ const HomeScreen = ({ navigation }: any): JSX.Element => {

setFilteredDataSource(DATA)
setMasterDataSource(DATA)
global.restaurantes = DATA
global.restaurantesFiltrados = DATA
})
.catch((err: Error): void => console.error(err))
} catch (error: unknown) {
Expand Down Expand Up @@ -330,7 +349,9 @@ const HomeScreen = ({ navigation }: any): JSX.Element => {
<View style={styles.spaceCategory}>
<img
src={require(`../../assets/Categoria/${
global.indexes[Math.floor(Math.random() * 5)]
// global.indexes[Math.floor(Math.random() * 5)]
// firstLetter
getLetterIndex(item[0].item.tipoRestaurante)
}.png`)}
onClick={() => onPressCategory(item)}
className='rounded-circle'
Expand Down Expand Up @@ -367,7 +388,9 @@ const HomeScreen = ({ navigation }: any): JSX.Element => {
<div style={styles.PositionImgRestaurant}>
<img
src={require(`../../assets/Restaurante/${
global.indexes[Math.floor(Math.random() * 5)]
// global.indexes[Math.floor(Math.random() * 5)]
// firstLetter
getLetterIndex(item[0].item.nomeRestaurante)
}.png`)}
className='rounded-circle'
style={{
Expand Down
49 changes: 24 additions & 25 deletions screens/MapsScreen/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { GoogleMap, Marker, useJsApiLoader } from '@react-google-maps/api'
import * as Location from 'expo-location'
import React from 'react'
import { ActivityIndicator, Platform, Text, View } from 'react-native'
import { ActivityIndicator, Platform, View } from 'react-native'
import GetLocation from 'react-native-get-location'
import Geolocation from 'react-native-geolocation-service'
import * as Location from 'expo-location';
import styles from './style'

const MapsScreen = ({ navigation }: any): JSX.Element => {
Expand All @@ -23,25 +22,29 @@ const MapsScreen = ({ navigation }: any): JSX.Element => {
})

React.useEffect(() => {
(async () => {
if (Platform.OS !== "web") {
const { status } = await Location.requestForegroundPermissionsAsync();

if (status !== "granted") {
window.alert("Insufficient permissions!")
return;
}
}

let location = await Location.getCurrentPositionAsync({accuracy: Location.Accuracy.Highest, timeInterval: 1000, distanceInterval: 0});
console.log(location)
setUserLocation({
;(async () => {
if (Platform.OS !== 'web') {
const { status } =
await Location.requestForegroundPermissionsAsync()

if (status !== 'granted') {
window.alert('Insufficient permissions!')
return
}
}

let location = await Location.getCurrentPositionAsync({
accuracy: Location.Accuracy.Highest,
timeInterval: 1000,
distanceInterval: 0
})
console.log(location)
setUserLocation({
lat: location.coords.latitude,
lng: location.coords.longitude
});
console.log(userLocation)
})();

})
console.log(userLocation)
})()

navigation.addListener('focus', (): void => {
// setUserActualLocation()
Expand Down Expand Up @@ -289,11 +292,7 @@ const MapsScreen = ({ navigation }: any): JSX.Element => {
fontFamily: 'Roboto'
}}
onClick={() => navigation.navigate('Profile')}
>
<View>
<Text>a</Text>
</View>
</Marker>
></Marker>

{navigator.geolocation.watchPosition(
//console.log(position.coords.latitude) loc do user
Expand Down
14 changes: 14 additions & 0 deletions screens/ProfileScreen/LoginScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ function LoginScreen({ navigation }: { navigation: any }) {
className='mb-3'
controlId='formBasicCheckbox'
>
<View style={{ marginVertical: 10 }}>
<Text
style={{
color: '#963333',
fontSize: 16,
fontWeight: 'bold'
}}
>
{message}
</Text>
</View>

<br />

<Text
style={{
color: '#000000'
Expand Down
13 changes: 9 additions & 4 deletions screens/RestaurantScreen/About/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Joi, { ObjectSchema } from 'joi'
import React from 'react'
import { Button, Form, Stack } from 'react-bootstrap'
import { Dimensions, SafeAreaView, ScrollView, Text, View } from 'react-native'
import { getFirstLetter, getLetterIndex } from '../../../constants/modules'
import styles from './style'

const AboutScreen = ({ navigation, route }: any): JSX.Element => {
Expand All @@ -11,6 +12,9 @@ const AboutScreen = ({ navigation, route }: any): JSX.Element => {
const restaurante: any = route.params
const [message, setMessage] = React.useState<string>('')
const [uniqueValue, setUniqueValue] = React.useState(1)
let firstLetter = getLetterIndex(
getFirstLetter(restaurante.nomeRestaurante)
)

React.useEffect((): void => {
navigation.addListener('focus', () => {
Expand Down Expand Up @@ -111,10 +115,11 @@ const AboutScreen = ({ navigation, route }: any): JSX.Element => {
>
<div style={styles.PositionImgRestaurant}>
<img
src={require(`../../../assets/Categoria/${
global.indexes[
Math.floor(Math.random() * 5)
]
src={require(`../../../assets/Restaurante/${
// Math.floor(Math.random() * 5)
// global.indexes[firstLetter]
getLetterIndex(restaurante.nomeRestaurante)
// restaurante.fotoRestaurante
}.png`)}
className='rounded-circle'
style={{
Expand Down
13 changes: 11 additions & 2 deletions screens/RestaurantScreen/Category/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
View
} from 'react-native'
import { SearchBar } from 'react-native-elements'
import { getLetterIndex } from '../../../constants/modules'
import styles from './style'

const RestaurantsScreen = ({ navigation, route }: any): JSX.Element => {
Expand All @@ -23,6 +24,8 @@ const RestaurantsScreen = ({ navigation, route }: any): JSX.Element => {
const [refresh, setRefresh] = React.useState<boolean>(false)
let tipoRestaurante = route.params.tipoRestaurante
const [key, setKey] = React.useState<number>(0)
const [hasAlreadyFetched, setHasAlreadyFetched] =
React.useState<boolean>(false)

const getRestaurant = async () => {
await fetch(`${global.getApiUrl()}/api/getRestaurantsByType`, {
Expand Down Expand Up @@ -57,7 +60,11 @@ const RestaurantsScreen = ({ navigation, route }: any): JSX.Element => {
if (global.tipoRestaurante != tipoRestaurante) {
setKey(key + 1)
tipoRestaurante = global.tipoRestaurante
getRestaurant()
if (hasAlreadyFetched === false) {
getRestaurant()

setHasAlreadyFetched(!hasAlreadyFetched)
}
} else {
if (refreshScreen()) {
setLoading(false)
Expand Down Expand Up @@ -94,7 +101,9 @@ const RestaurantsScreen = ({ navigation, route }: any): JSX.Element => {
variant='top'
style={styles.cardImg}
src={require(`../../../assets/Restaurante/${
global.indexes[Math.floor(Math.random() * 5)]
// global.indexes[Math.floor(Math.random() * 5)]
// firstLetter
getLetterIndex(item[0].item.nomeRestaurante)
}.png`)}
/>
<Card.Body
Expand Down
34 changes: 33 additions & 1 deletion screens/RestaurantScreen/Menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ const Menu = ({ navigation, route }: any) => {
}

const renderCardapio = (item: any): JSX.Element => {
const letters = [
['a', 'b', 'c', 'd'],
['e', 'f', 'g', 'h'],
['i', 'j', 'k', 'l'],
['m', 'n', 'o', 'p'],
['q', 'r', 's', 't'],
['u', 'v', 'w', 'x', 'y', 'z']
]

const getFirstLetter = (name: string): string => {
return name.charAt(0).toLowerCase()
}

const getLetterIndex = (letter: string): number => {
let index = 0
letters.forEach((array: string[], i: number) => {
if (array.includes(letter)) {
if (typeof i === 'number') {
index = i
}
}
})
return index
}

const getLetter = (name: string): string => {
return letters[getLetterIndex(getFirstLetter(name))][0]
}

let firstLetter = getLetterIndex(getFirstLetter(item.item.nomePrato))

return (
<View style={{ width: '100%' }}>
<Card style={styles.card}>
Expand All @@ -115,7 +146,8 @@ const Menu = ({ navigation, route }: any) => {
variant='top'
style={styles.cardImg}
src={require(`../../../assets/Cardapio/${
global.indexes[Math.floor(Math.random() * 5)]
// global.indexes[Math.floor(Math.random() * 5)]
firstLetter
}.png`)}
/>
</View>
Expand Down
Loading