|
1 | 1 | <template> |
2 | 2 | <div :class="isOpen ? '' : 'hidden overflow-hidden lg:block'"> |
| 3 | + <div class="mx-8 pt-6"> |
| 4 | + <SearchInput placeholder="Search Users..." @on-search="onSearch" /> |
| 5 | + </div> |
3 | 6 | <div class="sort-section"> |
4 | 7 | <h6 class="text-xs font-bold pb-2">Period:</h6> |
5 | 8 | <div class="flex lg:flex-col"> |
@@ -92,24 +95,65 @@ export default { |
92 | 95 | getPeriod: 'getPeriod', |
93 | 96 | getShow: 'getShow', |
94 | 97 | getSortBy: 'getSortBy', |
| 98 | + getUserSearchTerm: 'getUserSearchTerm', |
95 | 99 | }), |
96 | 100 | }, |
97 | 101 | methods: { |
98 | 102 | async onSortByChanged(sortBy) { |
| 103 | + this.$store.commit('setCurrentPage', 1) |
99 | 104 | this.$store.commit('setSortBy', sortBy) |
100 | | - const response = await this.$axios.get( |
101 | | - `v1/users?sort_by=${sortBy}&page=${this.getCurrentPage}&period=${this.getPeriod}&contributors=${this.getShow}` |
102 | | - ) |
103 | | - this.$store.commit('setUsers', response.data.users) |
| 105 | +
|
| 106 | + if (this.getUserSearchTerm) { |
| 107 | + const response = await this.$axios.get( |
| 108 | + `v1/users?sort_by=${sortBy}&page=${this.getCurrentPage}&period=${this.getPeriod}&contributors=${this.getShow}&search=${this.getUserSearchTerm}`, |
| 109 | + ) |
| 110 | + this.$store.commit('setUsers', response.data.users) |
| 111 | + this.$store.commit('setPageCount', response.data.totalPages) |
| 112 | + } else { |
| 113 | + const response = await this.$axios.get( |
| 114 | + `v1/users?sort_by=${sortBy}&page=${this.getCurrentPage}&period=${this.getPeriod}&contributors=${this.getShow}`, |
| 115 | + ) |
| 116 | +
|
| 117 | + this.$store.commit('setUsers', response.data.users) |
| 118 | + this.$store.commit('setPageCount', response.data.totalPages) |
| 119 | + } |
104 | 120 | }, |
105 | 121 | async onShowChanged(show) { |
106 | 122 | this.$store.commit('setCurrentPage', 1) |
107 | | - const response = await this.$axios.get( |
108 | | - `v1/users?sort_by=${this.getSortBy}&page=${this.getCurrentPage}&period=${this.getPeriod}&contributors=${show}` |
109 | | - ) |
110 | 123 | this.$store.commit('setShow', show) |
111 | | - this.$store.commit('setUsers', response.data.users) |
112 | | - this.$store.commit('setPageCount', response.data.totalPages) |
| 124 | + if (this.getUserSearchTerm) { |
| 125 | + const response = await this.$axios.get( |
| 126 | + `v1/users?sort_by=${this.getSortBy}&page=${this.getCurrentPage}&period=${this.getPeriod}&contributors=${show}&search=${this.getUserSearchTerm}`, |
| 127 | + ) |
| 128 | +
|
| 129 | + this.$store.commit('setUsers', response.data.users) |
| 130 | + this.$store.commit('setPageCount', response.data.totalPages) |
| 131 | + } else { |
| 132 | + const response = await this.$axios.get( |
| 133 | + `v1/users?sort_by=${this.getSortBy}&page=${this.getCurrentPage}&period=${this.getPeriod}&contributors=${show}`, |
| 134 | + ) |
| 135 | +
|
| 136 | + this.$store.commit('setUsers', response.data.users) |
| 137 | + this.$store.commit('setPageCount', response.data.totalPages) |
| 138 | + } |
| 139 | + }, |
| 140 | + async onSearch(searchTerm) { |
| 141 | + this.$store.commit('setCurrentPage', 1) |
| 142 | + if (searchTerm) { |
| 143 | + const response = await this.$axios.get( |
| 144 | + `v1/users?sort_by=${this.getSortBy}&page=${this.getCurrentPage}&period=${this.getPeriod}&contributors=${this.getShow}&search=${searchTerm}`, |
| 145 | + ) |
| 146 | + this.$store.commit('setUserSearchTerm', searchTerm) |
| 147 | + this.$store.commit('setUsers', response.data.users) |
| 148 | + this.$store.commit('setPageCount', response.data.totalPages) |
| 149 | + } else { |
| 150 | + const response = await this.$axios.get( |
| 151 | + `v1/users?sort_by=${this.getSortBy}&page=${this.getCurrentPage}&period=${this.getPeriod}&contributors=${this.getShow}`, |
| 152 | + ) |
| 153 | + this.$store.commit('setUserSearchTerm', '') |
| 154 | + this.$store.commit('setUsers', response.data.users) |
| 155 | + this.$store.commit('setPageCount', response.data.totalPages) |
| 156 | + } |
113 | 157 | }, |
114 | 158 | }, |
115 | 159 | } |
|
0 commit comments