Parent now pages history on event.
loadMoreHistory func uses new variables historyPage and historyPageSize to fetch the next x = historyPageSize elements with skip, take query parameters for /history endpoint before prepending the received messages to the existing.
This commit is contained in:
		| @@ -43,9 +43,11 @@ | |||||||
|       <Chat |       <Chat | ||||||
|         class="outer-chat" |         class="outer-chat" | ||||||
|         :chatHistory="chatHistory" |         :chatHistory="chatHistory" | ||||||
|  |         :historyPageSize="historyPageSize" | ||||||
|         :usernameAllowed="usernameAllowed" |         :usernameAllowed="usernameAllowed" | ||||||
|         v-on:message="sendMessage" |         @loadMoreHistory="loadMoreHistory" | ||||||
|         v-on:username="setUsername" |         @message="sendMessage" | ||||||
|  |         @username="setUsername" | ||||||
|       /> |       /> | ||||||
|     </div> |     </div> | ||||||
|     <Vipps class="vipps" :amount="1" /> |     <Vipps class="vipps" :amount="1" /> | ||||||
| @@ -74,6 +76,9 @@ export default { | |||||||
|       attendeesFetched: false, |       attendeesFetched: false, | ||||||
|       winnersFetched: false, |       winnersFetched: false, | ||||||
|       chatHistory: [], |       chatHistory: [], | ||||||
|  |       historyPage: 0, | ||||||
|  |       historyPageSize: 100, | ||||||
|  |       lastHistoryPage: false, | ||||||
|       usernameAccepted: false, |       usernameAccepted: false, | ||||||
|       username: null, |       username: null, | ||||||
|       wasDisconnected: false, |       wasDisconnected: false, | ||||||
| @@ -158,6 +163,15 @@ export default { | |||||||
|     sendMessage: function(msg) { |     sendMessage: function(msg) { | ||||||
|       this.socket.emit("chat", { message: msg }); |       this.socket.emit("chat", { message: msg }); | ||||||
|     }, |     }, | ||||||
|  |     loadMoreHistory: function() { | ||||||
|  |       const { historyPage, historyPageSize } = this; | ||||||
|  |       const page = historyPage + 1; | ||||||
|  |  | ||||||
|  |       getChatHistory(page * historyPageSize, historyPageSize).then(messages => { | ||||||
|  |         this.chatHistory = messages.concat(this.chatHistory); | ||||||
|  |         this.historyPage = page; | ||||||
|  |       }); | ||||||
|  |     }, | ||||||
|     getWinners: async function() { |     getWinners: async function() { | ||||||
|       let response = await winners(); |       let response = await winners(); | ||||||
|       if (response) { |       if (response) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user