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.

380 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 :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. color: 'red',
  109. mountains: [
  110. {
  111. slug: 'sluggy',
  112. title: 'titly'
  113. }
  114. ],
  115. isSidebarVisible: false,
  116. isPickerVisible: false,
  117. airports_orig: [],
  118. airports_dest: [],
  119. airportFetch_filterFormula: 'AND(Is_Origin=1,{IsCurrent-AsOrigin}=\'Yes\')',
  120. airportFetch_fields: [
  121. 'Airport_IATA',
  122. 'Icon_Url',
  123. 'Latitude_Deg',
  124. 'Longitude_Deg',
  125. 'Municipality',
  126. 'Airport_Name',
  127. 'Type',
  128. 'Search_Field'
  129. ],
  130. airportFetch_sort: '&sort[0][field]=Airport_IATA&sort[0][direction]=asc',
  131. selectedOrig: {
  132. iata: '',
  133. lat: '',
  134. long: '',
  135. icon: '',
  136. name: '',
  137. municipality: '',
  138. type: '',
  139. search: ''
  140. },
  141. selectedDest: {
  142. iata: '',
  143. lat: '',
  144. long: '',
  145. icon: '',
  146. name: '',
  147. municipality: '',
  148. type: '',
  149. search: ''
  150. },
  151. emptyAirport: {
  152. iata: '',
  153. lat: '',
  154. long: '',
  155. icon: '',
  156. name: '',
  157. municipality: '',
  158. type: '',
  159. search: ''
  160. }
  161. }
  162. },
  163. async fetch () {
  164. let offset
  165. let data = []
  166. while (true) {
  167. const offsetParam = offset ? `&offset=${offset}` : ''
  168. const res = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Airports_IATA?filterByFormula=${this.airportFetch_filterFormula}${this.airportFetch_fields_string}${this.airportFetch_sort}${offsetParam}`, {
  169. method: 'GET',
  170. headers: {
  171. 'Content-Type': 'application/x-www-form-urlencoded',
  172. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  173. }
  174. })
  175. const json = await res.json()
  176. offset = await json.offset
  177. data = [...data, ...await json.records]
  178. await console.log(data.length)
  179. if (await !offset) { break } // Were done let's stop this thing
  180. }
  181. // console.log('Look ma! I waited!') // Won't run till the while is done
  182. this.airports_orig = data.map((record) => {
  183. return {
  184. iata: record.fields.Airport_IATA,
  185. lat: record.fields.Latitude_Deg,
  186. long: record.fields.Longitude_Deg,
  187. icon: record.fields.Icon_Url,
  188. name: record.fields.Airport_Name,
  189. municipality: record.fields.Municipality,
  190. type: record.fields.Type,
  191. search: record.fields.Search_Field
  192. }
  193. })
  194. },
  195. computed: {
  196. airportFetch_fields_string () {
  197. const vm = this
  198. const array = vm.airportFetch_fields.map((field) => {
  199. return '&fields[]=' + field
  200. })
  201. return array.join('')
  202. },
  203. getCompliment () {
  204. const arr = [
  205. 'beautiful', 'gorgeous', 'breathtaking', 'wild', 'adventurous', 'amazing', 'majestic', 'uncharted', 'unpredictable', 'pristine', 'untamed'
  206. ]
  207. return arr[Math.floor(Math.random() * arr.length)]
  208. }
  209. },
  210. created () {
  211. // console.log(this.$route.path)
  212. if (this.$route && this.$route.params && this.$route.params.o) {
  213. this.fetchSingleAirport(this.$route.params.o, true)
  214. }
  215. if (this.$route && this.$route.params && this.$route.params.d) {
  216. this.fetchSingleAirport(this.$route.params.d, false)
  217. }
  218. },
  219. // watch: {
  220. // history (to, from) {
  221. // console.log(`routed from ${from} to ${to}`)
  222. // }
  223. // },
  224. methods: {
  225. makeOrigin (airport) {
  226. // console.log(airport)
  227. this.selectedOrig = { ...airport }
  228. this.selectedDest = { ...this.emptyAirport }
  229. history.pushState(
  230. {},
  231. null,
  232. '/go/' + encodeURIComponent(airport.iata)
  233. )
  234. this.fetchDestinations(airport.iata)
  235. },
  236. makeDestination (airport) {
  237. this.selectedDest = { ...airport }
  238. this.isPickerVisible = false
  239. history.pushState(
  240. {},
  241. null,
  242. '/go/' + encodeURIComponent(this.selectedOrig.iata) + '/' + encodeURIComponent(airport.iata)
  243. )
  244. },
  245. clearOrigin () {
  246. this.selectedOrig = { ...this.emptyAirport }
  247. this.selectedDest = { ...this.emptyAirport }
  248. history.pushState(
  249. {},
  250. null,
  251. '/go/'
  252. )
  253. },
  254. clearDestination () {
  255. this.selectedDest = { ...this.emptyAirport }
  256. history.pushState(
  257. {},
  258. null,
  259. '/go/' + encodeURIComponent(this.selectedOrig.iata)
  260. )
  261. },
  262. async fetchDestinations (iata) {
  263. const airportFetchDestfilterFormula = `AND(Is_Destination=1,{IsCurrent-AsDest}="Yes",(FIND("${iata}", Associated_Origin_Search)>0))`
  264. let offset
  265. let data = []
  266. while (true) {
  267. const offsetParam = offset ? `&offset=${offset}` : ''
  268. const res = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Airports_IATA?filterByFormula=${airportFetchDestfilterFormula}${this.airportFetch_fields_string}${this.airportFetch_sort}${offsetParam}`, {
  269. method: 'GET',
  270. headers: {
  271. 'Content-Type': 'application/x-www-form-urlencoded',
  272. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  273. }
  274. })
  275. const json = await res.json()
  276. offset = await json.offset
  277. data = [...data, ...await json.records]
  278. // await console.log(data.length)
  279. if (await !offset) { break } // Were done let's stop this thing
  280. }
  281. // console.log('Look ma! I waited!') // Won't run till the while is done
  282. this.airports_dest = data.map((record) => {
  283. return {
  284. iata: record.fields.Airport_IATA,
  285. lat: record.fields.Latitude_Deg,
  286. long: record.fields.Longitude_Deg,
  287. icon: record.fields.Icon_Url,
  288. name: record.fields.Airport_Name,
  289. municipality: record.fields.Municipality,
  290. type: record.fields.Type,
  291. search: record.fields.Search_Field
  292. }
  293. })
  294. },
  295. async fetchSingleAirport (iata, isOrig) {
  296. const airportFetchFilterFormula =
  297. isOrig
  298. ? `AND(Is_Origin=1,{IsCurrent-AsOrigin}="Yes",Airport_IATA="${iata}")`
  299. : `AND(Is_Destination=1,{IsCurrent-AsDest}="Yes",Airport_IATA="${iata}")`
  300. const response = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Airports_IATA?filterByFormula=${airportFetchFilterFormula}${this.airportFetch_fields_string}`, {
  301. method: 'GET',
  302. headers: {
  303. 'Content-Type': 'application/x-www-form-urlencoded',
  304. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  305. }
  306. })
  307. const mapData = await response.json()
  308. const thisAirport = {
  309. iata: mapData.records[0].fields.Airport_IATA,
  310. lat: mapData.records[0].fields.Latitude_Deg,
  311. long: mapData.records[0].fields.Longitude_Deg,
  312. icon: mapData.records[0].fields.Icon_Url,
  313. name: mapData.records[0].fields.Airport_Name,
  314. municipality: mapData.records[0].fields.Municipality,
  315. type: mapData.records[0].fields.Type,
  316. search: mapData.records[0].fields.Search_Field
  317. }
  318. switch (isOrig) {
  319. case true:
  320. this.selectedOrig = { ...thisAirport }
  321. this.fetchDestinations(thisAirport.iata)
  322. break
  323. case false:
  324. this.selectedDest = { ...thisAirport }
  325. break
  326. default:
  327. break
  328. }
  329. },
  330. showPicker () {
  331. const vm = this
  332. vm.isPickerVisible = !vm.isPickerVisible
  333. setTimeout(function () {
  334. vm.$refs.mapComponent.resize()
  335. }, 500)
  336. },
  337. showSidebar () {
  338. this.isSidebarVisible = !this.isSidebarVisible
  339. }
  340. }
  341. }
  342. </script>
  343. <style>
  344. .logo-blurb {
  345. position: absolute;
  346. left: min(400px, 47%);
  347. font-size: clamp(10px, 1rem, 18px);
  348. color: white;
  349. top: clamp(20px + 0.25rem, 4rem + 0.25rem, 50px + 0.25rem);
  350. white-space: nowrap;
  351. }
  352. </style>