Skip to content
Snippets Groups Projects
SearchProjects.vue 1.08 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="search"
      placeholder="Rechercher..."
    >
  </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);
        });
    }, 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 {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  input {
    width: 100%;
    height: 98%;
    text-align: left;
    color: #35495e;
    padding: 8px 40px 0 8px;
    border-radius: 5px;
    border: 1px solid #e8e8e8;
    font-size: 14px;
  }
Florent Lavelle's avatar
dev
Florent Lavelle committed
}
</style>