Skip to content

Commit

Permalink
Add live search
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorChristie committed Feb 26, 2020
1 parent 6934ba7 commit 360b283
Show file tree
Hide file tree
Showing 22 changed files with 38 additions and 54 deletions.
3 changes: 1 addition & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"clipboard": "^2.0.4",
"js-base64": "^2.5.1",
"lodash.clonedeep": "^4.5.0",
"lodash.debounce": "^4.0.8",
"material-design-icons": "^3.0.1",
"moment": "^2.24.0",
"normalize.css": "^8.0.1",
Expand Down
33 changes: 17 additions & 16 deletions frontend/src/components/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
<div id="result" ref="result">
<div>
<template v-if="isEmpty">
<p>{{ text }}</p>

<template v-if="value.length === 0">
<h3>{{ $t('search.types') }}</h3>
<div class="boxes">
Expand All @@ -53,10 +51,11 @@
<router-link @click.native="close" :to="'./' + s.path">
<i v-if="s.dir" class="material-icons">folder</i>
<i v-else class="material-icons">insert_drive_file</i>
<span>./{{ s.path }}</span>
<span>{{ s.path }}</span>
</router-link>
</li>
</ul>
<p v-show="noResults">{{ $t('search.noResultsFound') }}</p>
</div>
<p id="renew">
<i class="material-icons spin">autorenew</i>
Expand All @@ -69,6 +68,7 @@
import { mapState, mapGetters, mapMutations } from "vuex"
import url from "@/utils/url"
import { search } from "@/api"
import debounce from 'lodash.debounce'
var boxes = {
image: { label: "images", icon: "insert_photo" },
Expand All @@ -87,7 +87,8 @@ export default {
results: [],
reload: false,
resultsCount: 50,
scrollable: null
scrollable: null,
noResults: false
}
},
watch: {
Expand All @@ -111,7 +112,7 @@ export default {
}
},
value () {
if (this.results.length) {
if (this.value === '') {
this.reset()
}
}
Expand All @@ -125,13 +126,6 @@ export default {
isEmpty() {
return this.results.length === 0
},
text() {
if (this.ongoing) {
return ""
}
return this.value === '' ? this.$t("search.typeToSearch") : this.$t("search.pressToSearch")
},
filteredResults () {
return this.results.slice(0, this.resultsCount)
}
Expand Down Expand Up @@ -165,21 +159,28 @@ export default {
return
}
this.results.length = 0
this.keyupDebounced()
},
keyupDebounced: debounce(async function() {
await this.submit();
}, 2000),
init (string) {
this.value = `${string} `
this.$refs.input.focus()
},
reset () {
this.ongoing = false
this.noResults = false
this.resultsCount = 50
this.results = []
},
async submit(event) {
event.preventDefault()
if (event) {
event.preventDefault()
}
if (this.value === '') {
this.reset()
return
}
Expand All @@ -189,10 +190,10 @@ export default {
}
this.ongoing = true
this.results = await search(path, this.value)
this.ongoing = false
this.noResults = this.results.length === 0 && this.value.length !== 0
}
}
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/css/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ header .search-button {

#search.active #result {
padding: .5em;
padding-top: 2em;
height: calc(100% - 4em);
}

Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "الأنواع",
"video": "فيديوهات",
"search": "البحث...",
"typeToSearch": "Type to search...",
"pressToSearch": "Press enter to search..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Typen",
"video": "Video",
"search": "Suche...",
"typeToSearch": "Tippe um zu suchen...",
"pressToSearch": "Drücken sie Enter um zu suchen..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@
"types": "Types",
"video": "Video",
"search": "Search...",
"typeToSearch": "Type to search...",
"pressToSearch": "Press enter to search..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Tipos",
"video": "Vídeo",
"search": "Buscar...",
"typeToSearch": "Escribe para realizar una busqueda...",
"pressToSearch": "Presiona enter para buscar..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Types",
"video": "Video",
"search": "Recherche en cours...",
"typeToSearch": "Type to search...",
"pressToSearch": "Press enter to search..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/is.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Skrárgerðir",
"video": "Myndbönd",
"search": "Leita...",
"typeToSearch": "Skrifaðu til að leita...",
"pressToSearch": "Ýttu á Enter til að leita..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Tipi",
"video": "Video",
"search": "Cerca...",
"typeToSearch": "Type to search...",
"pressToSearch": "Press enter to search..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "種類",
"video": "ビデオ",
"search": "検索...",
"typeToSearch": "Type to search...",
"pressToSearch": "Press enter to search..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Types",
"video": "비디오",
"search": "검색...",
"typeToSearch": "검색어 입력...",
"pressToSearch": "검색하려면 엔터를 입력하세요"
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/nl-be.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Types",
"video": "Video",
"search": "Zoeken...",
"typeToSearch": "Typ om te zoeken...",
"pressToSearch": "Druk op enter om te zoeken..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "Arabisch",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Typy",
"video": "Video",
"search": "Szukaj...",
"typeToSearch": "Type to search...",
"pressToSearch": "Press enter to search..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Tipos",
"video": "Vídeos",
"search": "Pesquise...",
"typeToSearch": "Type to search...",
"pressToSearch": "Press enter to search..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Tipos",
"video": "Vídeos",
"search": "Pesquisar...",
"typeToSearch": "Escrever para pesquisar...",
"pressToSearch": "Tecla Enter para pesquisar..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "Árabe",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Tipuri",
"video": "Video",
"search": "Caută...",
"typeToSearch": "Scrie pentru a căuta...",
"pressToSearch": "Apasă enter pentru a căuta..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Типы",
"video": "Видео",
"search": "Поиск...",
"typeToSearch": "Type to search...",
"pressToSearch": "Press enter to search..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/sv-se.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "Typ",
"video": "Video",
"search": "Sök...",
"typeToSearch": "Skriv för att söka....",
"pressToSearch": "Tryck på enter för att söka..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "类型",
"video": "视频",
"search": "搜索...",
"typeToSearch": "输入搜索...",
"pressToSearch": "回车搜索..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/i18n/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"types": "類型",
"video": "影片",
"search": "搜尋...",
"typeToSearch": "Type to search...",
"pressToSearch": "Press enter to search..."
"noResultsFound": "No results found..."
},
"languages": {
"ar": "العربية",
Expand Down

0 comments on commit 360b283

Please sign in to comment.