Skip to content

Commit 27a26e9

Browse files
committed
fix(BackupView): remove store access
- use plain properties instead of passing the DevicesStore into the BackupView - adjust ProfileLayout and the SB page - remove anchors usage
1 parent ba606ff commit 27a26e9

File tree

4 files changed

+60
-58
lines changed

4 files changed

+60
-58
lines changed

storybook/pages/BackupViewPage.qml

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import QtQuick.Controls
44
import QtQuick.Layouts
55

66
import StatusQ
7+
import StatusQ.Core.Backpressure
78

89
import Storybook
910

1011
import AppLayouts.Profile.views
11-
import AppLayouts.Profile.stores as ProfileStores
1212

1313
import utils
1414

@@ -24,29 +24,11 @@ SplitView {
2424

2525
contentWidth: 664
2626

27-
devicesStore: ProfileStores.DevicesStore {
28-
property int backupImportState: Constants.BackupImportState.None
29-
readonly property string backupImportError: ctrlErrorState.checked ? "ERR" : ""
30-
function importLocalBackupFile(filePath) {
31-
logs.logEvent("DevicesStore::importLocalBackupFile", ["filePath"], arguments)
32-
backupImportState = Constants.BackupImportState.Completed
33-
}
34-
35-
property int backupDataState: Constants.BackupImportState.None
36-
readonly property string backupDataError: ctrlErrorState.checked ? "ERR" : ""
37-
function performLocalBackup() {
38-
logs.logEvent("DevicesStore::performLocalBackup()")
39-
backupDataState = Constants.BackupImportState.Completed
40-
}
41-
function resetBackupDataState() {
42-
logs.logEvent("DevicesStore::resetBackupDataState()")
43-
backupDataState = Constants.BackupImportState.None
44-
}
27+
backupDataState: Constants.BackupImportState.None
28+
backupDataError: ctrlErrorState.checked ? "ERR" : ""
4529

46-
function toFileUri(path) {
47-
return UrlUtils.urlFromUserInput(path)
48-
}
49-
}
30+
backupImportState: Constants.BackupImportState.None
31+
backupImportError: ctrlErrorState.checked ? "ERR" : ""
5032

5133
backupPath: StandardPaths.writableLocation(StandardPaths.TempLocation)
5234
messagesBackupEnabled: false
@@ -58,6 +40,17 @@ SplitView {
5840
logs.logEvent("BackupView::backupMessagesEnabledToggled", ["enabled"], arguments)
5941
messagesBackupEnabled = enabled
6042
}
43+
44+
onPerformLocalBackupRequested: {
45+
logs.logEvent("BackupView::onPerformLocalBackupRequested")
46+
backupDataState = Constants.BackupImportState.Completed
47+
Backpressure.debounce(this, 5000, () => {
48+
backupDataState = Constants.BackupImportState.None
49+
})()
50+
}
51+
onImportLocalBackupFileRequested: function(selectedFile) {
52+
logs.logEvent("BackupView::onImportLocalBackupFileRequested", ["selectedFile"], arguments)
53+
}
6154
}
6255

6356
LogsAndControlsPanel {

ui/app/AppLayouts/Profile/ProfileLayout.qml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -612,15 +612,18 @@ StatusSectionLayout {
612612
contentWidth: d.contentWidth
613613
sectionTitle: settingsEntriesModel.getNameForSubsection(Constants.settingsSubsection.backupSettings)
614614

615-
devicesStore: root.devicesStore
615+
backupDataState: root.devicesStore.backupDataState
616+
backupDataError: root.devicesStore.backupDataError
617+
618+
backupImportState: root.devicesStore.backupImportState
619+
backupImportError: root.devicesStore.backupImportError
620+
616621
backupPath: root.devicesStore.backupPath
617622
messagesBackupEnabled: root.devicesStore.messagesBackupEnabled
618-
onBackupPathSet: function(path) {
619-
root.devicesStore.setBackupPath(path)
620-
}
621-
onBackupMessagesEnabledToggled: function(enabled) {
622-
root.devicesStore.setMessagesBackupEnabled(enabled)
623-
}
623+
onBackupPathSet: path => root.devicesStore.setBackupPath(path)
624+
onBackupMessagesEnabledToggled: enabled => root.devicesStore.setMessagesBackupEnabled(enabled)
625+
onPerformLocalBackupRequested: root.devicesStore.performLocalBackup()
626+
onImportLocalBackupFileRequested: selectedFile => root.devicesStore.importLocalBackupFile(selectedFile)
624627
}
625628
}
626629
}

ui/app/AppLayouts/Profile/stores/DevicesStore.qml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import QtQuick
22
import utils
33

44
import StatusQ.Core.Utils 0.1 as StatusQUtils
5+
import StatusQ.Core.Backpressure
56

67
QtObject {
78
id: root
@@ -26,7 +27,7 @@ QtObject {
2627
readonly property int backupDataState: syncModule ? syncModule.backupDataState : 0
2728
readonly property string backupImportError: syncModule ? syncModule.backupImportError : ""
2829
readonly property string backupDataError: syncModule ? syncModule.backupDataError : ""
29-
readonly property url backupPath: d.appSettingsInst.backupPath
30+
readonly property url backupPath: toFileUri(d.appSettingsInst.backupPath)
3031
readonly property bool messagesBackupEnabled: d.appSettingsInst.messagesBackupEnabled
3132

3233
readonly property QtObject _d: StatusQUtils.QObject {
@@ -107,6 +108,9 @@ QtObject {
107108

108109
function performLocalBackup() {
109110
root.syncModule.performLocalBackup()
111+
Backpressure.debounce(this, 5000, () => {
112+
resetBackupDataState()
113+
})()
110114
}
111115

112116
function resetBackupDataState() {

ui/app/AppLayouts/Profile/views/BackupView.qml

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,31 @@ import QtQuick.Layouts
44

55
import StatusQ
66
import StatusQ.Core
7-
import StatusQ.Core.Backpressure
87
import StatusQ.Controls
98
import StatusQ.Core.Theme
109
import StatusQ.Popups.Dialog
1110

12-
import AppLayouts.Profile.stores as ProfileStores
13-
1411
import utils
15-
import shared.panels
1612
import shared.status
1713

1814
SettingsContentBase {
1915
id: root
2016

21-
required property ProfileStores.DevicesStore devicesStore
17+
required property int backupDataState // Constants.BackupImportState.*
18+
required property string backupDataError
19+
20+
required property int backupImportState // Constants.BackupImportState.*
21+
required property string backupImportError
22+
2223
required property bool messagesBackupEnabled
2324
required property url backupPath
2425

2526
signal backupPathSet(url path)
2627
signal backupMessagesEnabledToggled(bool enabled)
2728

29+
signal performLocalBackupRequested()
30+
signal importLocalBackupFileRequested(url selectedFile)
31+
2832
ColumnLayout {
2933
id: layout
3034
width: root.contentWidth
@@ -59,31 +63,26 @@ SettingsContentBase {
5963
Layout.leftMargin: Theme.padding
6064
text: qsTr("Backup now")
6165
icon.name: {
62-
if (root.devicesStore.backupDataState !== Constants.BackupImportState.Completed) {
66+
if (root.backupDataState !== Constants.BackupImportState.Completed) {
6367
return ""
6468
}
65-
if (root.devicesStore.backupDataError) {
69+
if (root.backupDataError) {
6670
return "tiny/exclamation"
6771
}
6872
return "tiny/checkmark"
6973
}
7074
icon.color: {
71-
if (root.devicesStore.backupDataState !== Constants.BackupImportState.Completed) {
75+
if (root.backupDataState !== Constants.BackupImportState.Completed) {
7276
return Theme.palette.primaryColor1
7377
}
74-
if (root.devicesStore.backupDataError) {
78+
if (root.backupDataError) {
7579
return Theme.palette.dangerColor1
7680
}
7781
return Theme.palette.successColor1
7882
}
7983

80-
loading: root.devicesStore.backupDataState === Constants.BackupImportState.InProgress
81-
onClicked : {
82-
root.devicesStore.performLocalBackup()
83-
Backpressure.debounce(this, 5000, () => {
84-
root.devicesStore.resetBackupDataState()
85-
})()
86-
}
84+
loading: root.backupDataState === Constants.BackupImportState.InProgress
85+
onClicked: root.performLocalBackupRequested()
8786
}
8887

8988
Separator {
@@ -110,12 +109,10 @@ SettingsContentBase {
110109

111110
StatusSettingsLineButton {
112111
Layout.fillWidth: true
113-
anchors.leftMargin: 0
114-
anchors.rightMargin: 0
115112
text: qsTr("Backup your messages")
116113
isSwitch: true
117-
switchChecked: root.messagesBackupEnabled
118-
onClicked: (checked) => root.backupMessagesEnabledToggled(checked)
114+
checked: root.messagesBackupEnabled
115+
onToggled: root.backupMessagesEnabledToggled(checked)
119116
}
120117

121118
Separator {
@@ -177,33 +174,33 @@ SettingsContentBase {
177174
StatusButton {
178175
Layout.leftMargin: Theme.padding
179176
text: qsTr("Import backup file")
180-
loading: root.devicesStore.backupImportState === Constants.BackupImportState.InProgress
177+
loading: root.backupImportState === Constants.BackupImportState.InProgress
181178
onClicked: importBackupFileDialog.open()
182179
}
183180

184181
StatusBaseText {
185182
Layout.fillWidth: true
186183
Layout.leftMargin: Theme.padding
187184
color: Theme.palette.successColor1
188-
visible: root.devicesStore.backupImportState === Constants.BackupImportState.Completed && !root.devicesStore.backupImportError
185+
visible: root.backupImportState === Constants.BackupImportState.Completed && !root.backupImportError
189186
text: qsTr("Success importing local data")
190187
}
191188

192189
StatusBaseText {
193190
Layout.fillWidth: true
194191
Layout.leftMargin: Theme.padding
195192
color: Theme.palette.dangerColor1
196-
visible: !!root.devicesStore.backupImportError
193+
visible: !!root.backupImportError
197194
wrapMode: Text.WordWrap
198-
text: qsTr("Error importing backup file: %1").arg(root.devicesStore.backupImportError)
195+
text: qsTr("Error importing backup file: %1").arg(root.backupImportError)
199196
}
200197
}
201198

202199
StatusFolderDialog {
203200
id: backupPathDialog
204201

205202
title: qsTr("Select your backup directory")
206-
currentFolder: root.devicesStore.toFileUri(root.backupPath)
203+
currentFolder: root.backupPath
207204
onAccepted: root.backupPathSet(backupPathDialog.selectedFolder)
208205
}
209206

@@ -212,7 +209,12 @@ SettingsContentBase {
212209

213210
title: qsTr("Select your backup file")
214211
nameFilters: [qsTr("Supported backup formats (%1)").arg("*.bkp")]
215-
currentFolder: root.devicesStore.toFileUri(root.backupPath)
216-
onAccepted: root.devicesStore.importLocalBackupFile(importBackupFileDialog.selectedFile)
212+
currentFolder: root.backupPath
213+
onAccepted: root.importLocalBackupFileRequested(importBackupFileDialog.selectedFile)
214+
}
215+
216+
component Separator: Rectangle {
217+
implicitHeight: 1
218+
color: Theme.palette.separator
217219
}
218220
}

0 commit comments

Comments
 (0)