diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e8bdb0c --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +repl-temp-* +.pulp* +dist +cabal-dev +.cabal-sandbox +cabal.sandbox.config +*.o +*.hi +*.chi +*.chs.h +*.lksh* +.virthualenv +.psci_modules/ +.test_modules/ +bower_components/ +node_modules +tmp/ +.stack-work/ +output +examples/docs/docs/ +core-tests/full-core-docs.md +.psc-ide-port diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..08501e6 --- /dev/null +++ b/bower.json @@ -0,0 +1,26 @@ +{ + "name": "purescript-rnx-google-places", + "description": "Purescript wrapper for react-native-google-places", + "main": "index.js", + "authors": "Sathish Kumar ", + "license": "MIT", + "keywords": [ + "purescript", + "rnx", + "react-native", + "google-places" + ], + "homepage": "", + "private": true, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "dependencies": { + "purescript-rnx" : "^0.1.2-alpha", + "purescript-react": "^2.0.0" + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..adeba1f --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "purescript-rnx-google-places", + "version": "1.0.0", + "description": "Purescript wrapper for react-native-google-places", + "main": "index.js", + "repository": "atomicits/purescript-google-places", + "author": "Sathish Kumar ", + "license": "MIT", + "dependencies": { + "react-native-google-places": "^2.0.9" + } +} diff --git a/src/RNGooglePlaces.js b/src/RNGooglePlaces.js new file mode 100644 index 0000000..5be03a4 --- /dev/null +++ b/src/RNGooglePlaces.js @@ -0,0 +1,62 @@ +'use strict'; + +var rnxGooglePlaces = require("react-native-google-places"); + +exports._openAutocompleteModal = function(filterOptions){ + return function(success_callback){ + return function(error_callback){ + return function(){ + rnxGooglePlaces.openAutocompleteModal(filterOptions).then(function(resData){ + success_callback(resData)(); + }).catch(function(error){ + error_callback(error)(); + }); + }; + }; + }; +}; + +exports._openPlacePickerModal = function(boundsOptions){ + return function(success_callback){ + return function(error_callback){ + return function(){ + rnxGooglePlaces.openPlacePickerModal(boundsOptions).then(function (resData){ + success_callback (resData)(); + }).catch(function (error){ + error_callback(error)(); + }); + }; + }; + }; +}; + + +exports._getAutocompletePredictions = function(queryOptions){ + return function(success_callback){ + return function(error_callback){ + return function(){ + rnxGooglePlaces.getAutocompletePredictions(queryOptions).then(function (resData){ + success_callback (resData)(); + }).catch(function (error){ + error_callback(error)(); + }); + }; + }; + }; +}; + + + +exports._lookUpPlaceByID = function(placeID){ + return function(success_callback){ + return function(error_callback){ + return function(){ + rnxGooglePlaces.lookUpPlaceByID(placeID).then(function (resData){ + success_callback(resData)(); + }).catch(function(error){ + error_callback(error)(); + }); + }; + }; + }; +}; diff --git a/src/RNGooglePlaces.purs b/src/RNGooglePlaces.purs new file mode 100644 index 0000000..6936968 --- /dev/null +++ b/src/RNGooglePlaces.purs @@ -0,0 +1,93 @@ +module RNGooglePlaces where + +import Prelude + +import Control.Monad.Aff (Aff, attempt, makeAff) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Exception (Error) +import Data.Either (Either) + + +type FilterOptions = + { type :: String + , country :: String + , latitude :: Number + , longitude :: Number + , radius :: Number + , useOverlay :: Number + } + +type BoundOptions = + { latitude :: Number + , longitude :: Number + , radius :: Number + } + +type Query = + { type :: String + , country :: String + , latitude :: Number + , longitude :: Number + , radius :: Number + } + +newtype PlaceId = PlaceId String + +type ResponseModal = + { placeID :: String + , website :: String + , phoneNumber :: String + , address :: String + , name :: String + , types :: Array String + , latitude :: Number + , longitude :: Number + } + +type AutocompletePredictionsResponseModal = Array APResponseModal + +type APResponseModal = + { primaryText :: String + , placeID :: String + , secondaryText :: String + , fullText :: String + , types :: Array String + } + + +foreign import _openAutocompleteModal :: + forall e scallback ecallback. FilterOptions + -> scallback + -> ecallback + -> Eff e Unit + +foreign import _openPlacePickerModal :: + forall e scallback ecallback. BoundOptions + -> scallback + -> ecallback + -> Eff e Unit + +foreign import _getAutocompletePredictions :: + forall e scallback ecallback. Query + -> scallback + -> ecallback + -> Eff e Unit + +foreign import _lookUpPlaceByID :: + forall e scallback ecallback. PlaceId + -> scallback + -> ecallback + -> Eff e Unit + + +openautoCompleteModal :: forall eff. FilterOptions -> Aff eff (Either Error ResponseModal) +openautoCompleteModal opt = attempt $ makeAff (\error success -> _openAutocompleteModal opt success error) + +openplacePickerModal :: forall eff. BoundOptions -> Aff eff (Either Error ResponseModal) +openplacePickerModal opt = attempt $ makeAff (\error success -> _openPlacePickerModal opt success error) + +getautocompletePredictions :: forall eff. Query -> Aff eff (Either Error AutocompletePredictionsResponseModal) +getautocompletePredictions opt = attempt $ makeAff (\error success -> _getAutocompletePredictions opt success error) + +lookUpPlaceByID :: forall eff. PlaceId -> Aff eff (Either Error ResponseModal) +lookUpPlaceByID opt = attempt $ makeAff (\error success -> _lookUpPlaceByID opt success error) diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..2d77ca2 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,6 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 +react-native-google-places@^2.0.9: + version "2.0.9" + resolved "https://registry.yarnpkg.com/react-native-google-places/-/react-native-google-places-2.0.9.tgz#4df2ad5ac930d1f99e3b7ada3a4cd04f1627c143" +