All files / movieapp/src/views MovieSearch.vue

0% Statements 0/6
100% Branches 0/0
0% Functions 0/3
0% Lines 0/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 87 88 89 90 91 92 93 94 95 96 97                                                                                                                                                                                                 
<template>
  <div class="container">
    <div class="row">
      <h1>Search movie</h1>
    </div>
    <div class="row">
      <form class="form-inline w-100" @submit.prevent="search()">
        <div class="col-4 offset-1">
          <div class="form-group">
            <label for="type_select">Select type </label>
            <select
              id="type_select"
              v-model="mediaType"
              class=" ml-2 custom-select"
            >
              <option value="movie">Movie</option>
              <option value="tv">TV Show</option>
            </select>
          </div>
        </div>
        <div class="col-6">
          <div class="input-group m-auto">
            <input
              v-model="searchQuery"
              type="text"
              class="form-control"
              placeholder="Search..."
              aria-describedby="search_button"
            />
            <div class="input-group-append">
              <button id="search_button" class="btn btn-primary" type="submit">
                Search
              </button>
            </div>
          </div>
        </div>
      </form>
    </div>
    <div class="row">
      <Loader />
      <div class="card-columns mt-4">
        <MovieCard v-for="movie in searchResult" :key="movie.id" :movie="movie">
          <div class="card-footer bg-white text-center">
            <AddToFavouritesButton :movie="movie" />
            <router-link
              :to="`/${(movie.media_type = mediaType)}/${movie.id}`"
              tag="button"
              class="btn btn-primary"
              >View details</router-link
            >
          </div>
        </MovieCard>
      </div>
    </div>
  </div>
</template>
 
<script>
import MovieCard from '@/components/MovieCard.vue'
import Loader from '@/components/Loader.vue'
import AddToFavouritesButton from '@/components/AddToFavouritesButton.vue'
 
export default {
  name: 'MovieSeach',
 
  components: {
    MovieCard,
    Loader,
    AddToFavouritesButton
  },
 
  data() {
    return {
      searchQuery: '',
      mediaType: ''
    }
  },
 
  computed: {
    searchResult() {
      return this.$store.getters.getSearchResult
    }
  },
 
  methods: {
    search() {
      this.$store.dispatch('fetchSearchResult', {
        type: this.mediaType,
        searchQuery: this.searchQuery
      })
    }
  }
}
</script>
 
<style scoped></style>