import React from 'react'; import {useState, useEffect} from 'react'; import {ScrollView, StyleSheet, Text, View, Dimensions, Button, Image, TextInput, TouchableOpacity, ActivityIndicator} from 'react-native'; import Theme from '../../../../components/theme.style.js'; import Assets from '../../../../components/assets.manager.js'; import Icon from '../../../../components/icons'; import DB from '../../../../components/storage'; import REQUEST from '../../../../components/api'; import {Divider} from 'react-native-elements'; import Geolocation from '@react-native-community/geolocation'; import SlidingUpPanel from 'rn-sliding-up-panel'; import MapView, { PROVIDER_GOOGLE, Marker } from 'react-native-maps'; const styles = { container: { flex: 1, backgroundColor: '#f8f9fa', alignItems: 'center', justifyContent: 'center' }, panel: { flex: 1, backgroundColor: 'white', position: 'relative' }, panelHeader: { height: 60, backgroundColor: Theme.colors.lightGray, alignItems: 'center', justifyContent: 'center' } } const {height} = Dimensions.get('window') const renderStations = (data, onPress, onUpdateFavorite) => { return data.map((station, index) => { let stars = [1,2,3,4,5].map((star, i) => { let name = station.stars >= star ? "star" : "staro" let mgn = index > 0 ? 5 : 0 return ( ) }) return ( onPress(station) || null} key={index} style={{}}> {station.name} {station.address} {stars} updateFavorite(station, index, onUpdateFavorite)} style={{flex: 0, justifyContent: 'center'}}> ) }) } const updateFavorite = async (city, index, callback) => { let session = await DB.session() let urlTask = city.favorite ? "station_delete_favorite" : "station_add_favorite" let method = city.favorite ? "delete" : "get" console.log(urlTask, method) REQUEST(urlTask, method, { Authorization: session.token }, { noID: true, value: city.station_uuid }, {}, function(res){ console.log(res.message) callback(index, city.favorite ? false : true) }, function(error){ console.log(error) }) } export default function renderStationPanel(props){ const [panel, setpanel] = useState(null) const [updatedFavorite, setupdatedfavorite] = useState(false) const [updatedFavoriteIndex, setupdatedfavoriteindex] = useState(null) useEffect(() => { // console.log("Error has", props.error) if(props.visible){ panel.show() } return setpanel(null) }, [props.visible]) return ( setpanel(c)} draggableRange={{top: height / 2.35, bottom: 60}} showBackdrop={false}> {props.error ? "There was an error" : props.loading || props.data.length == 0 ? "Getting Nearby Stations" : "Unioil Stations found: " + props.data.length} {props.error ? Try Again : props.loading || props.data.length == 0 ? : null} {renderStations(props.data, props.onClick, props.onUpdateFavorite)} ) }