-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add SearchBar to tile, Create Search Page for searching Project…
…s by Name fixes: #13 , part 1 (projects)
- Loading branch information
Showing
4 changed files
with
194 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<template> | ||
<input type="search" class="searchbar-small" placeholder="Search Projects" v-model="searchQuery" | ||
@change="initialSearch()" /> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'searchbar', | ||
data() { | ||
return { | ||
searchQuery: '' | ||
} | ||
}, | ||
methods: { | ||
initialSearch() { | ||
this.$router.push({ path: '/search', query: { searchQuery: this.searchQuery } }) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
.searchbar-small { | ||
padding: 10px; | ||
border: 1px solid #e8e8e8; | ||
border-radius: 7px; | ||
margin-top: 16px; | ||
float: right; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<template> | ||
<div class="container"> | ||
<div class="searchbar-container"> | ||
<input ref="searchbar" type="search" class="searchbar-fullsize" placeholder="Search Projects" | ||
v-model="query" @input="debounceInput" /> | ||
|
||
<md-button class="md-icon-button md-fab md-secondary search-button" @click="search()"> | ||
<md-icon>search</md-icon> | ||
</md-button> | ||
</div> | ||
|
||
<div class="results-container md-layout" v-if="results.length"> | ||
<router-link :to="`/${result.project}`" class="result" v-for="result of results" :key="result.project"> | ||
<div class="md-title" v-html="result.displayHtml"></div> | ||
</router-link> | ||
</div> | ||
|
||
<div class="no-results" v-else> | ||
<div v-if="query.length"> | ||
No results for "{{ query }}" | ||
</div> | ||
<div v-else> | ||
No results | ||
</div> | ||
</div> | ||
|
||
<md-button to="/" class="home-button md-fab md-primary"> | ||
<md-icon>home</md-icon> | ||
<md-tooltip md-direction="left">docs overview</md-tooltip> | ||
</md-button> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import _ from 'lodash'; | ||
import ProjectRepository from '@/repositories/ProjectRepository' | ||
export default { | ||
name: 'search', | ||
data() { | ||
return { | ||
query: this.$route.query.searchQuery ?? '', | ||
projects: [], | ||
results: [] | ||
} | ||
}, | ||
async created() { | ||
document.title = "Search | docat" | ||
this.projects = await ProjectRepository.get() | ||
this.search() | ||
}, | ||
mounted() { | ||
this.$refs.searchbar.focus() | ||
}, | ||
methods: { | ||
debounceInput: _.debounce(function (e) { | ||
this.query = e.target.value | ||
this.$router.replace({ query: { searchQuery: this.query } }) | ||
this.search(); | ||
}, 500), | ||
search() { | ||
if(!this.query) { | ||
this.results = [] | ||
return | ||
} | ||
this.results = this.projects.filter(p => p.toLowerCase().includes(this.query.toLowerCase())).map(p => { | ||
return { | ||
project: p, | ||
displayHtml: this.escapeHtml(p).replace(this.query, `<span class="highlighted">${this.query}</span>`) | ||
} | ||
} | ||
); | ||
}, | ||
escapeHtml(text) { | ||
return text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", '''); | ||
}, | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
.container{ | ||
padding-top: 16px; //margin in searchbar-container creates scroll | ||
} | ||
.search-button { | ||
border-radius: 0px; | ||
border-bottom-right-radius: 7px; | ||
border-top-right-radius: 7px; | ||
margin: 0px; | ||
box-shadow: none; | ||
} | ||
.searchbar-container { | ||
display: flex; | ||
flex-direction: row; | ||
width: 80%; | ||
margin: 0 10% 0 10%; | ||
} | ||
.searchbar-fullsize { | ||
padding: 10px; | ||
border: 1px solid #e8e8e8; | ||
border-radius: 7px; | ||
border-top-right-radius: 0px; | ||
border-bottom-right-radius: 0px; | ||
font-size: 140%; | ||
width: 100%; | ||
} | ||
.results-container { | ||
margin: 16px 10% 0 10%; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
.result { | ||
width: 100%; | ||
height: 50px; | ||
margin: 10px 0; | ||
padding: 12px; | ||
border-radius: 7px; | ||
font-size: 120%; | ||
background-color: #e8e8e8; | ||
} | ||
.highlighted { | ||
background-color: yellow; | ||
} | ||
.home-button { | ||
position: absolute; | ||
bottom: 32px; | ||
right: 50px; | ||
border-radius: 7px; | ||
margin-right: -1px; | ||
height: 52px; | ||
margin-top: 4px; | ||
box-shadow: none; | ||
border: 1px solid rgba(0, 0, 0, 0.42); | ||
} | ||
.no-results { | ||
text-align: center; | ||
font-size: 140%; | ||
margin-top: 16px; | ||
} | ||
</style> |