From e463590a405e66c6281c194a44ca9eb91a5fcb3f Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 29 Apr 2024 14:35:44 -0400 Subject: [PATCH] chore: hide create community button behind advanced setting Fixes #14530 (includes a revert of the previous hide that wasn't exactly what we wanted) --- src/app/global/local_app_settings.nim | 15 ++++++++++++++ .../Communities/CommunitiesPortalLayout.qml | 20 +++++++++++-------- .../Communities/stores/CommunitiesStore.qml | 3 +++ .../Profile/stores/AdvancedStore.qml | 8 ++++++++ .../AppLayouts/Profile/views/AdvancedView.qml | 11 ++++++++++ 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/app/global/local_app_settings.nim b/src/app/global/local_app_settings.nim index 69d6a99388..594d264401 100644 --- a/src/app/global/local_app_settings.nim +++ b/src/app/global/local_app_settings.nim @@ -17,11 +17,13 @@ const LAS_KEY_CUSTOM_MOUSE_SCROLLING_ENABLED = "global/custom_mouse_scroll_enabl const DEFAULT_CUSTOM_MOUSE_SCROLLING_ENABLED = false const DEFAULT_VISIBILITY = 2 #windowed visibility, from qml const LAS_KEY_FAKE_LOADING_SCREEN_ENABLED = "global/fake_loading_screen" +const LAS_KEY_CREATE_COMMUNITIES_ENABLED = "global/create_communities" let DEFAULT_FAKE_LOADING_SCREEN_ENABLED = defined(production) and not TEST_MODE_ENABLED #enabled in production, disabled in development and e2e tests const LAS_KEY_SHARDED_COMMUNITIES_ENABLED = "global/sharded_communities" const DEFAULT_LAS_KEY_SHARDED_COMMUNITIES_ENABLED = false const LAS_KEY_TRANSLATIONS_ENABLED = "global/translations_enabled" const DEFAULT_LAS_KEY_TRANSLATIONS_ENABLED = false +const DEFAULT_LAS_KEY_CREATE_COMMUNITIES_ENABLED = false QtObject: type LocalAppSettings* = ref object of QObject @@ -148,6 +150,19 @@ QtObject: write = setFakeLoadingScreenEnabled notify = fakeLoadingScreenEnabledChanged + proc createCommunityEnabledChanged*(self: LocalAppSettings) {.signal.} + proc getCreateCommunityEnabled*(self: LocalAppSettings): bool {.slot.} = + self.settings.value(LAS_KEY_CREATE_COMMUNITIES_ENABLED, newQVariant(DEFAULT_LAS_KEY_CREATE_COMMUNITIES_ENABLED)).boolVal + + proc setCreateCommunityEnabled*(self: LocalAppSettings, enabled: bool) {.slot.} = + self.settings.setValue(LAS_KEY_CREATE_COMMUNITIES_ENABLED, newQVariant(enabled)) + self.createCommunityEnabledChanged() + + QtProperty[bool] createCommunityEnabled: + read = getCreateCommunityEnabled + write = setCreateCommunityEnabled + notify = createCommunityEnabledChanged + proc wakuV2ShardedCommunitiesEnabledChanged*(self: LocalAppSettings) {.signal.} proc getWakuV2ShardedCommunitiesEnabled*(self: LocalAppSettings): bool {.slot.} = self.settings.value(LAS_KEY_SHARDED_COMMUNITIES_ENABLED, newQVariant(DEFAULT_LAS_KEY_SHARDED_COMMUNITIES_ENABLED)).boolVal diff --git a/ui/app/AppLayouts/Communities/CommunitiesPortalLayout.qml b/ui/app/AppLayouts/Communities/CommunitiesPortalLayout.qml index 87dc1028af..4ade03c4a9 100644 --- a/ui/app/AppLayouts/Communities/CommunitiesPortalLayout.qml +++ b/ui/app/AppLayouts/Communities/CommunitiesPortalLayout.qml @@ -137,14 +137,18 @@ StatusSectionLayout { onClicked: Global.importCommunityPopupRequested() } - StatusButton { - id: createBtn - objectName: "createCommunityButton" - Layout.preferredHeight: 38 - verticalPadding: 0 - text: qsTr("Create community") - onClicked: { - Global.openPopup(chooseCommunityCreationTypePopupComponent) + Loader { + Layout.preferredHeight: active ? 38 : 0 + active: communitiesStore.createCommunityEnabled || communitiesStore.testEnvironment + sourceComponent: StatusButton { + id: createBtn + objectName: "createCommunityButton" + height: parent.height + verticalPadding: 0 + text: qsTr("Create community") + onClicked: { + Global.openPopup(chooseCommunityCreationTypePopupComponent) + } } } } diff --git a/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml b/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml index 0747b7f210..6e88cecda0 100644 --- a/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml +++ b/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml @@ -35,6 +35,9 @@ QtObject { property bool downloadingCommunityHistoryArchives: root.communitiesModuleInst.downloadingCommunityHistoryArchives property var advancedModule: profileSectionModule.advancedModule + readonly property bool createCommunityEnabled: localAppSettings.createCommunityEnabled ?? false + readonly property bool testEnvironment: localAppSettings.testEnvironment ?? false + // TODO: Could the backend provide directly 2 filtered models?? //property var featuredCommunitiesModel: root.communitiesModuleInst.curatedFeaturedCommunities //property var popularCommunitiesModel: root.communitiesModuleInst.curatedPopularCommunities diff --git a/ui/app/AppLayouts/Profile/stores/AdvancedStore.qml b/ui/app/AppLayouts/Profile/stores/AdvancedStore.qml index 785d44bc01..fdc95cb487 100644 --- a/ui/app/AppLayouts/Profile/stores/AdvancedStore.qml +++ b/ui/app/AppLayouts/Profile/stores/AdvancedStore.qml @@ -22,6 +22,7 @@ QtObject { property var customNetworksModel: advancedModule? advancedModule.customNetworksModel : [] readonly property bool isFakeLoadingScreenEnabled: localAppSettings.fakeLoadingScreenEnabled ?? false + readonly property bool createCommunityEnabled: localAppSettings.createCommunityEnabled ?? false property bool isManageCommunityOnTestModeEnabled: false readonly property QtObject experimentalFeatures: QtObject { readonly property string browser: "browser" @@ -142,6 +143,13 @@ QtObject { localAppSettings.fakeLoadingScreenEnabled = !localAppSettings.fakeLoadingScreenEnabled } + function toggleCreateCommunityEnabled() { + if(!localAppSettings) + return + + localAppSettings.createCommunityEnabled = !localAppSettings.createCommunityEnabled + } + function toggleManageCommunityOnTestnet() { root.isManageCommunityOnTestModeEnabled = !root.isManageCommunityOnTestModeEnabled } diff --git a/ui/app/AppLayouts/Profile/views/AdvancedView.qml b/ui/app/AppLayouts/Profile/views/AdvancedView.qml index e94a19c4ef..ca0d40182c 100644 --- a/ui/app/AppLayouts/Profile/views/AdvancedView.qml +++ b/ui/app/AppLayouts/Profile/views/AdvancedView.qml @@ -171,6 +171,17 @@ SettingsContentBase { } } + StatusSettingsLineButton { + anchors.leftMargin: 0 + anchors.rightMargin: 0 + text: qsTr("Enable Community Creation") + isSwitch: true + switchChecked: root.advancedStore.createCommunityEnabled + onClicked: { + root.advancedStore.toggleCreateCommunityEnabled() + } + } + StatusSettingsLineButton { anchors.leftMargin: 0 anchors.rightMargin: 0