Skip to content

Commit e3f5a78

Browse files
committed
Add search feature to publications
1 parent 6b2e326 commit e3f5a78

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

pages/publications.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ aside: false
33
---
44

55
<script setup>
6-
import { ref, onMounted, computed } from 'vue'
6+
import { ref, onMounted, computed, watch } from 'vue'
7+
import debounce from 'lodash.debounce'
78

89
const SORT_OPTIONS = {
910
sort: ["year", "author", "title", "conference"],
@@ -19,6 +20,9 @@ const sorting = ref({
1920

2021
const previousSort = ref("author")
2122

23+
const search = ref("")
24+
const searchOpen = ref(false)
25+
2226
// helper
2327
function sortByAuthor(a, b, order) {
2428
const aFirstAuthor = a.authors.split(',')[0]
@@ -29,7 +33,13 @@ function sortByAuthor(a, b, order) {
2933
}
3034

3135
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) => {
3343
const sortKey = sorting.value.sort
3444
const order = sorting.value.ascending ? 1 : -1
3545

@@ -65,10 +75,18 @@ function handleSortToggle(v) {
6575
}
6676
}
6777

78+
function openSearchBar() {
79+
searchOpen.value = true
80+
}
81+
6882
onMounted(async () => {
6983
const response = await fetch('/assets/publications.json')
7084
publications.value = await response.json()
7185
})
86+
87+
watch(search, debounce(() => {
88+
89+
}, 500))
7290
</script>
7391

7492
<style>
@@ -140,6 +158,26 @@ onMounted(async () => {
140158
</v-icon>
141159
<span v-else class="v-icon-placeholder"></span>
142160
</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>
143181
</v-btn-toggle>
144182
</v-row>
145183

0 commit comments

Comments
 (0)