Merge pull request #13738 from zfox23/MS17215_newEarlyFetchLogic

Fix MS17215: Auto-show Confirmed txns in Recent Activity when many Pending txns present
This commit is contained in:
Zach Fox 2018-08-02 09:39:37 -07:00 committed by GitHub
commit 41b804a5dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 11 deletions

View file

@ -142,7 +142,7 @@ Item {
Timer { Timer {
id: refreshTimer; id: refreshTimer;
interval: 4000; interval: 6000;
onTriggered: { onTriggered: {
if (transactionHistory.atYBeginning) { if (transactionHistory.atYBeginning) {
console.log("Refreshing 1st Page of Recent Activity..."); console.log("Refreshing 1st Page of Recent Activity...");
@ -211,6 +211,7 @@ Item {
HifiModels.PSFListModel { HifiModels.PSFListModel {
id: transactionHistoryModel; id: transactionHistoryModel;
property int lastPendingCount: 0;
listModelName: "transaction history"; // For debugging. Alternatively, we could specify endpoint for that purpose, even though it's not used directly. listModelName: "transaction history"; // For debugging. Alternatively, we could specify endpoint for that purpose, even though it's not used directly.
listView: transactionHistory; listView: transactionHistory;
itemsPerPage: 6; itemsPerPage: 6;
@ -221,8 +222,26 @@ Item {
processPage: function (data) { processPage: function (data) {
console.debug('processPage', transactionHistoryModel.listModelName, JSON.stringify(data)); console.debug('processPage', transactionHistoryModel.listModelName, JSON.stringify(data));
var result, pending; // Set up or get the accumulator for pending. var result, pending; // Set up or get the accumulator for pending.
if (transactionHistoryModel.currentPageToRetrieve == 1) { if (transactionHistoryModel.currentPageToRetrieve === 1) {
pending = {transaction_type: "pendingCount", count: 0}; // The initial data elements inside the ListModel MUST contain all keys
// that will be used in future data.
pending = {
transaction_type: "pendingCount",
count: 0,
created_at: 0,
hfc_text: "",
id: "",
message: "",
place_name: "",
received_certs: 0,
received_money: 0,
recipient_name: "",
sender_name: "",
sent_certs: 0,
sent_money: 0,
status: "",
transaction_text: ""
};
result = [pending]; result = [pending];
} else { } else {
pending = transactionHistoryModel.get(0); pending = transactionHistoryModel.get(0);
@ -239,6 +258,15 @@ Item {
} }
}); });
if (lastPendingCount === 0) {
lastPendingCount = pending.count;
} else {
if (lastPendingCount !== pending.count) {
transactionHistoryModel.getNextPageIfNotEnoughVerticalResults();
}
lastPendingCount = pending.count;
}
// Only auto-refresh if the user hasn't scrolled // Only auto-refresh if the user hasn't scrolled
// and there is more data to grab // and there is more data to grab
if (transactionHistory.atYBeginning && data.history.length) { if (transactionHistory.atYBeginning && data.history.length) {
@ -257,13 +285,13 @@ Item {
ListView { ListView {
id: transactionHistory; id: transactionHistory;
ScrollBar.vertical: ScrollBar { ScrollBar.vertical: ScrollBar {
policy: transactionHistory.contentHeight > parent.parent.height ? ScrollBar.AlwaysOn : ScrollBar.AsNeeded; policy: transactionHistory.contentHeight > parent.parent.height ? ScrollBar.AlwaysOn : ScrollBar.AsNeeded;
parent: transactionHistory.parent; parent: transactionHistory.parent;
anchors.top: transactionHistory.top; anchors.top: transactionHistory.top;
anchors.left: transactionHistory.right; anchors.left: transactionHistory.right;
anchors.leftMargin: 4; anchors.leftMargin: 4;
anchors.bottom: transactionHistory.bottom; anchors.bottom: transactionHistory.bottom;
width: 20; width: 20;
} }
anchors.centerIn: parent; anchors.centerIn: parent;
width: parent.width - 12; width: parent.width - 12;
@ -340,7 +368,7 @@ Item {
} }
HifiControlsUit.Separator { HifiControlsUit.Separator {
colorScheme: 1; colorScheme: 1;
anchors.left: parent.left; anchors.left: parent.left;
anchors.right: parent.right; anchors.right: parent.right;
anchors.bottom: parent.bottom; anchors.bottom: parent.bottom;

View file

@ -38,6 +38,16 @@ ListModel {
onSearchFilterChanged: if (initialized) { getFirstPage('delayClear'); } onSearchFilterChanged: if (initialized) { getFirstPage('delayClear'); }
onTagsFilterChanged: if (initialized) { getFirstPage('delayClear'); } onTagsFilterChanged: if (initialized) { getFirstPage('delayClear'); }
// When considering a value for `itemsPerPage` in YOUR model, consider the following:
// - If your ListView delegates are of variable width/height, ensure you select
// an `itemsPerPage` value that would be sufficient to show one full page of data
// if all of the delegates were at their minimum heights.
// - If your first ListView delegate contains some special data (as in WalletHome's
// "Recent Activity" view), beware that your `itemsPerPage` value may _never_ reasonably be
// high enough such that the first page of data causes the view to be one-screen in height
// after retrieving the first page. This means data will automatically pop-in (after a short delay)
// until the combined heights of your View's delegates reach one-screen in height OR there is
// no more data to retrieve. See "needsMoreVerticalResults()" below.
property int itemsPerPage: 100; property int itemsPerPage: 100;
// State. // State.
@ -81,12 +91,35 @@ ListModel {
function getNextPageIfVerticalScroll() { function getNextPageIfVerticalScroll() {
if (needsEarlyYFetch()) { getNextPage(); } if (needsEarlyYFetch()) { getNextPage(); }
} }
function needsMoreHorizontalResults() {
return flickable
&& currentPageToRetrieve > 0
&& flickable.contentWidth < flickable.width;
}
function needsMoreVerticalResults() {
return flickable
&& currentPageToRetrieve > 0
&& flickable.contentHeight < flickable.height;
}
function getNextPageIfNotEnoughHorizontalResults() {
if (needsMoreHorizontalResults()) {
getNextPage();
}
}
function getNextPageIfNotEnoughVerticalResults() {
if (needsMoreVerticalResults()) {
getNextPage();
}
}
Component.onCompleted: { Component.onCompleted: {
initialized = true; initialized = true;
if (flickable && pageAhead > 0.0) { if (flickable && pageAhead > 0.0) {
// Pun: Scrollers are usually one direction or another, such that only one of the following will actually fire. // Pun: Scrollers are usually one direction or another, such that only one of the following will actually fire.
flickable.contentXChanged.connect(getNextPageIfHorizontalScroll); flickable.contentXChanged.connect(getNextPageIfHorizontalScroll);
flickable.contentYChanged.connect(getNextPageIfVerticalScroll); flickable.contentYChanged.connect(getNextPageIfVerticalScroll);
flickable.contentWidthChanged.connect(getNextPageIfNotEnoughHorizontalResults);
flickable.contentHeightChanged.connect(getNextPageIfNotEnoughVerticalResults);
} }
} }