src_components_AddLandmark.tsx.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title> src/components/AddLandmark.tsx</title>
  7. <script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
  8. <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
  9. <script src="./build/entry.js"></script>
  10. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  11. <!--[if lt IE 9]>
  12. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  13. <![endif]-->
  14. <link href="https://fonts.googleapis.com/css?family=Roboto:100,400,700|Inconsolata,700" rel="stylesheet">
  15. <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
  16. <link type="text/css" rel="stylesheet" href="https://jmblog.github.io/color-themes-for-google-code-prettify/themes/tomorrow-night.min.css">
  17. <link type="text/css" rel="stylesheet" href="styles/app.min.css">
  18. <link type="text/css" rel="stylesheet" href="styles/iframe.css">
  19. <link type="text/css" rel="stylesheet" href="">
  20. <script async defer src="https://buttons.github.io/buttons.js"></script>
  21. </head>
  22. <body class="layout small-header">
  23. <div id="stickyNavbarOverlay"></div>
  24. <div class="top-nav">
  25. <div class="inner">
  26. <a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
  27. <span aria-hidden="true"></span>
  28. <span aria-hidden="true"></span>
  29. <span aria-hidden="true"></span>
  30. </a>
  31. <div class="logo">
  32. </div>
  33. <div class="menu">
  34. <div class="navigation">
  35. <a
  36. href="index.html"
  37. class="link"
  38. >
  39. API Documentation
  40. </a>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. <div id="main">
  46. <div
  47. class="sidebar "
  48. id="sidebarNav"
  49. >
  50. <nav>
  51. <h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Interfaces</h3><ul><li><a href="AddLandmarkProps.html">AddLandmarkProps</a></li><li><a href="CommentProps.html">CommentProps</a></li><li><a href="IdToken.html">IdToken</a></li><li><a href="IntroProps.html">IntroProps</a></li><li><a href="Landmark.html">Landmark</a></li><li><a href="LandmarkDetailsProps.html">LandmarkDetailsProps</a></li><li><a href="LandmarkPinProps.html">LandmarkPinProps</a></li><li><a href="LMComment.html">LMComment</a></li><li><a href="ProfileProps.html">ProfileProps</a></li><li><a href="RegisterProps.html">RegisterProps</a></li><li><a href="UserProfile.html">UserProfile</a></li></ul><h3>Components</h3><ul><li><a href="App.html">App</a></li><li><a href="Atlas.html">Atlas</a></li><li><a href="Comment.html">Comment</a></li><li><a href="PrimaryButton.html">PrimaryButton</a></li><li><a href="Profile.html">Profile</a></li><li><a href="SecondaryButton.html">SecondaryButton</a></li></ul><h3>Global</h3><ul><li><a href="global.html#IconStrings">IconStrings</a></li></ul></div><div class="category"><h2>Hooks</h2><h3>Namespaces</h3><ul><li><a href="useAuth.html">useAuth</a></li><li><a href="useLandmarks.html">useLandmarks</a></li><li><a href="useProfile.html">useProfile</a></li></ul></div><div class="category"><h2>Map</h2><h3>Interfaces</h3><ul><li><a href="UserLocation.html">UserLocation</a></li></ul><h3>Components</h3><ul><li><a href="AddLandmark.html">AddLandmark</a></li><li><a href="LandmarkDetails.html">LandmarkDetails</a></li><li><a href="LandmarkPin.html">LandmarkPin</a></li><li><a href="Map.html">Map</a></li></ul></div><div class="category"><h2>Navigation</h2><h3>Components</h3><ul><li><a href="AuthorizedNavigator.html">AuthorizedNavigator</a></li><li><a href="UnauthorizedNavigator.html">UnauthorizedNavigator</a></li></ul><h3><a href="global.html">Global</a></h3></div><div class="category"><h2>Stores</h2><h3>Classes</h3><ul><li><a href="AuthStore.html">AuthStore</a></li></ul></div><div class="category"><h2>Unauthorized</h2><h3>Components</h3><ul><li><a href="Intro.html">Intro</a></li><li><a href="UnauthorizedLayout.html">UnauthorizedLayout</a></li></ul><h3>Components / Registration</h3><ul><li><a href="RegisterMain.html">RegisterMain</a></li></ul></div>
  52. </nav>
  53. </div>
  54. <div class="core" id="main-content-wrapper">
  55. <div class="content">
  56. <header class="page-title">
  57. <p>Source</p>
  58. <h1>src/components/AddLandmark.tsx</h1>
  59. </header>
  60. <section>
  61. <article>
  62. <pre class="prettyprint source linenums"><code>import { FontAwesome } from "@expo/vector-icons";
  63. import React, { memo, useEffect, useState } from "react";
  64. import { ActivityIndicator, Dimensions, Image, Keyboard, Text, TextInput, TouchableOpacity, View } from 'react-native';
  65. import { TouchableWithoutFeedback } from "react-native-gesture-handler";
  66. import Picker from 'react-native-picker-select';
  67. import { colors, Icons, IconStrings } from "../globals";
  68. import { Landmark, useLandmarks } from "../hooks/useLandmarks";
  69. import { SecondaryButton } from "./Auth/Buttons";
  70. /**
  71. * Props for the {@link AddLandmark} component.
  72. */
  73. export interface AddLandmarkProps {
  74. /**
  75. * The {@link landmark} object to be added.
  76. */
  77. landmark?: Landmark;
  78. /**
  79. * A call back that toggles the visibility state of the {@link AddLandmark} modal. Passed down from {@link AddLandmark}.
  80. */
  81. setVisible: (state: boolean) => void;
  82. }
  83. /**
  84. * Component that renders a form for adding a new {@link Landmark}. Contained within a [react-native-modal]{@link https://github.com/react-native-modal/react-native-modal}.
  85. * @component
  86. * @category Map
  87. */
  88. const AddLandmark: React.FC&lt;AddLandmarkProps> = ({landmark, setVisible}) => {
  89. const {
  90. addLandmarkAsync,
  91. resetAddLm,
  92. addLandmarkStatus,
  93. newLandmark,
  94. getLandmarksStatus
  95. } = useLandmarks(undefined);
  96. /**
  97. * Holds the state of the landmark object to be added.
  98. */
  99. const currentLandmarkState = undefined;
  100. const [currentLandmark, setLandmark] = useState&lt;Landmark | undefined>(currentLandmarkState);
  101. useEffect(() => {
  102. /**
  103. * Updates this component's {@linkcode currentLandmarkState} when the {@linkcode landmark} prop passed down from the parent {@link Map}'s {@linkcode newLandmark} is changed.
  104. * Embedded in a useEffect that listens to the {@linkcode landmark} prop.
  105. * @memberOf AddLandmark
  106. */
  107. const updateLandmarkStateFromParent = () => {
  108. setLandmark(landmark), [landmark]
  109. }
  110. })
  111. useEffect(() => {
  112. /**
  113. * Resets the {@link addLandmarkAsync} mutation on successful add.
  114. * Embedded in a useEffect that listens to the {@link addLandmarkStatus} value from the {@link useLandmarks} hook.
  115. * @memberOf AddLandmark
  116. */
  117. const resetAddMutationOnSuccess = () => {
  118. if (addLandmarkStatus == 'success') {
  119. resetAddLm();
  120. }
  121. }
  122. resetAddMutationOnSuccess();
  123. }, [addLandmarkStatus]);
  124. /**
  125. * Calls {@link addLandmarkAsync} from {@link useLandmarks} to initate the process of adding a landmark, then closes the modal.
  126. */
  127. const submit = async () => {
  128. await addLandmarkAsync(currentLandmark)
  129. setVisible(false);
  130. }
  131. /**
  132. * Closes the modal.
  133. */
  134. const close = () => {
  135. setVisible(false)
  136. }
  137. return (
  138. &lt;View style={{backgroundColor: colors.red, paddingBottom: 20, height: Dimensions.get("window").height * .6, }}>
  139. {addLandmarkStatus == 'idle' ?
  140. &lt;>
  141. &lt;View style={{
  142. justifyContent: 'space-between',
  143. alignItems: 'center',
  144. flexDirection: "row",
  145. marginBottom: 15,
  146. borderBottomWidth: 1,
  147. borderBottomColor: 'white',
  148. paddingHorizontal: 20,
  149. paddingVertical: 10}}>
  150. &lt;Text style={{color: 'white', fontSize: 15}}>Add landmark here?&lt;/Text>
  151. &lt;FontAwesome name="times" color='white' size={25} onPress={close} />
  152. &lt;/View>
  153. &lt;View style={{paddingHorizontal: 20, paddingBottom: 20 }}>
  154. &lt;TextInput
  155. multiline={true}
  156. style={{backgroundColor: 'white', paddingHorizontal: 10, paddingTop: 10, paddingBottom: 10, marginBottom: 20, height: 150}}
  157. placeholder="Description"
  158. onChangeText={value => setLandmark({...currentLandmark, description: value})}>
  159. {currentLandmark?.description}
  160. &lt;/TextInput>
  161. &lt;View style={{flexDirection: 'row'}}>
  162. &lt;Picker
  163. style={{
  164. inputIOS: {color: 'white'},
  165. inputAndroid: {color: 'white'},
  166. viewContainer: {marginVertical: 10, flex: 1}, placeholder: {color: 'white'}}}
  167. textInputProps={{placeholderTextColor: 'white', selectionColor: 'white'}}
  168. Icon={() => &lt;FontAwesome name="chevron-down" color='white' size={20} />}
  169. placeholder={{label: "Select a landmark type...", value: 0}}
  170. value={currentLandmark?.landmark_type}
  171. onValueChange={(value) => {
  172. setLandmark({...currentLandmark, landmark_type: value, title: IconStrings[value]})
  173. console.log(value)
  174. }}
  175. useNativeAndroidPickerStyle={true}
  176. items={Object.keys(Icons)?.map(icon => {
  177. return (
  178. {label: IconStrings[parseInt(icon)].toUpperCase(), value: icon, key: icon}
  179. )})}
  180. />
  181. {currentLandmark?.landmark_type ? &lt;Image style={{marginLeft: 20}} source={Icons[currentLandmark.landmark_type]}/>
  182. : null}
  183. &lt;/View>
  184. &lt;/View>
  185. {currentLandmark?.landmark_type ?
  186. &lt;View style={{justifyContent: 'flex-end', flexDirection: 'row', paddingHorizontal: 20}}>
  187. {currentLandmark.description &amp;&amp; currentLandmark.title ?
  188. &lt;View style={{flexDirection: 'row' }}>
  189. &lt;TouchableOpacity onPress={async () => submit()}>&lt;Text style={{color: 'white', marginRight: 20}}>Add&lt;/Text>&lt;/TouchableOpacity>
  190. &lt;TouchableOpacity onPress={close}>&lt;Text style={{color: 'white'}}>Cancel&lt;/Text>&lt;/TouchableOpacity>
  191. &lt;/View> : null}
  192. &lt;/View> : null}
  193. &lt;TouchableWithoutFeedback style={{height: '100%'}} onPress={() => Keyboard.dismiss()}>&lt;Text>&lt;/Text>&lt;/TouchableWithoutFeedback>
  194. &lt;/> :
  195. &lt;View style={{height: '100%', justifyContent: "space-evenly", alignItems: "center"}}>
  196. &lt;Text style={{color: 'white', fontSize: 20}}>{
  197. addLandmarkStatus == "loading" ? 'Uploading landmark...' :
  198. addLandmarkStatus == "error" ? 'Something went wrong when trying to upload the landmark.' : null }
  199. &lt;/Text>
  200. {
  201. addLandmarkStatus == "loading" ? &lt;ActivityIndicator color='white' size="large"/> :
  202. addLandmarkStatus == "error" ? &lt;SecondaryButton text="Okay" onPress={close}/> : null
  203. }
  204. &lt;/View> }
  205. &lt;/View>
  206. )
  207. }
  208. export default memo(AddLandmark);</code></pre>
  209. </article>
  210. </section>
  211. </div>
  212. <footer class="footer">
  213. <div class="content has-text-centered">
  214. <p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a></p>
  215. <p class="sidebar-created-by">
  216. <a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
  217. <a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
  218. </p>
  219. </div>
  220. </footer>
  221. </div>
  222. <div id="side-nav" class="side-nav">
  223. </div>
  224. </div>
  225. <script src="scripts/app.min.js"></script>
  226. <script>PR.prettyPrint();</script>
  227. <script src="scripts/linenumber.js"> </script>
  228. </body>
  229. </html>