Skip to content

Commit 87b7ff2

Browse files
authored
Merge pull request #197 from yel-hadd/master
Improve chat tooltip UX with dismissible functionality
2 parents 60fe699 + 7f45f4d commit 87b7ff2

File tree

1 file changed

+77
-3
lines changed

1 file changed

+77
-3
lines changed

docs/.vuepress/components/Chat.vue

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div id="bot-ui">
33
<!-- Conditionally show toggle button with highlight -->
44
<div class="toggle-container" v-show="!(isMobile && showChat)">
5-
<div v-if="!showChat" class="pulse-ring"></div>
5+
<div v-if="shouldShowTooltip" class="pulse-ring"></div>
66
<button
77
class="chat-toggle"
88
@click="toggleChat"
@@ -29,8 +29,9 @@
2929
</svg>
3030
</button>
3131

32-
<div v-if="!showChat" class="highlight-container">
32+
<div v-if="shouldShowTooltip" class="highlight-container">
3333
<div class="tooltip-text">
34+
<div class="tooltip-close" @click="dismissTooltip">×</div>
3435
<div class="tooltip-title"><b>Need help?</b></div>
3536
<div class="tooltip-subtitle">I'm an AI chatbot, trained to answer all your questions.</div>
3637
</div>
@@ -85,30 +86,66 @@ export default {
8586
isLoading: true,
8687
iframeUrl: "https://chatbot.cloudlinux.com/docs/tuxcare",
8788
windowWidth: 0, // Changed from window.innerWidth to avoid SSR error
89+
showTooltip: true,
90+
tooltipDismissDuration: 2 * 60 * 60 * 1000, // 2 hours in milliseconds
8891
};
8992
},
9093
computed: {
9194
isMobile() {
9295
return this.windowWidth < 768;
9396
},
97+
shouldShowTooltip() {
98+
return this.showTooltip && !this.showChat;
99+
},
94100
},
95101
mounted() {
96102
window.addEventListener("resize", this.handleResize);
97103
this.handleResize(); // Set initial windowWidth on client-side
104+
this.updateTooltipVisibility();
98105
},
99106
beforeUnmount() {
100107
window.removeEventListener("resize", this.handleResize);
101108
},
102109
methods: {
103110
toggleChat() {
104111
this.showChat = !this.showChat;
112+
if (this.showChat) {
113+
this.dismissTooltip();
114+
}
105115
},
106116
handleResize() {
107117
this.windowWidth = window.innerWidth;
108118
},
109119
onIframeLoad() {
110120
this.isLoading = false;
111121
},
122+
dismissTooltip() {
123+
const currentTime = new Date().getTime();
124+
if (typeof localStorage !== 'undefined') {
125+
localStorage.setItem('chatbot_tooltip_dismissed_time', currentTime.toString());
126+
}
127+
this.showTooltip = false;
128+
},
129+
updateTooltipVisibility() {
130+
if (typeof localStorage === 'undefined') {
131+
this.showTooltip = true;
132+
return;
133+
}
134+
135+
const dismissedTime = localStorage.getItem('chatbot_tooltip_dismissed_time');
136+
137+
if (dismissedTime) {
138+
const currentTime = new Date().getTime();
139+
if (currentTime - parseInt(dismissedTime) < this.tooltipDismissDuration) {
140+
this.showTooltip = false;
141+
} else {
142+
localStorage.removeItem('chatbot_tooltip_dismissed_time');
143+
this.showTooltip = true;
144+
}
145+
} else {
146+
this.showTooltip = true;
147+
}
148+
},
112149
},
113150
};
114151
</script>
@@ -188,7 +225,7 @@ mobile-breakpoint = 768px
188225
display: flex;
189226
flex-direction: column;
190227
align-items: flex-end;
191-
pointer-events: none;
228+
pointer-events: auto;
192229
z-index: 10001;
193230
max-width: 90vw;
194231
}
@@ -206,14 +243,51 @@ mobile-breakpoint = 768px
206243
box-shadow: 0 0 15px $primary-color;
207244
overflow: visible;
208245
text-overflow: clip;
246+
247+
/* Stop animation on hover */
248+
&:hover {
249+
animation-play-state: paused;
250+
}
251+
}
252+
253+
.tooltip-close {
254+
position: absolute;
255+
top: -8px;
256+
right: -8px;
257+
width: 20px;
258+
height: 20px;
259+
background: white;
260+
border: 1px solid #ddd;
261+
border-radius: 50%;
262+
display: flex;
263+
align-items: center;
264+
justify-content: center;
265+
cursor: pointer;
266+
font-size: 14px;
267+
line-height: 1;
268+
color: #666;
269+
transition: all 0.2s ease;
270+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
271+
z-index: 10;
272+
pointer-events: auto;
273+
274+
&:hover {
275+
background: #f5f5f5;
276+
transform: scale(1.1);
277+
color: #333;
278+
}
209279
}
210280
211281
.tooltip-title {
212282
margin-bottom: 4px;
283+
position: relative;
284+
z-index: 2;
213285
}
214286
215287
.tooltip-subtitle {
216288
white-space: nowrap;
289+
position: relative;
290+
z-index: 2;
217291
}
218292
219293
.chat-container {

0 commit comments

Comments
 (0)