Skip to content
Snippets Groups Projects
SearchProjects.vue 1.42 KiB
Newer Older
Florent Lavelle's avatar
dev
Florent Lavelle committed
<template>
Timothee P's avatar
Timothee P committed
  <div id="search-projects">
Florent Lavelle's avatar
dev
Florent Lavelle committed
    <input
      v-model="text"
      type="text"
      placeholder="Rechercher un projet ..."
Florent Lavelle's avatar
dev
Florent Lavelle committed
    >
  </div>
</template>

<script>
import _ from 'lodash';
import { mapMutations } from 'vuex';
Florent Lavelle's avatar
dev
Florent Lavelle committed

export default {
  name: 'SearchProjects',

  props: {
    searchFunction: {
      type: Function,
Timothee P's avatar
Timothee P committed
      default: () => { return {}; }
Timothee P's avatar
Timothee P committed
  },
Florent Lavelle's avatar
dev
Florent Lavelle committed

  data() {
    return {
      text: null
Timothee P's avatar
Timothee P committed
    };
Florent Lavelle's avatar
dev
Florent Lavelle committed
  },

  watch: {
    text: _.debounce(function(newValue) {
      this.$emit('loading', true);
      this.SET_CURRENT_PAGE(1);
      this.searchFunction(newValue)
Florent Lavelle's avatar
dev
Florent Lavelle committed
        .then(() => {
          this.$emit('loading', false);
Florent Lavelle's avatar
Florent Lavelle committed
        })
        .catch((err) => {
          if (err.message) this.$emit('loading', false);
Florent Lavelle's avatar
dev
Florent Lavelle committed
        });
    }, 100)
  },

  methods: {
    ...mapMutations('projects', [
      'SET_CURRENT_PAGE'
    ])
Florent Lavelle's avatar
dev
Florent Lavelle committed
  }
Timothee P's avatar
Timothee P committed
};
Florent Lavelle's avatar
dev
Florent Lavelle committed
</script>

<style lang="less" scoped>
#search-projects {
  display: block;
  height: 100%;
  min-height: 40px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  font-size: 1rem;
    display: block;
    width: 100%;
    height: 100%;
    text-align: left;
    color: #35495e;
    padding: 8px 40px 8px 8px;
Florent Lavelle's avatar
Florent Lavelle committed
    border: 1px solid #ced4da;
    font-size: 1rem;
Florent Lavelle's avatar
Florent Lavelle committed
    font-family: 'Roboto Condensed', Lato, 'Helvetica Neue', Arial, Helvetica, sans-serif !important;
  }
  input:focus {
    outline: none !important;
    box-shadow: 0 0 1px grey;
Florent Lavelle's avatar
dev
Florent Lavelle committed
}
</style>