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.

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