You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

378 lines
12 KiB

  1. <template>
  2. <div :class="['page-container', { 'nav-is-showing': isPickerVisible }]">
  3. <header>
  4. <div class="header__col">
  5. <template v-if="!isPickerVisible">
  6. <button class="btn btn--primary" @click="showPicker">
  7. tap the map or <svg
  8. xmlns="http://www.w3.org/2000/svg"
  9. class="icon icon-tabler icon-tabler-search"
  10. width="24"
  11. height="24"
  12. viewBox="0 0 24 24"
  13. stroke-width="3"
  14. stroke="#ffffff"
  15. fill="none"
  16. stroke-linecap="round"
  17. stroke-linejoin="round"
  18. >
  19. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  20. <circle cx="10" cy="10" r="7" />
  21. <line x1="21" y1="21" x2="15" y2="15" />
  22. </svg>
  23. </button>
  24. </template>
  25. <template v-if="isPickerVisible">
  26. <button class="btn btn--primary" @click="showPicker">
  27. hide search <svg
  28. xmlns="http://www.w3.org/2000/svg"
  29. class="icon icon-tabler icon-tabler-arrow-bar-to-up"
  30. width="24"
  31. height="24"
  32. viewBox="0 0 24 24"
  33. stroke-width="3"
  34. stroke="#ffffff"
  35. fill="none"
  36. stroke-linecap="round"
  37. stroke-linejoin="round"
  38. >
  39. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  40. <line x1="12" y1="10" x2="12" y2="20" />
  41. <line x1="12" y1="10" x2="16" y2="14" />
  42. <line x1="12" y1="10" x2="8" y2="14" />
  43. <line x1="4" y1="4" x2="20" y2="4" />
  44. </svg>
  45. </button>
  46. </template>
  47. </div>
  48. <div class="header__col">
  49. <Logo />
  50. <div v-if="!selectedOrig.iata && !isPickerVisible" class="logo-blurb">
  51. from one of <strong>{{ airports_orig.length }}</strong> <span style="color: white;">local</span> airports
  52. </div>
  53. <div v-if="selectedOrig.iata && !selectedDest.iata && airports_dest.length > 1 && !isPickerVisible" class="logo-blurb">
  54. to one of <strong>{{ airports_dest.length }}</strong> {{ getCompliment() }} destinations
  55. </div>
  56. </div>
  57. <div class="header__col" />
  58. </header>
  59. <!-- <pre style="position: fixed; z-index: 500; right: 0; top: 2rem; font-size: 0.6rem; color: gray;">
  60. {{ selectedOrig }}
  61. {{ selectedDest }}
  62. </pre> -->
  63. <main>
  64. <nav v-if="isMounted" :class="['nav', { 'nav--show': isPickerVisible },{ 'nav--hide': !isPickerVisible }]">
  65. <AirportPicker
  66. :airports="airports_orig"
  67. :selected-airport="selectedOrig"
  68. leg="start here ►"
  69. @select-airport="makeOrigin"
  70. @deselect-airport="clearOrigin"
  71. />
  72. <AirportPicker
  73. v-show="selectedOrig.iata"
  74. :airports="airports_dest"
  75. :selected-airport="selectedDest"
  76. leg="land here ■"
  77. @select-airport="makeDestination"
  78. @deselect-airport="clearDestination"
  79. />
  80. </nav>
  81. <Map
  82. ref="mapComponent"
  83. :airports-orig="airports_orig"
  84. :airports-dest="airports_dest"
  85. :selected-orig="selectedOrig"
  86. :selected-dest="selectedDest"
  87. @make-origin="makeOrigin"
  88. @make-destination="makeDestination"
  89. @clear-origin="clearOrigin"
  90. @clear-destination="clearDestination"
  91. />
  92. <div :class="['flyout-container',{ 'flyout-container--hide': !selectedOrig.iata || !selectedDest.iata },{ 'flyout-container--show': selectedOrig.iata && selectedDest.iata }]">
  93. <FlightsFlyout
  94. v-if="selectedOrig.iata && selectedDest.iata"
  95. :selected-orig="selectedOrig"
  96. :selected-dest="selectedDest"
  97. />
  98. </div>
  99. </main>
  100. </div>
  101. </template>
  102. <script>
  103. // import AirportPicker from '../components/AirportPicker.vue'
  104. export default {
  105. // components: { AirportPicker },
  106. data () {
  107. return {
  108. isMounted: false,
  109. color: 'red',
  110. isSidebarVisible: false,
  111. isPickerVisible: false,
  112. airports_orig: [],
  113. airports_dest: [],
  114. airportFetch_filterFormula: 'AND(Is_Origin=1,{IsCurrent-AsOrigin}=\'Yes\')',
  115. airportFetch_fields: [
  116. 'Airport_IATA',
  117. 'Icon_Url',
  118. 'Latitude_Deg',
  119. 'Longitude_Deg',
  120. 'Municipality',
  121. 'Airport_Name',
  122. 'Type',
  123. 'Search_Field'
  124. ],
  125. airportFetch_sort: '&sort[0][field]=Airport_IATA&sort[0][direction]=asc',
  126. selectedOrig: {
  127. iata: '',
  128. lat: '',
  129. long: '',
  130. icon: '',
  131. name: '',
  132. municipality: '',
  133. type: '',
  134. search: ''
  135. },
  136. selectedDest: {
  137. iata: '',
  138. lat: '',
  139. long: '',
  140. icon: '',
  141. name: '',
  142. municipality: '',
  143. type: '',
  144. search: ''
  145. },
  146. emptyAirport: {
  147. iata: '',
  148. lat: '',
  149. long: '',
  150. icon: '',
  151. name: '',
  152. municipality: '',
  153. type: '',
  154. search: ''
  155. }
  156. }
  157. },
  158. async fetch () {
  159. let offset
  160. let data = []
  161. while (true) {
  162. const offsetParam = offset ? `&offset=${offset}` : ''
  163. const res = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Airports_IATA?filterByFormula=${this.airportFetch_filterFormula}${this.airportFetch_fields_string}${this.airportFetch_sort}${offsetParam}`, {
  164. method: 'GET',
  165. headers: {
  166. 'Content-Type': 'application/x-www-form-urlencoded',
  167. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  168. }
  169. })
  170. const json = await res.json()
  171. offset = await json.offset
  172. data = [...data, ...await json.records]
  173. await console.log(data.length)
  174. if (await !offset) { break } // Were done let's stop this thing
  175. }
  176. // console.log('Look ma! I waited!') // Won't run till the while is done
  177. this.airports_orig = data.map((record) => {
  178. return {
  179. iata: record.fields.Airport_IATA,
  180. lat: record.fields.Latitude_Deg,
  181. long: record.fields.Longitude_Deg,
  182. icon: record.fields.Icon_Url,
  183. name: record.fields.Airport_Name,
  184. municipality: record.fields.Municipality,
  185. type: record.fields.Type,
  186. search: record.fields.Search_Field
  187. }
  188. })
  189. },
  190. computed: {
  191. airportFetch_fields_string () {
  192. const vm = this
  193. const array = vm.airportFetch_fields.map((field) => {
  194. return '&fields[]=' + field
  195. })
  196. return array.join('')
  197. }
  198. },
  199. created () {
  200. // console.log(this.$route.path)
  201. if (this.$route && this.$route.params && this.$route.params.o) {
  202. this.fetchSingleAirport(this.$route.params.o, true)
  203. }
  204. if (this.$route && this.$route.params && this.$route.params.d) {
  205. this.fetchSingleAirport(this.$route.params.d, false)
  206. }
  207. },
  208. mounted () {
  209. this.isMounted = true
  210. },
  211. // watch: {
  212. // history (to, from) {
  213. // console.log(`routed from ${from} to ${to}`)
  214. // }
  215. // },
  216. methods: {
  217. getCompliment () {
  218. const arr = [
  219. 'beautiful', 'gorgeous', 'breathtaking', 'wild', 'adventurous', 'amazing', 'majestic', 'uncharted', 'unpredictable', 'pristine', 'untamed'
  220. ]
  221. return arr[Math.floor(Math.random() * arr.length)]
  222. },
  223. makeOrigin (airport) {
  224. // console.log(airport)
  225. this.selectedOrig = { ...airport }
  226. this.selectedDest = { ...this.emptyAirport }
  227. history.pushState(
  228. {},
  229. null,
  230. '/go/' + encodeURIComponent(airport.iata)
  231. )
  232. this.fetchDestinations(airport.iata)
  233. },
  234. makeDestination (airport) {
  235. this.selectedDest = { ...airport }
  236. this.isPickerVisible = false
  237. history.pushState(
  238. {},
  239. null,
  240. '/go/' + encodeURIComponent(this.selectedOrig.iata) + '/' + encodeURIComponent(airport.iata)
  241. )
  242. },
  243. clearOrigin () {
  244. this.selectedOrig = { ...this.emptyAirport }
  245. this.selectedDest = { ...this.emptyAirport }
  246. history.pushState(
  247. {},
  248. null,
  249. '/go/'
  250. )
  251. },
  252. clearDestination () {
  253. this.selectedDest = { ...this.emptyAirport }
  254. history.pushState(
  255. {},
  256. null,
  257. '/go/' + encodeURIComponent(this.selectedOrig.iata)
  258. )
  259. },
  260. async fetchDestinations (iata) {
  261. const airportFetchDestfilterFormula = `AND(Is_Destination=1,{IsCurrent-AsDest}="Yes",(FIND("${iata}", Associated_Origin_Search)>0))`
  262. let offset
  263. let data = []
  264. while (true) {
  265. const offsetParam = offset ? `&offset=${offset}` : ''
  266. const res = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Airports_IATA?filterByFormula=${airportFetchDestfilterFormula}${this.airportFetch_fields_string}${this.airportFetch_sort}${offsetParam}`, {
  267. method: 'GET',
  268. headers: {
  269. 'Content-Type': 'application/x-www-form-urlencoded',
  270. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  271. }
  272. })
  273. const json = await res.json()
  274. offset = await json.offset
  275. data = [...data, ...await json.records]
  276. // await console.log(data.length)
  277. if (await !offset) { break } // Were done let's stop this thing
  278. }
  279. // console.log('Look ma! I waited!') // Won't run till the while is done
  280. this.airports_dest = data.map((record) => {
  281. return {
  282. iata: record.fields.Airport_IATA,
  283. lat: record.fields.Latitude_Deg,
  284. long: record.fields.Longitude_Deg,
  285. icon: record.fields.Icon_Url,
  286. name: record.fields.Airport_Name,
  287. municipality: record.fields.Municipality,
  288. type: record.fields.Type,
  289. search: record.fields.Search_Field
  290. }
  291. })
  292. },
  293. async fetchSingleAirport (iata, isOrig) {
  294. const airportFetchFilterFormula =
  295. isOrig
  296. ? `AND(Is_Origin=1,{IsCurrent-AsOrigin}="Yes",Airport_IATA="${iata}")`
  297. : `AND(Is_Destination=1,{IsCurrent-AsDest}="Yes",Airport_IATA="${iata}")`
  298. const response = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Airports_IATA?filterByFormula=${airportFetchFilterFormula}${this.airportFetch_fields_string}`, {
  299. method: 'GET',
  300. headers: {
  301. 'Content-Type': 'application/x-www-form-urlencoded',
  302. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  303. }
  304. })
  305. const mapData = await response.json()
  306. const thisAirport = {
  307. iata: mapData.records[0].fields.Airport_IATA,
  308. lat: mapData.records[0].fields.Latitude_Deg,
  309. long: mapData.records[0].fields.Longitude_Deg,
  310. icon: mapData.records[0].fields.Icon_Url,
  311. name: mapData.records[0].fields.Airport_Name,
  312. municipality: mapData.records[0].fields.Municipality,
  313. type: mapData.records[0].fields.Type,
  314. search: mapData.records[0].fields.Search_Field
  315. }
  316. switch (isOrig) {
  317. case true:
  318. this.selectedOrig = { ...thisAirport }
  319. this.fetchDestinations(thisAirport.iata)
  320. break
  321. case false:
  322. this.selectedDest = { ...thisAirport }
  323. break
  324. default:
  325. break
  326. }
  327. },
  328. showPicker () {
  329. const vm = this
  330. vm.isPickerVisible = !vm.isPickerVisible
  331. setTimeout(function () {
  332. vm.$refs.mapComponent.resize()
  333. }, 500)
  334. },
  335. showSidebar () {
  336. this.isSidebarVisible = !this.isSidebarVisible
  337. }
  338. }
  339. }
  340. </script>
  341. <style scoped>
  342. .logo-blurb {
  343. position: absolute;
  344. left: clamp(47% + 1rem, 51% - 2rem, 47%);
  345. font-size: clamp(10px, 1rem, 18px);
  346. color: white;
  347. top: clamp(20px + 0.25rem, 4rem + 0.25rem, 50px + 0.25rem);
  348. white-space: nowrap;
  349. }
  350. </style>