From c953d87eecda6a92dfdabc78ff4152ba2c0d8537 Mon Sep 17 00:00:00 2001 From: Baghi Date: Wed, 16 Apr 2025 17:52:36 +0330 Subject: [PATCH] clear button serach --- assets/haditha/font-icons/close-circle.svg | 5 ++ components/haditha/AutoComplation.vue | 69 +++++++++++++++++----- pages/haditha/search/index.vue | 4 +- 3 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 assets/haditha/font-icons/close-circle.svg diff --git a/assets/haditha/font-icons/close-circle.svg b/assets/haditha/font-icons/close-circle.svg new file mode 100644 index 0000000..a92e4d6 --- /dev/null +++ b/assets/haditha/font-icons/close-circle.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/components/haditha/AutoComplation.vue b/components/haditha/AutoComplation.vue index c184877..f43c75f 100644 --- a/components/haditha/AutoComplation.vue +++ b/components/haditha/AutoComplation.vue @@ -57,6 +57,7 @@ const search_type = ref("normal"); const type_key = ref("hadith"); const typeModelValue = ref("normal"); const typeModelValueFa = ref(""); +const showclearButton = ref(false); // If you want to share state across multiple components, // you can use the same key in useState. Nuxt will ensure @@ -168,17 +169,27 @@ const clearSimilar = () => { // const onUpdateModel = (newVal: boolean | InputMenuItem | any) => { // console.info("onUpdateModel", newVal); // }; +const searchButtonIcon = computed(() => { + return showclearButton.value ? "i-lucide-x" : "i-haditha-search"; +}); + +const handleSearchClearButton = ()=>{ + showclearButton.value = true; + sendQuery(); +} const onKeyDown = () => { - clearTimeout(typingTimer.value); -}; -const onKeyUp = () => { - clearTimeout(typingTimer.value); - typingTimer.value = setTimeout(() => { - if (props.autoRedirection) sendQuery(); - }, doneTypingInterval.value); + showclearButton.value = false; + // clearTimeout(typingTimer.value); }; +// const onKeyUp = () => { +// clearTimeout(typingTimer.value); +// typingTimer.value = setTimeout(() => { +// if (props.autoRedirection) sendQuery(); +// }, doneTypingInterval.value); +// }; + const setType = (type: string) => { search_type.value = type; sendQuery(); @@ -225,11 +236,6 @@ const sendQuery = async (payload = {}) => { .postRequest(url, payload) .then((res) => { // pass res and search query to the parent. - emit("response-ready", { - res: res, - searchQuery: searchTerm.value, - disableAutoRedirect: true, - }); loading.value = false; // check if search term is not empty @@ -238,6 +244,32 @@ const sendQuery = async (payload = {}) => { // close the history dropdown menu open.value = false; + + + // show clear button + if (showclearButton.value) { + searchTerm.value = ""; + + emit("response-ready", { + res: { + hits:{ + total:0, + hits:[] + } + }, + searchQuery: searchTerm.value, + disableAutoRedirect: true, + }); + } else { + emit("response-ready", { + res: res, + searchQuery: searchTerm.value, + disableAutoRedirect: true, + }); + } + + showclearButton.value = !showclearButton.value; + // store search phrase useStorage("searchPhrase", searchTerm.value); }) @@ -405,7 +437,6 @@ onMounted(() => { @blur="open = false" @change="sendQuery" @keydown="onKeyDown" - @keyup="onKeyUp" @keydown.enter="sendQuery" > @@ -414,8 +445,9 @@ onMounted(() => { @@ -765,6 +797,13 @@ onMounted(() => { ); */ } } + .close-mode { + background: #f0f1f4; + color: #000; /* رنگ خاکستری */ + &:hover { + background: #e0e0e0; /* رنگ خاکستری */ + } + } .haditha-search-input { z-index: 0; diff --git a/pages/haditha/search/index.vue b/pages/haditha/search/index.vue index e4b7efa..a25b7a4 100644 --- a/pages/haditha/search/index.vue +++ b/pages/haditha/search/index.vue @@ -90,7 +90,7 @@ const SearchList = defineAsyncComponent(() =>
/>
کاوش با - هوش مصنوعی + هوش مصنوعی در احادیث اسلامی