2020-08-18 19:10:30 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtGraphicalEffects 1.13
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
2021-10-05 20:50:22 +00:00
|
|
|
import "../controls"
|
2020-08-18 19:10:30 +00:00
|
|
|
|
|
|
|
Item {
|
2021-10-05 20:50:22 +00:00
|
|
|
id: collectiblesContainer
|
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
property url collectibleIconSource: "CryptoKitties"
|
2020-08-18 19:10:30 +00:00
|
|
|
property string collectibleName: "CryptoKitties"
|
2020-08-18 20:11:36 +00:00
|
|
|
property bool collectiblesOpened: false
|
2020-08-19 15:58:25 +00:00
|
|
|
property var collectiblesModal
|
|
|
|
property string buttonText: "View in Cryptokitties"
|
|
|
|
property var getLink: function () {}
|
2020-08-20 21:59:07 +00:00
|
|
|
property var collectibles: {
|
2020-08-24 20:50:49 +00:00
|
|
|
if (error) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
2020-08-20 21:59:07 +00:00
|
|
|
try {
|
2020-08-24 20:50:49 +00:00
|
|
|
var result = JSON.parse(collectiblesJSON)
|
|
|
|
if (typeof result === "string") {
|
|
|
|
return JSON.parse(result)
|
|
|
|
}
|
|
|
|
return result
|
2020-08-20 21:59:07 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error('Error parsing collectibles for:', collectibleName)
|
|
|
|
console.error('JSON:', collectiblesJSON)
|
|
|
|
console.error('Error:', e)
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Adding active instead of just using visible, because visible counts as false when the parent is not visible
|
2020-08-24 20:50:49 +00:00
|
|
|
property bool active: !!loading || !!error || collectibles.length > 0
|
2020-08-18 19:10:30 +00:00
|
|
|
|
2021-10-05 20:50:22 +00:00
|
|
|
signal reloadCollectibles(string collectibleType)
|
|
|
|
|
2020-08-20 21:59:07 +00:00
|
|
|
visible: active
|
2020-08-19 17:07:07 +00:00
|
|
|
width: parent.width
|
2020-08-19 21:09:11 +00:00
|
|
|
height: visible ? collectiblesHeader.height + collectiblesContent.height : 0
|
2020-08-18 19:10:30 +00:00
|
|
|
|
|
|
|
CollectiblesHeader {
|
2020-08-18 20:11:36 +00:00
|
|
|
id: collectiblesHeader
|
2021-10-05 20:50:22 +00:00
|
|
|
collectibleName: collectiblesContainer.collectibleName
|
|
|
|
collectibleIconSource: collectiblesContainer.collectibleIconSource
|
2020-08-20 21:59:07 +00:00
|
|
|
collectiblesQty: collectibles.length
|
|
|
|
isLoading: loading
|
2020-08-18 20:11:36 +00:00
|
|
|
toggleCollectible: function () {
|
2021-10-05 20:50:22 +00:00
|
|
|
collectiblesContainer.collectiblesOpened = !collectiblesContainer.collectiblesOpened
|
2020-08-18 20:11:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 21:09:11 +00:00
|
|
|
CollectiblesContent {
|
|
|
|
id: collectiblesContent
|
2021-10-05 20:50:22 +00:00
|
|
|
visible: collectiblesContainer.collectiblesOpened
|
|
|
|
collectiblesModal: collectiblesContainer.collectiblesModal
|
|
|
|
buttonText: collectiblesContainer.buttonText
|
|
|
|
getLink: collectiblesContainer.getLink()
|
2020-08-18 20:11:36 +00:00
|
|
|
anchors.top: collectiblesHeader.bottom
|
|
|
|
anchors.topMargin: Style.current.halfPadding
|
2021-10-05 20:50:22 +00:00
|
|
|
collectibles: collectiblesContainer.collectibles
|
|
|
|
onReloadCollectibles: reloadCollectibles(collectibleType)
|
2020-08-18 19:10:30 +00:00
|
|
|
}
|
|
|
|
}
|