mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-12-22 11:39:31 +00:00
Lazy loading for the tweets
This commit is contained in:
parent
417c9bf609
commit
88d9be953b
4 changed files with 47 additions and 28 deletions
|
@ -36,6 +36,11 @@ Rectangle {
|
|||
width: 330
|
||||
color: "#FFFFFF"
|
||||
|
||||
function updateTweets() {
|
||||
tabView.twitter.item.updateTweets()
|
||||
}
|
||||
|
||||
|
||||
TabView {
|
||||
id: tabView
|
||||
anchors.left: parent.left
|
||||
|
@ -45,12 +50,18 @@ Rectangle {
|
|||
anchors.leftMargin: 14
|
||||
anchors.rightMargin: 14
|
||||
anchors.topMargin: 40
|
||||
property alias twitter: twitter
|
||||
|
||||
Tab { title: qsTr("Twitter"); source: "tabs/Twitter.qml" }
|
||||
|
||||
|
||||
|
||||
Tab { id: twitter; title: qsTr("Twitter"); source: "tabs/Twitter.qml" }
|
||||
Tab { title: "News" }
|
||||
Tab { title: "Help" }
|
||||
Tab { title: "About" }
|
||||
|
||||
|
||||
|
||||
style: TabViewStyle {
|
||||
frameOverlap: 0
|
||||
tabOverlap: 0
|
||||
|
|
6
main.qml
6
main.qml
|
@ -210,6 +210,12 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
|
||||
onRightPanelExpandedChanged: {
|
||||
if (rightPanelExpanded) {
|
||||
rightPanel.updateTweets()
|
||||
}
|
||||
}
|
||||
|
||||
Settings {
|
||||
id: persistentSettings
|
||||
property string language
|
||||
|
|
|
@ -56,47 +56,41 @@ Item {
|
|||
|
||||
function reload() {
|
||||
tweets.clear()
|
||||
|
||||
if (from == "" && phrase == "")
|
||||
return;
|
||||
|
||||
if (appWindow.rightPanelExpanded) {
|
||||
|
||||
//! [requesting]
|
||||
var req = new XMLHttpRequest;
|
||||
req.open("GET", "https://api.twitter.com/1.1/search/tweets.json?from=" + from +
|
||||
"&count=" + tweetsMaxCount + "&q=" + encodePhrase(phrase));
|
||||
req.setRequestHeader("Authorization", "Bearer " + bearerToken);
|
||||
req.onreadystatechange = function() {
|
||||
status = req.readyState;
|
||||
if (status === XMLHttpRequest.DONE) {
|
||||
var objectArray = JSON.parse(req.responseText);
|
||||
if (objectArray.errors !== undefined)
|
||||
console.log("Error fetching tweets: " + objectArray.errors[0].message)
|
||||
else {
|
||||
for (var key in objectArray.statuses) {
|
||||
var jsonObject = objectArray.statuses[key];
|
||||
tweets.append(jsonObject);
|
||||
}
|
||||
//! [requesting]
|
||||
var req = new XMLHttpRequest;
|
||||
req.open("GET", "https://api.twitter.com/1.1/search/tweets.json?from=" + from +
|
||||
"&count=" + tweetsMaxCount + "&q=" + encodePhrase(phrase));
|
||||
req.setRequestHeader("Authorization", "Bearer " + bearerToken);
|
||||
req.onreadystatechange = function() {
|
||||
status = req.readyState;
|
||||
if (status === XMLHttpRequest.DONE) {
|
||||
var objectArray = JSON.parse(req.responseText);
|
||||
if (objectArray.errors !== undefined)
|
||||
console.log("Error fetching tweets: " + objectArray.errors[0].message)
|
||||
else {
|
||||
for (var key in objectArray.statuses) {
|
||||
var jsonObject = objectArray.statuses[key];
|
||||
tweets.append(jsonObject);
|
||||
}
|
||||
if (wasLoading == true)
|
||||
wrapper.isLoaded()
|
||||
}
|
||||
wasLoading = (status === XMLHttpRequest.LOADING);
|
||||
if (wasLoading == true)
|
||||
wrapper.isLoaded()
|
||||
}
|
||||
req.send();
|
||||
//! [requesting]
|
||||
wasLoading = (status === XMLHttpRequest.LOADING);
|
||||
}
|
||||
req.send();
|
||||
//! [requesting]
|
||||
}
|
||||
|
||||
|
||||
Component.onCompleted: {
|
||||
if (consumerKey === "" || consumerSecret == "") {
|
||||
console.log("setting demo token")
|
||||
bearerToken = encodeURIComponent(Helper.demoToken())
|
||||
tweetsModel.phrase = ""
|
||||
tweetsModel.from = "@monerocurrency"
|
||||
reload()
|
||||
// reload()
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ import "../components"
|
|||
Item {
|
||||
id: tab
|
||||
|
||||
|
||||
|
||||
ListModel {
|
||||
id: testModel
|
||||
ListElement { head: "Monero || #xmr"; foot: "<b>@btcplanet</b> Duis turpis arcu, varius nec rutrum in, adipiscing at enim. Donec quis consequat ipsum," }
|
||||
|
@ -56,10 +58,16 @@ Item {
|
|||
property var idx
|
||||
property var ids
|
||||
|
||||
function updateTweets() {
|
||||
tweetsModel.reload()
|
||||
}
|
||||
|
||||
|
||||
Component.onCompleted: {
|
||||
ids = new Array()
|
||||
}
|
||||
|
||||
|
||||
function idInModel(id) {
|
||||
for (var j = 0; j < ids.length; j++)
|
||||
if (ids[j] === id)
|
||||
|
|
Loading…
Reference in a new issue