Skip to content

Commit

Permalink
fix: welcome card flip bug
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-husky committed Aug 2, 2024
1 parent 573dc4d commit f35f663
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions themes/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ class WelcomeMessage {
this.card_array = [];
this.static_welcome_message_previous = [];
this.reflesh_time_interval = 15*1000;


const reflesh_render_status = () => {
for (let index = 0; index < this.card_array.length; index++) {
const card = this.card_array[index];
card.classList.remove('hide');
card.classList.remove('show');
}
};
const pageFocusHandler = new PageFocusHandler();
pageFocusHandler.addFocusCallback(reflesh_render_status);
}

begin_render() {
Expand Down Expand Up @@ -106,8 +117,12 @@ class WelcomeMessage {
}

const card = this.card_array[index];
card.classList.remove('hide');
card.classList.remove('show');
// 已经包含了 hide 属性?
if (card.classList.contains('hide') || card.classList.contains('show')) {
card.classList.remove('hide');
card.classList.remove('show');
continue;
}

// 等待动画结束
card.addEventListener('transitionend', () => {
Expand Down Expand Up @@ -158,7 +173,7 @@ class WelcomeMessage {
}

async update() {
console.log('update')
// console.log('update')
var page_width = document.documentElement.clientWidth;
const width_to_hide_welcome = 1200;
if (!await this.isChatbotEmpty() || page_width < width_to_hide_welcome) {
Expand Down Expand Up @@ -269,3 +284,34 @@ class WelcomeMessage {

}




class PageFocusHandler {
constructor() {
this.hasReturned = false;
this.focusCallbacks = [];

// Bind the focus and blur event handlers
window.addEventListener('visibilitychange', this.handleFocus.bind(this));
}

// Method to handle the focus event
handleFocus() {
if (this.hasReturned) {
this.focusCallbacks.forEach(callback => callback());
}
this.hasReturned = true;
}

// Method to add a custom callback function
addFocusCallback(callback) {
if (typeof callback === 'function') {
this.focusCallbacks.push(callback);
} else {
throw new Error('Callback must be a function');
}
}
}


0 comments on commit f35f663

Please sign in to comment.