2019-12-31 16:21:34 +00:00
|
|
|
<template>
|
|
|
|
<form :class="['message-search', {opened: searchOpened}]" @submit.prevent="searchMessages">
|
|
|
|
<div class="input-wrapper">
|
|
|
|
<input
|
|
|
|
ref="searchInputField"
|
2021-04-12 22:11:43 +00:00
|
|
|
v-model="searchInput"
|
2019-12-31 16:21:34 +00:00
|
|
|
type="text"
|
|
|
|
name="search"
|
|
|
|
class="input"
|
2020-03-07 11:01:07 +00:00
|
|
|
placeholder="Search messages…"
|
2019-12-31 16:21:34 +00:00
|
|
|
@blur="closeSearch"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<button
|
2021-04-12 22:55:57 +00:00
|
|
|
v-if="!onSearchPage"
|
2019-12-31 16:21:34 +00:00
|
|
|
class="search"
|
|
|
|
type="button"
|
|
|
|
aria-label="Search messages in this channel"
|
2020-01-04 18:03:56 +00:00
|
|
|
@mousedown.prevent="toggleSearch"
|
2019-12-31 16:21:34 +00:00
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
2020-03-07 12:56:50 +00:00
|
|
|
<style>
|
|
|
|
form.message-search {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
|
|
|
form.message-search .input-wrapper {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
|
|
|
form.message-search input {
|
|
|
|
width: 100%;
|
|
|
|
height: auto !important;
|
|
|
|
margin: 7px 0;
|
|
|
|
border: 0;
|
|
|
|
color: inherit;
|
2021-04-12 22:55:57 +00:00
|
|
|
background-color: #fafafa;
|
2020-03-07 12:56:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
form.message-search input::placeholder {
|
2021-04-12 22:55:57 +00:00
|
|
|
color: rgba(0, 0, 0, 0.35);
|
2020-03-07 12:56:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@media (min-width: 480px) {
|
|
|
|
form.message-search input {
|
|
|
|
min-width: 140px;
|
|
|
|
}
|
|
|
|
|
|
|
|
form.message-search input:focus {
|
|
|
|
min-width: 220px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 22:55:57 +00:00
|
|
|
form.message-search .input-wrapper {
|
|
|
|
position: absolute;
|
|
|
|
top: 45px;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
z-index: 1;
|
|
|
|
height: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
background: var(--window-bg-color);
|
|
|
|
}
|
2020-03-07 12:56:50 +00:00
|
|
|
|
2021-04-12 22:55:57 +00:00
|
|
|
form.message-search .input-wrapper input {
|
|
|
|
margin: 7px;
|
|
|
|
}
|
2020-03-07 12:56:50 +00:00
|
|
|
|
2021-04-12 22:55:57 +00:00
|
|
|
form.message-search.opened .input-wrapper {
|
|
|
|
height: 50px;
|
|
|
|
}
|
2020-03-07 12:56:50 +00:00
|
|
|
|
2021-04-12 22:55:57 +00:00
|
|
|
#chat form.message-search button {
|
|
|
|
display: flex;
|
|
|
|
color: #607992;
|
2020-03-07 12:56:50 +00:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2019-12-31 16:21:34 +00:00
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: "MessageSearchForm",
|
|
|
|
props: {
|
|
|
|
network: Object,
|
|
|
|
channel: Object,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
searchOpened: false,
|
|
|
|
searchInput: "",
|
|
|
|
};
|
|
|
|
},
|
2021-04-12 22:55:57 +00:00
|
|
|
computed: {
|
|
|
|
onSearchPage() {
|
|
|
|
return this.$route.name === "SearchResults";
|
|
|
|
},
|
|
|
|
},
|
2021-04-12 22:11:43 +00:00
|
|
|
watch: {
|
|
|
|
"$route.query.q"() {
|
|
|
|
this.searchInput = this.$route.query.q;
|
2019-12-31 16:21:34 +00:00
|
|
|
},
|
2021-04-12 22:11:43 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.searchInput = this.$route.query.q;
|
2021-04-12 22:55:57 +00:00
|
|
|
this.searchOpened = this.onSearchPage;
|
2021-05-06 01:24:20 +00:00
|
|
|
|
|
|
|
if (!this.searchInput) {
|
|
|
|
this.$refs.searchInputField.focus();
|
|
|
|
}
|
2021-04-12 22:11:43 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2019-12-31 16:21:34 +00:00
|
|
|
closeSearch() {
|
2021-04-12 22:55:57 +00:00
|
|
|
if (!this.onSearchPage) {
|
|
|
|
this.searchOpened = false;
|
|
|
|
}
|
2019-12-31 16:21:34 +00:00
|
|
|
},
|
2020-01-04 18:03:56 +00:00
|
|
|
toggleSearch() {
|
2019-12-31 16:21:34 +00:00
|
|
|
if (this.searchOpened) {
|
2020-01-04 18:03:56 +00:00
|
|
|
this.$refs.searchInputField.blur();
|
|
|
|
return;
|
2019-12-31 16:21:34 +00:00
|
|
|
}
|
2020-01-04 18:03:56 +00:00
|
|
|
|
|
|
|
this.searchOpened = true;
|
|
|
|
this.$refs.searchInputField.focus();
|
2019-12-31 16:21:34 +00:00
|
|
|
},
|
|
|
|
searchMessages(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (!this.searchInput) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-12 22:45:15 +00:00
|
|
|
this.$router
|
|
|
|
.push({
|
|
|
|
name: "SearchResults",
|
|
|
|
params: {
|
2021-04-29 23:07:31 +00:00
|
|
|
id: this.channel.id,
|
2021-04-12 22:45:15 +00:00
|
|
|
},
|
|
|
|
query: {
|
|
|
|
q: this.searchInput,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
if (err.name === "NavigationDuplicated") {
|
|
|
|
// Search for the same query again
|
|
|
|
this.$root.$emit("re-search");
|
|
|
|
}
|
|
|
|
});
|
2019-12-31 16:21:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|