Results.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <transition name="accordeon" appear>
  3. <div
  4. v-if="opened"
  5. id="results"
  6. class="row"
  7. :class="{ loading: isloading }"
  8. >
  9. <header class="small-col-12 med-col-1 large-col-1">
  10. <h2>Resultats</h2>
  11. <span class="search-keys">{{ searchedKeys }}</span>
  12. <span v-if="resultsQuantity" class="results-count">{{ resultsCount }}</span>
  13. <v-select
  14. id="sorting"
  15. type="select"
  16. placeholder="trier par"
  17. append-to-body
  18. :calculate-position="dropDownMenuPos"
  19. :options="sortOptions"
  20. :value="sorting"
  21. @input="onSortingSelected"
  22. />
  23. </header>
  24. <section class="small-col-12 med-col-10 large-col-10 results-list">
  25. <div class="wrapper">
  26. <ul v-if="results.length">
  27. <li v-for="result in results" :key="result.uuid" class="result">
  28. <ResultItem :result="result" />
  29. </li>
  30. <infinite-loading
  31. v-if="offset < resultsQuantity.quantity"
  32. :identifier="isloading"
  33. @infinite="nextResultsBatch"
  34. />
  35. </ul>
  36. </div>
  37. </section>
  38. <nav class="col-1 tools">
  39. <span
  40. class="mdi mdi-close"
  41. title="close"
  42. @click.prevent="close"
  43. @keydown.enter.prevent="close"
  44. />
  45. </nav>
  46. </div>
  47. </transition>
  48. </template>
  49. <script>
  50. import { createPopper } from '@popperjs/core'
  51. import ResultItem from '../Content/ResultItem'
  52. import { mapState, mapActions, mapMutations } from 'vuex'
  53. export default {
  54. name: 'Results',
  55. components: {
  56. ResultItem
  57. },
  58. // data: () => ({
  59. // }),
  60. computed: {
  61. opened: {
  62. get () { return this.$store.state.Search.opened },
  63. set (value) { this.$store.commit('Search/setOpened', value) }
  64. },
  65. ...mapState({
  66. isloading: state => state.Search.isloading,
  67. searchedKeys: state => state.Search.searchedKeys,
  68. results: state => state.Search.results,
  69. resultsQuantity: state => state.Search.resultsQuantity,
  70. offset: state => state.Search.offset,
  71. sortOptions: state => state.Search.sortOptions,
  72. sorting: state => state.Search.sorting
  73. }),
  74. resultsCount () {
  75. return `${this.$store.state.Search.resultsQuantity.quantity} ${this.$store.state.Search.resultsQuantity.unit}`
  76. }
  77. },
  78. methods: {
  79. close () {
  80. console.log('clicked on close results')
  81. this.opened = false
  82. },
  83. ...mapMutations({
  84. setSorting: 'Search/setSorting'
  85. }),
  86. ...mapActions({
  87. nextResultsBatch: 'Search/nextResultsBatch',
  88. updateSearch: 'Search/updateSearch'
  89. }),
  90. dropDownMenuPos (dropdownList, component, { width }) {
  91. /**
  92. * We need to explicitly define the dropdown width since
  93. * it is usually inherited from the parent with CSS.
  94. */
  95. dropdownList.style.width = width
  96. /**
  97. * Here we position the dropdownList relative to the $refs.toggle Element.
  98. *
  99. * The 'offset' modifier aligns the dropdown so that the $refs.toggle and
  100. * the dropdownList overlap by 1 pixel.
  101. *
  102. * The 'toggleClass' modifier adds a 'drop-up' class to the Vue Select
  103. * wrapper so that we can set some styles for when the dropdown is placed
  104. * above.
  105. */
  106. const popper = createPopper(component.$refs.toggle, dropdownList, {
  107. placement: 'top',
  108. modifiers: [
  109. {
  110. name: 'offset',
  111. options: {
  112. offset: [0, -1]
  113. }
  114. },
  115. {
  116. name: 'toggleClass',
  117. enabled: true,
  118. phase: 'write',
  119. fn ({ state }) {
  120. component.$el.classList.toggle('drop-up', state.placement === 'top')
  121. }
  122. }]
  123. })
  124. /**
  125. * To prevent memory leaks Popper needs to be destroyed.
  126. * If you return function, it will be called just before dropdown is removed from DOM.
  127. */
  128. return () => popper.destroy()
  129. },
  130. onSortingSelected (o) {
  131. this.setSorting(o)
  132. this.updateSearch()
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. </style>