@@ -3,7 +3,8 @@ aside: false
3
3
---
4
4
5
5
<script setup >
6
- import { ref , onMounted , computed } from ' vue'
6
+ import { ref , onMounted , computed , watch } from ' vue'
7
+ import debounce from ' lodash.debounce'
7
8
8
9
const SORT_OPTIONS = {
9
10
sort: [" year" , " author" , " title" , " conference" ],
@@ -19,6 +20,9 @@ const sorting = ref({
19
20
20
21
const previousSort = ref (" author" )
21
22
23
+ const search = ref (" " )
24
+ const searchOpen = ref (false )
25
+
22
26
// helper
23
27
function sortByAuthor (a , b , order ) {
24
28
const aFirstAuthor = a .authors .split (' ,' )[0 ]
@@ -29,7 +33,13 @@ function sortByAuthor(a, b, order) {
29
33
}
30
34
31
35
const sortedPublications = computed (() => {
32
- return [... publications .value ].sort ((a , b ) => {
36
+ // filter search string first
37
+ let filteredPubs = [... publications .value ]
38
+ if (search .value !== " " ) {
39
+ filteredPubs = filteredPubs .filter ((p ) => p .title .toLowerCase ().includes (search .value .toLowerCase ()))
40
+ }
41
+
42
+ return filteredPubs .sort ((a , b ) => {
33
43
const sortKey = sorting .value .sort
34
44
const order = sorting .value .ascending ? 1 : - 1
35
45
@@ -65,10 +75,18 @@ function handleSortToggle(v) {
65
75
}
66
76
}
67
77
78
+ function openSearchBar () {
79
+ searchOpen .value = true
80
+ }
81
+
68
82
onMounted (async () => {
69
83
const response = await fetch (' /assets/publications.json' )
70
84
publications .value = await response .json ()
71
85
})
86
+
87
+ watch (search, debounce (() => {
88
+
89
+ }, 500 ))
72
90
</script >
73
91
74
92
<style >
@@ -140,6 +158,26 @@ onMounted(async () => {
140
158
</v-icon>
141
159
<span v-else class="v-icon-placeholder"></span>
142
160
</v-btn>
161
+ <v-menu
162
+ :close-on-content-click="false"
163
+ location="bottom"
164
+ >
165
+ <template v-slot:activator="{ props }">
166
+ <v-btn v-bind="props" icon="mdi-magnify" @click="() => {
167
+ sorting.sort = previousSort // reset sorting to previous to ignore the click action
168
+ openSearchBar()
169
+ }">
170
+ </v-btn>
171
+ </template>
172
+ <v-card min-width="300">
173
+ <v-text-field
174
+ v-model="search"
175
+ hide-details
176
+ label="Search"
177
+ >
178
+ </v-text-field>
179
+ </v-card>
180
+ </v-menu>
143
181
</v-btn-toggle >
144
182
</v-row >
145
183
0 commit comments