2023-09-14 22:30:20 +12:00
|
|
|
<script>
|
2025-06-20 23:26:06 +12:00
|
|
|
import CommonMixins from "../mixins/CommonMixins";
|
|
|
|
import { pagination } from "../stores/pagination";
|
2023-09-14 22:30:20 +12:00
|
|
|
|
|
|
|
export default {
|
|
|
|
mixins: [CommonMixins],
|
|
|
|
|
2025-06-20 23:26:06 +12:00
|
|
|
emits: ["loadMessages"],
|
2023-12-31 09:22:33 +13:00
|
|
|
|
2023-09-14 22:30:20 +12:00
|
|
|
data() {
|
|
|
|
return {
|
2025-06-20 23:26:06 +12:00
|
|
|
search: "",
|
|
|
|
};
|
2023-09-14 22:30:20 +12:00
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
$route() {
|
2025-06-20 23:26:06 +12:00
|
|
|
this.searchFromURL();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.searchFromURL();
|
2023-09-14 22:30:20 +12:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2024-06-22 13:27:00 +12:00
|
|
|
searchFromURL() {
|
2025-06-20 23:26:06 +12:00
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
this.search = urlParams.get("q") ? urlParams.get("q") : "";
|
2023-09-14 22:30:20 +12:00
|
|
|
},
|
|
|
|
|
2024-06-22 13:27:00 +12:00
|
|
|
doSearch(e) {
|
2025-06-20 23:26:06 +12:00
|
|
|
pagination.start = 0;
|
|
|
|
if (this.search === "") {
|
|
|
|
this.$router.push("/");
|
2023-09-14 22:30:20 +12:00
|
|
|
} else {
|
2025-06-20 23:26:06 +12:00
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const curr = urlParams.get("q");
|
|
|
|
if (curr && curr === this.search) {
|
|
|
|
pagination.start = 0;
|
|
|
|
this.$emit("loadMessages");
|
2023-12-31 09:22:33 +13:00
|
|
|
}
|
2024-06-02 16:07:26 +12:00
|
|
|
const p = {
|
2025-06-20 23:26:06 +12:00
|
|
|
q: this.search,
|
|
|
|
};
|
2024-06-02 16:07:26 +12:00
|
|
|
if (pagination.start > 0) {
|
2025-06-20 23:26:06 +12:00
|
|
|
p.start = pagination.start.toString();
|
2024-06-02 16:07:26 +12:00
|
|
|
}
|
2025-06-20 23:26:06 +12:00
|
|
|
if (pagination.limit !== pagination.defaultLimit) {
|
|
|
|
p.limit = pagination.limit.toString();
|
2024-06-02 16:07:26 +12:00
|
|
|
}
|
|
|
|
|
2025-06-20 23:26:06 +12:00
|
|
|
const params = new URLSearchParams(p);
|
|
|
|
this.$router.push("/search?" + params.toString());
|
2023-09-14 22:30:20 +12:00
|
|
|
}
|
|
|
|
|
2025-06-20 23:26:06 +12:00
|
|
|
e.preventDefault();
|
2023-09-14 22:30:20 +12:00
|
|
|
},
|
|
|
|
|
2024-06-22 13:27:00 +12:00
|
|
|
resetSearch() {
|
2025-06-20 23:26:06 +12:00
|
|
|
this.search = "";
|
|
|
|
this.$router.push("/");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2023-09-14 22:30:20 +12:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2025-06-20 23:26:06 +12:00
|
|
|
<form @submit="doSearch">
|
2023-09-22 15:06:03 +12:00
|
|
|
<div class="input-group flex-nowrap">
|
2023-09-14 22:30:20 +12:00
|
|
|
<div class="ms-md-2 d-flex border bg-body rounded-start flex-fill position-relative">
|
2025-06-20 23:26:06 +12:00
|
|
|
<input
|
|
|
|
v-model.trim="search"
|
|
|
|
type="text"
|
|
|
|
class="form-control border-0"
|
|
|
|
aria-label="Search"
|
|
|
|
placeholder="Search mailbox"
|
|
|
|
/>
|
|
|
|
<span v-if="search != ''" class="btn btn-link position-absolute end-0 text-muted" @click="resetSearch"
|
|
|
|
><i class="bi bi-x-circle"></i
|
|
|
|
></span>
|
2023-09-14 22:30:20 +12:00
|
|
|
</div>
|
|
|
|
<button class="btn btn-outline-secondary" type="submit">
|
|
|
|
<i class="bi bi-search"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</template>
|