Skip to content

Commit 7d956fb

Browse files
authored
Merge pull request #270 from yel-hadd/master
Improve chat tooltip UX with dismissible functionality
2 parents 607d881 + 8848c34 commit 7d956fb

File tree

1 file changed

+87
-3
lines changed

1 file changed

+87
-3
lines changed

docs/.vuepress/components/Chat.vue

Lines changed: 87 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,77 @@ export default {
8586
isLoading: true,
8687
iframeUrl: "https://chatbot.cloudlinux.com/docs/cloudlinux",
8788
windowWidth: 0, // Changed from window.innerWidth to avoid SSR error
89+
tooltipDismissedTime: null,
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+
// Don't show tooltip if chat is open
99+
if (this.showChat) {
100+
return false;
101+
}
102+
103+
// Don't show tooltip if it was recently dismissed
104+
if (this.tooltipDismissedTime) {
105+
const currentTime = new Date().getTime();
106+
if (currentTime - this.tooltipDismissedTime < this.tooltipDismissDuration) {
107+
return false;
108+
}
109+
}
110+
111+
return true;
112+
},
94113
},
95114
mounted() {
96115
window.addEventListener("resize", this.handleResize);
97116
this.handleResize(); // Set initial windowWidth on client-side
117+
this.loadTooltipDismissalState();
98118
},
99119
beforeUnmount() {
100120
window.removeEventListener("resize", this.handleResize);
101121
},
102122
methods: {
103123
toggleChat() {
104124
this.showChat = !this.showChat;
125+
// Dismiss tooltip when chat is opened
126+
if (this.showChat) {
127+
this.dismissTooltip();
128+
}
105129
},
106130
handleResize() {
107131
this.windowWidth = window.innerWidth;
108132
},
109133
onIframeLoad() {
110134
this.isLoading = false;
111135
},
136+
dismissTooltip() {
137+
const currentTime = new Date().getTime();
138+
this.tooltipDismissedTime = currentTime;
139+
if (typeof localStorage !== 'undefined') {
140+
localStorage.setItem('cldocs_chatbot_tooltip_dismissed_time', currentTime.toString());
141+
}
142+
},
143+
loadTooltipDismissalState() {
144+
if (typeof localStorage !== 'undefined') {
145+
const dismissedTime = localStorage.getItem('cldocs_chatbot_tooltip_dismissed_time');
146+
if (dismissedTime) {
147+
const parsedTime = parseInt(dismissedTime);
148+
const currentTime = new Date().getTime();
149+
150+
// If the dismissal duration has passed, clear the stored time
151+
if (currentTime - parsedTime >= this.tooltipDismissDuration) {
152+
localStorage.removeItem('cldocs_chatbot_tooltip_dismissed_time');
153+
this.tooltipDismissedTime = null;
154+
} else {
155+
this.tooltipDismissedTime = parsedTime;
156+
}
157+
}
158+
}
159+
},
112160
},
113161
};
114162
</script>
@@ -188,7 +236,7 @@ mobile-breakpoint = 768px
188236
display: flex;
189237
flex-direction: column;
190238
align-items: flex-end;
191-
pointer-events: none;
239+
pointer-events: auto;
192240
z-index: 10001;
193241
max-width: 90vw;
194242
}
@@ -206,14 +254,50 @@ mobile-breakpoint = 768px
206254
box-shadow: 0 0 15px $primary-color;
207255
overflow: visible;
208256
text-overflow: clip;
257+
258+
&:hover {
259+
animation-play-state: paused;
260+
}
261+
}
262+
263+
.tooltip-close {
264+
position: absolute;
265+
top: -8px;
266+
right: -8px;
267+
width: 20px;
268+
height: 20px;
269+
background: white;
270+
border: 1px solid #ddd;
271+
border-radius: 50%;
272+
display: flex;
273+
align-items: center;
274+
justify-content: center;
275+
cursor: pointer;
276+
font-size: 14px;
277+
line-height: 1;
278+
color: #666;
279+
transition: all 0.2s ease;
280+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
281+
z-index: 10;
282+
pointer-events: auto;
283+
284+
&:hover {
285+
background: #f5f5f5;
286+
transform: scale(1.1);
287+
color: #333;
288+
}
209289
}
210290
211291
.tooltip-title {
212292
margin-bottom: 4px;
293+
position: relative;
294+
z-index: 2;
213295
}
214296
215297
.tooltip-subtitle {
216298
white-space: nowrap;
299+
position: relative;
300+
z-index: 2;
217301
}
218302
219303
.chat-container {

0 commit comments

Comments
 (0)