๐Ÿ“ฆ vladsosnov / movie-app

๐Ÿ“„ App.vue ยท 86 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86<template>
  <div class="app">
    <app-header
      :autoCompleteMoviesTitle="titlesToAutoComplete"
      @set-search-path="fetchSearchMoveis"
    />
    <search-result
      :movies="searchResult"
      @close-results="isSearchResultVisible"
    />
    <router-view />
    <app-footer />
  </div>
</template>

<script>
import axios from 'axios'

import AppHeader from './components/Shared/AppHeader'
import SearchResult from './components/SearchResult'
import AppFooter from './components/Shared/AppFooter'

export default {
  name: 'App',
  components: {
    AppHeader,
    SearchResult,
    AppFooter
  },
  data () {
    return {
      searchResult: {},
      titlesToAutoComplete: ''
    }
  },
  async mounted () {
    await this.fetchMoviesTitle()
  },
  computed: {
    searchMovies () {
      return this.$store.getters['searchMovies']
    }
  },
  methods: {
    async fetchMoviesTitle () {
      try {
        const fetchData = await axios.get(`${process.env.VUE_APP_API_URL}/discover/movie?sort_by=popularity.desc&api_key=${process.env.VUE_APP_API_KEY}`)
        this.titlesToAutoComplete = Object.values(fetchData.data.results).map(item => item.title)
      }
      catch (error) {
        console.log(error)
      }
    },
    async fetchSearchMoveis (searchMoviePath) {
      try {
        const fetchSeatchData = await axios.get(searchMoviePath)
        this.searchResult = {...fetchSeatchData.data.results}

        await this.$store.dispatch('setSearchMovies', this.searchResult)
      }
      catch (error) {
        console.log(error)
      }
    },
    isSearchResultVisible () {
      this.$store.commit('setSearchResultVisibility')
    }
  }
}
</script>

<style lang="scss">
@import url('./assets/normalize.css');
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700;900&display=swap');

html {
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
  background-color: #f2f2f2;

  @media (max-width: 1024px){
    font-size: 12px;
  }
}
</style>