mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-02-12 10:15:50 +00:00
add oldmessage fetch loader
This commit is contained in:
parent
66d94cfc52
commit
d22a4abdcc
@ -67,6 +67,7 @@ class ChatPage extends LitElement {
|
|||||||
chatEditorNewChat: { type: Object },
|
chatEditorNewChat: { type: Object },
|
||||||
userLanguage: { type: String },
|
userLanguage: { type: String },
|
||||||
lastMessageRefVisible: { type: Boolean },
|
lastMessageRefVisible: { type: Boolean },
|
||||||
|
isLoadingOldMessages: {type: Boolean}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -873,11 +874,15 @@ class ChatPage extends LitElement {
|
|||||||
.sendMessage=${(val) => this._sendMessage(val)}
|
.sendMessage=${(val) => this._sendMessage(val)}
|
||||||
.showLastMessageRefScroller=${(val) => this.showLastMessageRefScroller(val)}
|
.showLastMessageRefScroller=${(val) => this.showLastMessageRefScroller(val)}
|
||||||
.emojiPicker=${this.emojiPicker}
|
.emojiPicker=${this.emojiPicker}
|
||||||
|
?isLoadingMessages=${this.isLoadingOldMessages}
|
||||||
|
.setIsLoadingMessages=${(val) => this.setIsLoadingMessages(val)}
|
||||||
>
|
>
|
||||||
</chat-scroller>
|
</chat-scroller>
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
setIsLoadingMessages(val){
|
||||||
|
this.isLoadingOldMessages = val
|
||||||
|
}
|
||||||
async getUpdateComplete() {
|
async getUpdateComplete() {
|
||||||
await super.getUpdateComplete();
|
await super.getUpdateComplete();
|
||||||
const marginElements = Array.from(this.shadowRoot.querySelectorAll('chat-scroller'));
|
const marginElements = Array.from(this.shadowRoot.querySelectorAll('chat-scroller'));
|
||||||
@ -887,7 +892,6 @@ class ChatPage extends LitElement {
|
|||||||
|
|
||||||
async getOldMessage(scrollElement) {
|
async getOldMessage(scrollElement) {
|
||||||
|
|
||||||
|
|
||||||
if (this.isReceipient) {
|
if (this.isReceipient) {
|
||||||
const getInitialMessages = await parentEpml.request('apiCall', {
|
const getInitialMessages = await parentEpml.request('apiCall', {
|
||||||
type: 'api',
|
type: 'api',
|
||||||
@ -910,14 +914,17 @@ class ChatPage extends LitElement {
|
|||||||
return a.timestamp
|
return a.timestamp
|
||||||
- b.timestamp
|
- b.timestamp
|
||||||
})
|
})
|
||||||
|
this.isLoadingOldMessages = false
|
||||||
await this.getUpdateComplete();
|
await this.getUpdateComplete();
|
||||||
const marginElements = Array.from(this.shadowRoot.querySelector('chat-scroller').shadowRoot.querySelectorAll('message-template'));
|
const marginElements = Array.from(this.shadowRoot.querySelector('chat-scroller').shadowRoot.querySelectorAll('message-template'));
|
||||||
|
|
||||||
const findElement = marginElements.find((item)=> item.messageObj.reference === scrollElement.messageObj.reference)
|
const findElement = marginElements.find((item)=> item.messageObj.reference === scrollElement.messageObj.reference)
|
||||||
|
|
||||||
if(findElement){
|
if(findElement){
|
||||||
findElement.scrollIntoView({ behavior: 'auto', block: 'center' });
|
findElement.scrollIntoView({ behavior: 'auto', block: 'center' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const getInitialMessages = await parentEpml.request('apiCall', {
|
const getInitialMessages = await parentEpml.request('apiCall', {
|
||||||
type: 'api',
|
type: 'api',
|
||||||
@ -941,6 +948,7 @@ class ChatPage extends LitElement {
|
|||||||
return a.timestamp
|
return a.timestamp
|
||||||
- b.timestamp
|
- b.timestamp
|
||||||
})
|
})
|
||||||
|
this.isLoadingOldMessages = false
|
||||||
await this.getUpdateComplete();
|
await this.getUpdateComplete();
|
||||||
const marginElements = Array.from(this.shadowRoot.querySelector('chat-scroller').shadowRoot.querySelectorAll('message-template'));
|
const marginElements = Array.from(this.shadowRoot.querySelector('chat-scroller').shadowRoot.querySelectorAll('message-template'));
|
||||||
const findElement = marginElements.find((item)=> item.messageObj.reference === scrollElement.messageObj.reference)
|
const findElement = marginElements.find((item)=> item.messageObj.reference === scrollElement.messageObj.reference)
|
||||||
|
@ -435,4 +435,9 @@ export const chatStyles = css`
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
.spinnerContainer {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
justify-content: center
|
||||||
|
}
|
||||||
`
|
`
|
||||||
|
@ -31,7 +31,9 @@ class ChatScroller extends LitElement {
|
|||||||
focusChatEditor: {attribute: false},
|
focusChatEditor: {attribute: false},
|
||||||
sendMessage: {attribute: false},
|
sendMessage: {attribute: false},
|
||||||
showLastMessageRefScroller: { type: Function },
|
showLastMessageRefScroller: { type: Function },
|
||||||
emojiPicker: { attribute: false }
|
emojiPicker: { attribute: false },
|
||||||
|
isLoadingMessages: { type: Boolean},
|
||||||
|
setIsLoadingMessages: {attribute: false}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +73,11 @@ class ChatScroller extends LitElement {
|
|||||||
return messageArray;
|
return messageArray;
|
||||||
}, [])
|
}, [])
|
||||||
return html`
|
return html`
|
||||||
|
${this.isLoadingMessages ? html`
|
||||||
|
<div class="spinnerContainer">
|
||||||
|
<paper-spinner-lite active></paper-spinner-lite>
|
||||||
|
</div>
|
||||||
|
` : ''}
|
||||||
<ul id="viewElement" class="chat-list clearfix">
|
<ul id="viewElement" class="chat-list clearfix">
|
||||||
<div id="upObserver"></div>
|
<div id="upObserver"></div>
|
||||||
${formattedMessages.map((formattedMessage) => {
|
${formattedMessages.map((formattedMessage) => {
|
||||||
@ -101,6 +108,9 @@ class ChatScroller extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shouldUpdate(changedProperties) {
|
shouldUpdate(changedProperties) {
|
||||||
|
if(changedProperties.has('isLoadingMessages')){
|
||||||
|
return true
|
||||||
|
}
|
||||||
// Only update element if prop1 changed.
|
// Only update element if prop1 changed.
|
||||||
return changedProperties.has('messages');
|
return changedProperties.has('messages');
|
||||||
}
|
}
|
||||||
@ -144,6 +154,7 @@ class ChatScroller extends LitElement {
|
|||||||
|
|
||||||
_upObserverhandler(entries) {
|
_upObserverhandler(entries) {
|
||||||
if (entries[0].isIntersecting) {
|
if (entries[0].isIntersecting) {
|
||||||
|
this.setIsLoadingMessages(true)
|
||||||
let _scrollElement = entries[0].target.nextElementSibling
|
let _scrollElement = entries[0].target.nextElementSibling
|
||||||
this._getOldMessage(_scrollElement)
|
this._getOldMessage(_scrollElement)
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,6 @@ class ChatTextEditor extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async firstUpdated() {
|
async firstUpdated() {
|
||||||
console.log(this.placeholder, "here500");
|
|
||||||
if (this.hasGlobalEvents) {
|
if (this.hasGlobalEvents) {
|
||||||
this.addGlobalEventListener();
|
this.addGlobalEventListener();
|
||||||
}
|
}
|
||||||
@ -301,7 +300,6 @@ class ChatTextEditor extends LitElement {
|
|||||||
this.chatEditor.insertText(this.editedMessageObj.message)
|
this.chatEditor.insertText(this.editedMessageObj.message)
|
||||||
}
|
}
|
||||||
if (changedProperties && changedProperties.has('placeholder')) {
|
if (changedProperties && changedProperties.has('placeholder')) {
|
||||||
console.log(this.placeholder, "here600");
|
|
||||||
const captionEditor = this.shadowRoot.getElementById(this.iframeId).contentWindow.document.getElementById('testingId');
|
const captionEditor = this.shadowRoot.getElementById(this.iframeId).contentWindow.document.getElementById('testingId');
|
||||||
captionEditor.setAttribute('data-placeholder', this.placeholder);
|
captionEditor.setAttribute('data-placeholder', this.placeholder);
|
||||||
}
|
}
|
||||||
@ -372,7 +370,6 @@ class ChatTextEditor extends LitElement {
|
|||||||
|
|
||||||
initChatEditor() {
|
initChatEditor() {
|
||||||
const ChatEditor = function (editorConfig) {
|
const ChatEditor = function (editorConfig) {
|
||||||
console.log(editorConfig.placeholder, "here5600");
|
|
||||||
const ChatEditor = function () {
|
const ChatEditor = function () {
|
||||||
const editor = this;
|
const editor = this;
|
||||||
editor.init();
|
editor.init();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user