1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-01-18 03:22:06 +02:00
mailpit/server/ui-src/components/SearchForm.vue
2024-06-02 16:07:26 +12:00

83 lines
1.8 KiB
Vue

<script>
import CommonMixins from '../mixins/CommonMixins'
import { pagination } from '../stores/pagination'
export default {
mixins: [CommonMixins],
emits: ['loadMessages'],
data() {
return {
search: ''
}
},
mounted() {
this.searchFromURL()
},
watch: {
$route() {
this.searchFromURL()
}
},
methods: {
searchFromURL: function () {
const urlParams = new URLSearchParams(window.location.search)
this.search = urlParams.get('q') ? urlParams.get('q') : ''
},
doSearch: function (e) {
pagination.start = 0
if (this.search == '') {
this.$router.push('/')
} else {
const urlParams = new URLSearchParams(window.location.search)
let curr = urlParams.get('q')
if (curr && curr == this.search) {
pagination.start = 0
this.$emit('loadMessages')
}
const p = {
q: this.search
}
if (pagination.start > 0) {
p.start = pagination.start.toString()
}
if (pagination.limit != pagination.defaultLimit) {
p.limit = pagination.limit.toString()
}
const params = new URLSearchParams(p)
this.$router.push('/search?' + params.toString())
}
e.preventDefault()
},
resetSearch: function () {
this.search = ''
this.$router.push('/')
}
}
}
</script>
<template>
<form v-on:submit="doSearch">
<div class="input-group flex-nowrap">
<div class="ms-md-2 d-flex border bg-body rounded-start flex-fill position-relative">
<input type="text" class="form-control border-0" aria-label="Search" v-model.trim="search"
placeholder="Search mailbox">
<span class="btn btn-link position-absolute end-0 text-muted" v-if="search != ''"
v-on:click="resetSearch"><i class="bi bi-x-circle"></i></span>
</div>
<button class="btn btn-outline-secondary" type="submit">
<i class="bi bi-search"></i>
</button>
</div>
</form>
</template>