mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-05 13:37:55 +00:00
- Adds pagination support for search. - Use composition API on all search related component. - Minor UI improvements. - Adds missing specs Loom video https://www.loom.com/share/5b01afa5c9204e7d97ff81b215621dde?sid=82ca6d22-ca8c-4d5e-8740-ba06ca4051ba
94 lines
2.0 KiB
Vue
94 lines
2.0 KiB
Vue
<script setup>
|
|
import { ref, useTemplateRef, onMounted, watch, nextTick } from 'vue';
|
|
import { useMessageFormatter } from 'shared/composables/useMessageFormatter';
|
|
import ReadMore from './ReadMore.vue';
|
|
|
|
const props = defineProps({
|
|
author: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
content: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
searchTerm: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
});
|
|
|
|
const { highlightContent } = useMessageFormatter();
|
|
|
|
const messageContainer = useTemplateRef('messageContainer');
|
|
const isOverflowing = ref(false);
|
|
|
|
const setOverflow = () => {
|
|
const wrap = messageContainer.value;
|
|
if (wrap) {
|
|
const message = wrap.querySelector('.message-content');
|
|
isOverflowing.value = message.offsetHeight > 150;
|
|
}
|
|
};
|
|
|
|
const escapeHtml = html => {
|
|
var text = document.createTextNode(html);
|
|
var p = document.createElement('p');
|
|
p.appendChild(text);
|
|
return p.innerText;
|
|
};
|
|
|
|
const prepareContent = (content = '') => {
|
|
const escapedText = escapeHtml(content);
|
|
return highlightContent(
|
|
escapedText,
|
|
props.searchTerm,
|
|
'searchkey--highlight'
|
|
);
|
|
};
|
|
|
|
onMounted(() => {
|
|
watch(() => {
|
|
return messageContainer.value;
|
|
}, setOverflow);
|
|
|
|
nextTick(setOverflow);
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<blockquote ref="messageContainer" class="message border-l-2 border-n-weak">
|
|
<p class="header">
|
|
<strong class="text-n-slate-11">
|
|
{{ author }}
|
|
</strong>
|
|
{{ $t('SEARCH.WROTE') }}
|
|
</p>
|
|
<ReadMore :shrink="isOverflowing" @expand="isOverflowing = false">
|
|
<div v-dompurify-html="prepareContent(content)" class="message-content" />
|
|
</ReadMore>
|
|
</blockquote>
|
|
</template>
|
|
|
|
<style scoped lang="scss">
|
|
.message {
|
|
@apply py-0 px-2 mt-2;
|
|
}
|
|
.message-content::v-deep p,
|
|
.message-content::v-deep li::marker {
|
|
@apply text-n-slate-11 mb-1;
|
|
}
|
|
|
|
.header {
|
|
@apply text-n-slate-11 mb-1;
|
|
}
|
|
|
|
.message-content {
|
|
@apply break-words text-n-slate-11;
|
|
}
|
|
|
|
.message-content::v-deep .searchkey--highlight {
|
|
@apply text-n-slate-12 text-sm font-semibold;
|
|
}
|
|
</style>
|