Refactor PageLoader show methods
Also lets the chat page recycling work with showPrevious() (ctrl+tab)
This commit is contained in:
parent
a4bbbfee87
commit
e947fe7695
|
@ -111,7 +111,8 @@ HMenu {
|
|||
text: qsTr("Account settings")
|
||||
onTriggered: {
|
||||
pageLoader.showPage(
|
||||
"AccountSettings/AccountSettings", { "userId": userId },
|
||||
"Pages/AccountSettings/AccountSettings.qml",
|
||||
{ "userId": userId },
|
||||
)
|
||||
wentToAccountPage()
|
||||
}
|
||||
|
@ -121,7 +122,7 @@ HMenu {
|
|||
icon.name: "menu-add-chat"
|
||||
text: qsTr("Add new chat")
|
||||
onTriggered: {
|
||||
pageLoader.showPage("AddChat/AddChat", {userId: userId})
|
||||
pageLoader.showPage("Pages/AddChat/AddChat.qml", {userId: userId})
|
||||
wentToAccountPage()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,9 @@ HTile {
|
|||
backgroundColor: "transparent"
|
||||
toolTip.text: qsTr("Add new chat")
|
||||
onClicked: {
|
||||
pageLoader.showPage("AddChat/AddChat", {userId: model.id})
|
||||
pageLoader.showPage(
|
||||
"Pages/AddChat/AddChat.qml", {userId: model.id},
|
||||
)
|
||||
account.wentToAccountPage()
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ Rectangle {
|
|||
toolTip.text: qsTr("Add another account")
|
||||
backgroundColor: theme.mainPane.bottomBar.settingsButtonBackground
|
||||
onClicked: {
|
||||
pageLoader.showPage("AddAccount/AddAccount")
|
||||
pageLoader.showPage("Pages/AddAccount/AddAccount.qml")
|
||||
roomList.startCorrectItemSearch()
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ HListView {
|
|||
|
||||
item.type === "Account" ?
|
||||
pageLoader.showPage(
|
||||
"AccountSettings/AccountSettings", { "userId": item.id }
|
||||
"Pages/AccountSettings/AccountSettings.qml", { "userId": item.id },
|
||||
) :
|
||||
pageLoader.showRoom(item.for_account, item.id)
|
||||
|
||||
|
|
|
@ -21,35 +21,29 @@ HLoader {
|
|||
|
||||
signal previousShown(string componentUrl, var properties)
|
||||
|
||||
function _show(componentUrl, properties={}) {
|
||||
function showPage(componentUrl, properties={}) {
|
||||
history.unshift([componentUrl, properties])
|
||||
if (history.length > historyLength) history.pop()
|
||||
|
||||
pageLoader.setSource(componentUrl, properties)
|
||||
}
|
||||
const recycle =
|
||||
window.uiState.page === componentUrl &&
|
||||
componentUrl === "Pages/Chat/Chat.qml" &&
|
||||
item
|
||||
|
||||
function showPage(name, properties={}) {
|
||||
const path = `Pages/${name}.qml`
|
||||
_show(path, properties)
|
||||
if (recycle) {
|
||||
for (const [prop, value] of Object.entries(properties))
|
||||
item[prop] = value
|
||||
} else {
|
||||
pageLoader.setSource(componentUrl, properties)
|
||||
window.uiState.page = componentUrl
|
||||
}
|
||||
|
||||
window.uiState.page = path
|
||||
window.uiState.pageProperties = properties
|
||||
window.uiStateChanged()
|
||||
}
|
||||
|
||||
function showRoom(userId, roomId) {
|
||||
if (window.uiState.page === "Pages/Chat/Chat.qml" && item) {
|
||||
// XXX: showPrevious
|
||||
item.userId = userId
|
||||
item.roomId = roomId
|
||||
return
|
||||
}
|
||||
|
||||
_show("Pages/Chat/Chat.qml", {userId, roomId})
|
||||
|
||||
window.uiState.page = "Pages/Chat/Chat.qml"
|
||||
window.uiState.pageProperties = {userId, roomId}
|
||||
window.uiStateChanged()
|
||||
showPage("Pages/Chat/Chat.qml", {userId, roomId})
|
||||
}
|
||||
|
||||
function showPrevious(timesBack=1) {
|
||||
|
@ -57,12 +51,7 @@ HLoader {
|
|||
if (timesBack < 1) return false
|
||||
|
||||
const [componentUrl, properties] = history[timesBack]
|
||||
|
||||
_show(componentUrl, properties)
|
||||
|
||||
window.uiState.page = componentUrl
|
||||
window.uiState.pageProperties = properties
|
||||
window.uiStateChanged()
|
||||
showPage(componentUrl, properties)
|
||||
previousShown(componentUrl, properties)
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -46,7 +46,8 @@ HFlickableColumnPage {
|
|||
)
|
||||
|
||||
pageLoader.showPage(
|
||||
"AccountSettings/AccountSettings", {userId: receivedUserId}
|
||||
"Pages/AccountSettings/AccountSettings.qml",
|
||||
{userId: receivedUserId},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ HFlickableColumnPopup {
|
|||
window.uiState.pageProperties.roomId === roomId)
|
||||
{
|
||||
window.mainUI.pageLoader.showPrevious() ||
|
||||
window.mainUI.pageLoader.showPage("Default")
|
||||
window.mainUI.pageLoader.showPage("Pages/Default.qml")
|
||||
|
||||
Qt.callLater(popup.destroy)
|
||||
}
|
||||
|
|
|
@ -38,7 +38,8 @@ HFlickableColumnPopup {
|
|||
if (ModelStore.get("accounts").count < 2 ||
|
||||
window.uiState.pageProperties.userId === userId)
|
||||
{
|
||||
window.mainUI.pageLoader.showPage("AddAccount/AddAccount")
|
||||
const page = "Pages/AddAccount/AddAccount.qml"
|
||||
window.mainUI.pageLoader.showPage(page)
|
||||
}
|
||||
|
||||
py.callCoro("logout_client", [userId])
|
||||
|
|
Loading…
Reference in New Issue
Block a user