Refactor PageLoader show methods

Also lets the chat page recycling work with showPrevious() (ctrl+tab)
This commit is contained in:
miruka 2020-09-02 15:07:10 -04:00
parent a4bbbfee87
commit e947fe7695
8 changed files with 27 additions and 33 deletions

View File

@ -111,7 +111,8 @@ HMenu {
text: qsTr("Account settings") text: qsTr("Account settings")
onTriggered: { onTriggered: {
pageLoader.showPage( pageLoader.showPage(
"AccountSettings/AccountSettings", { "userId": userId }, "Pages/AccountSettings/AccountSettings.qml",
{ "userId": userId },
) )
wentToAccountPage() wentToAccountPage()
} }
@ -121,7 +122,7 @@ HMenu {
icon.name: "menu-add-chat" icon.name: "menu-add-chat"
text: qsTr("Add new chat") text: qsTr("Add new chat")
onTriggered: { onTriggered: {
pageLoader.showPage("AddChat/AddChat", {userId: userId}) pageLoader.showPage("Pages/AddChat/AddChat.qml", {userId: userId})
wentToAccountPage() wentToAccountPage()
} }
} }

View File

@ -146,7 +146,9 @@ HTile {
backgroundColor: "transparent" backgroundColor: "transparent"
toolTip.text: qsTr("Add new chat") toolTip.text: qsTr("Add new chat")
onClicked: { onClicked: {
pageLoader.showPage("AddChat/AddChat", {userId: model.id}) pageLoader.showPage(
"Pages/AddChat/AddChat.qml", {userId: model.id},
)
account.wentToAccountPage() account.wentToAccountPage()
} }

View File

@ -24,7 +24,7 @@ Rectangle {
toolTip.text: qsTr("Add another account") toolTip.text: qsTr("Add another account")
backgroundColor: theme.mainPane.bottomBar.settingsButtonBackground backgroundColor: theme.mainPane.bottomBar.settingsButtonBackground
onClicked: { onClicked: {
pageLoader.showPage("AddAccount/AddAccount") pageLoader.showPage("Pages/AddAccount/AddAccount.qml")
roomList.startCorrectItemSearch() roomList.startCorrectItemSearch()
} }

View File

@ -62,7 +62,7 @@ HListView {
item.type === "Account" ? item.type === "Account" ?
pageLoader.showPage( pageLoader.showPage(
"AccountSettings/AccountSettings", { "userId": item.id } "Pages/AccountSettings/AccountSettings.qml", { "userId": item.id },
) : ) :
pageLoader.showRoom(item.for_account, item.id) pageLoader.showRoom(item.for_account, item.id)

View File

@ -21,35 +21,29 @@ HLoader {
signal previousShown(string componentUrl, var properties) signal previousShown(string componentUrl, var properties)
function _show(componentUrl, properties={}) { function showPage(componentUrl, properties={}) {
history.unshift([componentUrl, properties]) history.unshift([componentUrl, properties])
if (history.length > historyLength) history.pop() 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={}) { if (recycle) {
const path = `Pages/${name}.qml` for (const [prop, value] of Object.entries(properties))
_show(path, properties) item[prop] = value
} else {
pageLoader.setSource(componentUrl, properties)
window.uiState.page = componentUrl
}
window.uiState.page = path
window.uiState.pageProperties = properties window.uiState.pageProperties = properties
window.uiStateChanged() window.uiStateChanged()
} }
function showRoom(userId, roomId) { function showRoom(userId, roomId) {
if (window.uiState.page === "Pages/Chat/Chat.qml" && item) { showPage("Pages/Chat/Chat.qml", {userId, roomId})
// 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()
} }
function showPrevious(timesBack=1) { function showPrevious(timesBack=1) {
@ -57,12 +51,7 @@ HLoader {
if (timesBack < 1) return false if (timesBack < 1) return false
const [componentUrl, properties] = history[timesBack] const [componentUrl, properties] = history[timesBack]
showPage(componentUrl, properties)
_show(componentUrl, properties)
window.uiState.page = componentUrl
window.uiState.pageProperties = properties
window.uiStateChanged()
previousShown(componentUrl, properties) previousShown(componentUrl, properties)
return true return true
} }

View File

@ -46,7 +46,8 @@ HFlickableColumnPage {
) )
pageLoader.showPage( pageLoader.showPage(
"AccountSettings/AccountSettings", {userId: receivedUserId} "Pages/AccountSettings/AccountSettings.qml",
{userId: receivedUserId},
) )
} }

View File

@ -20,7 +20,7 @@ HFlickableColumnPopup {
window.uiState.pageProperties.roomId === roomId) window.uiState.pageProperties.roomId === roomId)
{ {
window.mainUI.pageLoader.showPrevious() || window.mainUI.pageLoader.showPrevious() ||
window.mainUI.pageLoader.showPage("Default") window.mainUI.pageLoader.showPage("Pages/Default.qml")
Qt.callLater(popup.destroy) Qt.callLater(popup.destroy)
} }

View File

@ -38,7 +38,8 @@ HFlickableColumnPopup {
if (ModelStore.get("accounts").count < 2 || if (ModelStore.get("accounts").count < 2 ||
window.uiState.pageProperties.userId === userId) 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]) py.callCoro("logout_client", [userId])