Add isLoading variable
This commit is contained in:
parent
d950ce0a2b
commit
ed578be468
@ -50,7 +50,9 @@ class ChatElement extends HTMLElement {
|
|||||||
private selectedRole: string | null = null;
|
private selectedRole: string | null = null;
|
||||||
private userProcessSet: Set<string> = new Set();
|
private userProcessSet: Set<string> = new Set();
|
||||||
private dmMembersSet: Set<string> = new Set();
|
private dmMembersSet: Set<string> = new Set();
|
||||||
private addressMap: Record<string, string> = {};
|
private addressMap: Record<string, string> = {};
|
||||||
|
private isLoading = false;
|
||||||
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -585,7 +587,13 @@ class ChatElement extends HTMLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async loadMemberChat(pairingProcess: string) {
|
private async loadMemberChat(pairingProcess: string) {
|
||||||
|
if (this.isLoading) {
|
||||||
|
console.log('Already loading messages, skipping...');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.isLoading = true;
|
||||||
const service = await Services.getInstance();
|
const service = await Services.getInstance();
|
||||||
const myAddresses = await service.getMemberFromDevice();
|
const myAddresses = await service.getMemberFromDevice();
|
||||||
const database = await Database.getInstance();
|
const database = await Database.getInstance();
|
||||||
@ -763,6 +771,8 @@ class ChatElement extends HTMLElement {
|
|||||||
this.scrollToBottom(messagesContainer);
|
this.scrollToBottom(messagesContainer);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Error in loadMemberChat:', error);
|
console.error('❌ Error in loadMemberChat:', error);
|
||||||
|
} finally {
|
||||||
|
this.isLoading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1804,17 +1814,23 @@ class ChatElement extends HTMLElement {
|
|||||||
await this.loadAllProcesses(processSet);
|
await this.loadAllProcesses(processSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.selectedMember && this.selectedMember.length > 0) {
|
if (this.selectedMember && this.selectedMember.length > 0 && !this.isLoading) {
|
||||||
console.log('🔍 Loading chat for selected member:', this.selectedMember);
|
console.log('🔍 Loading chat for selected member:', this.selectedMember);
|
||||||
await this.loadMemberChat(this.selectedMember);
|
await this.loadMemberChat(this.selectedMember);
|
||||||
} else {
|
} else {
|
||||||
console.warn('⚠️ No member selected yet. Waiting for selection...');
|
console.warn('⚠️ No member selected yet. Waiting for selection...');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let timeout: NodeJS.Timeout;
|
||||||
window.addEventListener('process-updated', async (e: CustomEvent) => {
|
window.addEventListener('process-updated', async (e: CustomEvent) => {
|
||||||
const processId = e.detail.processId;
|
const processId = e.detail.processId;
|
||||||
if (processId === this.processId) {
|
if (processId === this.processId) {
|
||||||
setTimeout(async () => await this.reloadMemberChat(this.selectedMember), 3000);
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(async () => {
|
||||||
|
if (!this.isLoading) {
|
||||||
|
await this.reloadMemberChat(this.selectedMember);
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user