diff --git a/ui/app/AppLayouts/Profile/helpers/ProfileShowcaseDirtyState.qml b/ui/app/AppLayouts/Profile/helpers/ProfileShowcaseDirtyState.qml index c123cc6693..750a36322f 100644 --- a/ui/app/AppLayouts/Profile/helpers/ProfileShowcaseDirtyState.qml +++ b/ui/app/AppLayouts/Profile/helpers/ProfileShowcaseDirtyState.qml @@ -31,6 +31,15 @@ QObject { */ readonly property alias hiddenModel: hidden + /** + * Returns dirty state of the showcase model. + */ + readonly property alias dirty: writable.dirty + + function revert() { + writable.revert() + } + function currentState() { return writable.currentState() } diff --git a/ui/app/AppLayouts/Profile/helpers/ProfileShowcaseModelAdapter.qml b/ui/app/AppLayouts/Profile/helpers/ProfileShowcaseModelAdapter.qml new file mode 100644 index 0000000000..d13603679a --- /dev/null +++ b/ui/app/AppLayouts/Profile/helpers/ProfileShowcaseModelAdapter.qml @@ -0,0 +1,212 @@ +import QtQml 2.15 + +import StatusQ 0.1 +import StatusQ.Core.Utils 0.1 + +import SortFilterProxyModel 0.2 + +QObject { + id: root + + // input models + property alias communitiesSourceModel: communityRenamingSource.sourceModel + property alias communitiesShowcaseModel: communityRenamingShowcase.sourceModel + + // adapted models + readonly property alias adaptedCommunitiesSourceModel: communityRenamingSource + readonly property alias adaptedCommunitiesShowcaseModel: communityRenamingShowcase + + // input models + property alias accountsSourceModel: accountsRenamingSource.sourceModel + property alias accountsShowcaseModel: accountsRenamingShowcase.sourceModel + + // adapted models + readonly property alias adaptedAccountsSourceModel: accountsRenamingSource + readonly property alias adaptedAccountsShowcaseModel: accountsRenamingShowcase + + // input models + property alias collectiblesSourceModel: collectiblesRenamingSource.sourceModel + property alias collectiblesShowcaseModel: collectiblesRenamingShowcase.sourceModel + + // adapted models + readonly property alias adaptedCollectiblesSourceModel: collectiblesRenamingSource + readonly property alias adaptedCollectiblesShowcaseModel: collectiblesRenamingShowcase + + + RolesRenamingModel { + id: communityRenamingSource + mapping: [ + RoleRename { + from: "id" + to: "key" + } + ] + } + + RolesRenamingModel { + id: communityRenamingShowcase + mapping: [ + RoleRename { + from: "id" + to: "key" + }, + RoleRename { + from: "order" + to: "position" + }, + RoleRename { + from: "showcaseVisibility" + to: "visibility" + }, + // Removing model duplicates + // TODO: remove this when the lightweigth model is used + // https://github.com/status-im/status-desktop/issues/13688 + RoleRename { + from: "name" + to: "_name" + }, + RoleRename { + from: "memberRole" + to: "_memberRole" + }, + RoleRename { + from: "image" + to: "_image" + }, + RoleRename { + from: "color" + to: "_color" + }, + RoleRename { + from: "description" + to: "_description" + }, + RoleRename { + from: "membersCount" + to: "_membersCount" + }, + RoleRename { + from: "loading" + to: "_loading" + } + ] + } + + RolesRenamingModel { + id: accountsRenamingSource + mapping: [ + RoleRename { + from: "address" + to: "key" + }, + RoleRename { + from: "position" + to: "positions" + } + ] + } + + + RolesRenamingModel { + id: accountsRenamingShowcase + mapping: [ + RoleRename { + from: "address" + to: "key" + }, + RoleRename { + from: "order" + to: "position" + }, + RoleRename { + from: "showcaseVisibility" + to: "visibility" + }, + // Removing model duplicates + // TODO: remove this when the lightweigth model is used + // https://github.com/status-im/status-desktop/issues/13688 + RoleRename { + from: "name" + to: "_name" + }, + RoleRename { + from: "emoji" + to: "_emoji" + }, + RoleRename { + from: "colorId" + to: "_colorId" + } + ] + } + + RolesRenamingModel { + id: collectiblesRenamingSource + sourceModel: root.collectiblesSourceModel + mapping: [ + RoleRename { + from: "uid" + to: "key" + } + ] + } + + RolesRenamingModel { + id: collectiblesRenamingShowcase + sourceModel: root.collectiblesShowcaseModel + + mapping: [ + RoleRename { + from: "uid" + to: "key" + }, + RoleRename { + from: "order" + to: "position" + }, + RoleRename { + from: "showcaseVisibility" + to: "visibility" + }, + // Removing model duplicates + // TODO: remove this when the lightweigth model is used + // https://github.com/status-im/status-desktop/issues/13688 + RoleRename { + from: "chainId" + to: "_chainId" + }, + RoleRename { + from: "contractAddress" + to: "_contractAddress" + }, + RoleRename { + from: "tokenId" + to: "_tokenId" + }, + RoleRename { + from: "name" + to: "_name" + }, + RoleRename { + from: "imageUrl" + to: "_imageUrl" + }, + RoleRename { + from: "backgroundColor" + to: "_backgroundColor" + }, + RoleRename { + from: "collectionName" + to: "_collectionName" + }, + RoleRename { + from: "isLoading" + to: "_isLoading" + }, + RoleRename { + from: "communityId" + to: "_communityId" + } + ] + } +} \ No newline at end of file diff --git a/ui/app/AppLayouts/Profile/helpers/ProfileShowcaseModels.qml b/ui/app/AppLayouts/Profile/helpers/ProfileShowcaseModels.qml index 9e82f7e25e..efec54a4a4 100644 --- a/ui/app/AppLayouts/Profile/helpers/ProfileShowcaseModels.qml +++ b/ui/app/AppLayouts/Profile/helpers/ProfileShowcaseModels.qml @@ -10,11 +10,20 @@ import utils 1.0 QObject { id: root + // GENERAL + readonly property bool dirty: communities.dirty || accounts.dirty || collectibles.dirty + + function revert() { + communities.revert() + accounts.revert() + collectibles.revert() + } + // COMMUNITIES // Input models - property alias communitiesSourceModel: communities.sourceModel - property alias communitiesShowcaseModel: communities.showcaseModel + property alias communitiesSourceModel: modelAdapter.communitiesSourceModel + property alias communitiesShowcaseModel: modelAdapter.communitiesShowcaseModel // Output models readonly property alias communitiesVisibleModel: communities.visibleModel @@ -36,8 +45,8 @@ QObject { // ACCOUNTS // Input models - property alias accountsSourceModel: accounts.sourceModel - property alias accountsShowcaseModel: accounts.showcaseModel + property alias accountsSourceModel: modelAdapter.accountsSourceModel + property alias accountsShowcaseModel: modelAdapter.accountsShowcaseModel // Output models readonly property alias accountsVisibleModel: accounts.visibleModel @@ -66,8 +75,8 @@ QObject { // COLLECTIBLES // Input models - property alias collectiblesSourceModel: collectiblesFilter.sourceModel - property alias collectiblesShowcaseModel: collectibles.showcaseModel + property alias collectiblesSourceModel: modelAdapter.collectiblesSourceModel + property alias collectiblesShowcaseModel: modelAdapter.collectiblesShowcaseModel // Output models readonly property alias collectiblesVisibleModel: collectibles.visibleModel @@ -86,25 +95,36 @@ QObject { collectibles.changePosition(key, to) } + ProfileShowcaseModelAdapter { + id: modelAdapter + } + ProfileShowcaseDirtyState { id: communities + + sourceModel: modelAdapter.adaptedCommunitiesSourceModel + showcaseModel: modelAdapter.adaptedCommunitiesShowcaseModel } ProfileShowcaseDirtyState { id: accounts + + sourceModel: modelAdapter.adaptedAccountsSourceModel + showcaseModel: modelAdapter.adaptedAccountsShowcaseModel } ProfileShowcaseDirtyState { id: collectibles sourceModel: collectiblesFilter + showcaseModel: modelAdapter.adaptedCollectiblesShowcaseModel } SortFilterProxyModel { id: collectiblesFilter delayed: true - + sourceModel: modelAdapter.adaptedCollectiblesSourceModel proxyRoles: FastExpressionRole { name: "maxVisibility" diff --git a/ui/app/AppLayouts/Profile/helpers/qmldir b/ui/app/AppLayouts/Profile/helpers/qmldir index 87106dd06a..ddeab1d4f3 100644 --- a/ui/app/AppLayouts/Profile/helpers/qmldir +++ b/ui/app/AppLayouts/Profile/helpers/qmldir @@ -1,3 +1,4 @@ ProfileShowcaseDirtyState 1.0 ProfileShowcaseDirtyState.qml +ProfileShowcaseModelAdapter 1.0 ProfileShowcaseModelAdapter.qml ProfileShowcaseModels 1.0 ProfileShowcaseModels.qml VisibilityAndPositionDirtyStateModel 1.0 VisibilityAndPositionDirtyStateModel.qml