Skip to content

Commit

Permalink
Add two way sync to folder card and folder model
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Jun 17, 2024
1 parent 7fbe1d8 commit b8fb7c3
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
17 changes: 17 additions & 0 deletions lib/src/accounts/controllers/folder_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ class Folder extends _$Folder {
);
}

void toggleTwoWaySync(FolderModel model) {
final index = state.indexOf(model);
state = [
...state
..remove(model)
..insert(
index,
model.copyWith(isTwoWaySync: !model.isTwoWaySync),
)
];
Hive.box('vault').put(
hiveFoldersKey,
jsonEncode(state.map((e) => e.toJson()).toList()),
);
}

Future<void> createFolder(
AuthProviderModel authModel,
String folderPath,
Expand Down Expand Up @@ -152,6 +168,7 @@ class Folder extends _$Folder {
folderId: id,
isAutoSync: true,
isDeletionEnabled: false,
isTwoWaySync: false,
files: files,
);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/accounts/controllers/folder_controller.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/accounts/models/folder_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FolderModel with _$FolderModel {
required String folderId,
required bool isAutoSync,
required bool isDeletionEnabled,
required bool isTwoWaySync,
required List<CloudFileModel> files,
}) = _FolderModel;

Expand Down
25 changes: 24 additions & 1 deletion lib/src/accounts/models/folder_model.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mixin _$FolderModel {
String get folderId => throw _privateConstructorUsedError;
bool get isAutoSync => throw _privateConstructorUsedError;
bool get isDeletionEnabled => throw _privateConstructorUsedError;
bool get isTwoWaySync => throw _privateConstructorUsedError;
List<CloudFileModel> get files => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
Expand All @@ -49,6 +50,7 @@ abstract class $FolderModelCopyWith<$Res> {
String folderId,
bool isAutoSync,
bool isDeletionEnabled,
bool isTwoWaySync,
List<CloudFileModel> files});
}

Expand All @@ -72,6 +74,7 @@ class _$FolderModelCopyWithImpl<$Res, $Val extends FolderModel>
Object? folderId = null,
Object? isAutoSync = null,
Object? isDeletionEnabled = null,
Object? isTwoWaySync = null,
Object? files = null,
}) {
return _then(_value.copyWith(
Expand Down Expand Up @@ -103,6 +106,10 @@ class _$FolderModelCopyWithImpl<$Res, $Val extends FolderModel>
? _value.isDeletionEnabled
: isDeletionEnabled // ignore: cast_nullable_to_non_nullable
as bool,
isTwoWaySync: null == isTwoWaySync
? _value.isTwoWaySync
: isTwoWaySync // ignore: cast_nullable_to_non_nullable
as bool,
files: null == files
? _value.files
: files // ignore: cast_nullable_to_non_nullable
Expand All @@ -127,6 +134,7 @@ abstract class _$$FolderModelImplCopyWith<$Res>
String folderId,
bool isAutoSync,
bool isDeletionEnabled,
bool isTwoWaySync,
List<CloudFileModel> files});
}

Expand All @@ -148,6 +156,7 @@ class __$$FolderModelImplCopyWithImpl<$Res>
Object? folderId = null,
Object? isAutoSync = null,
Object? isDeletionEnabled = null,
Object? isTwoWaySync = null,
Object? files = null,
}) {
return _then(_$FolderModelImpl(
Expand Down Expand Up @@ -179,6 +188,10 @@ class __$$FolderModelImplCopyWithImpl<$Res>
? _value.isDeletionEnabled
: isDeletionEnabled // ignore: cast_nullable_to_non_nullable
as bool,
isTwoWaySync: null == isTwoWaySync
? _value.isTwoWaySync
: isTwoWaySync // ignore: cast_nullable_to_non_nullable
as bool,
files: null == files
? _value._files
: files // ignore: cast_nullable_to_non_nullable
Expand All @@ -198,6 +211,7 @@ class _$FolderModelImpl with DiagnosticableTreeMixin implements _FolderModel {
required this.folderId,
required this.isAutoSync,
required this.isDeletionEnabled,
required this.isTwoWaySync,
required final List<CloudFileModel> files})
: _files = files;

Expand All @@ -218,6 +232,8 @@ class _$FolderModelImpl with DiagnosticableTreeMixin implements _FolderModel {
final bool isAutoSync;
@override
final bool isDeletionEnabled;
@override
final bool isTwoWaySync;
final List<CloudFileModel> _files;
@override
List<CloudFileModel> get files {
Expand All @@ -228,7 +244,7 @@ class _$FolderModelImpl with DiagnosticableTreeMixin implements _FolderModel {

@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'FolderModel(email: $email, provider: $provider, folderPath: $folderPath, folderName: $folderName, folderId: $folderId, isAutoSync: $isAutoSync, isDeletionEnabled: $isDeletionEnabled, files: $files)';
return 'FolderModel(email: $email, provider: $provider, folderPath: $folderPath, folderName: $folderName, folderId: $folderId, isAutoSync: $isAutoSync, isDeletionEnabled: $isDeletionEnabled, isTwoWaySync: $isTwoWaySync, files: $files)';
}

@override
Expand All @@ -243,6 +259,7 @@ class _$FolderModelImpl with DiagnosticableTreeMixin implements _FolderModel {
..add(DiagnosticsProperty('folderId', folderId))
..add(DiagnosticsProperty('isAutoSync', isAutoSync))
..add(DiagnosticsProperty('isDeletionEnabled', isDeletionEnabled))
..add(DiagnosticsProperty('isTwoWaySync', isTwoWaySync))
..add(DiagnosticsProperty('files', files));
}

Expand All @@ -264,6 +281,8 @@ class _$FolderModelImpl with DiagnosticableTreeMixin implements _FolderModel {
other.isAutoSync == isAutoSync) &&
(identical(other.isDeletionEnabled, isDeletionEnabled) ||
other.isDeletionEnabled == isDeletionEnabled) &&
(identical(other.isTwoWaySync, isTwoWaySync) ||
other.isTwoWaySync == isTwoWaySync) &&
const DeepCollectionEquality().equals(other._files, _files));
}

Expand All @@ -278,6 +297,7 @@ class _$FolderModelImpl with DiagnosticableTreeMixin implements _FolderModel {
folderId,
isAutoSync,
isDeletionEnabled,
isTwoWaySync,
const DeepCollectionEquality().hash(_files));

@JsonKey(ignore: true)
Expand All @@ -303,6 +323,7 @@ abstract class _FolderModel implements FolderModel {
required final String folderId,
required final bool isAutoSync,
required final bool isDeletionEnabled,
required final bool isTwoWaySync,
required final List<CloudFileModel> files}) = _$FolderModelImpl;

factory _FolderModel.fromJson(Map<String, dynamic> json) =
Expand All @@ -323,6 +344,8 @@ abstract class _FolderModel implements FolderModel {
@override
bool get isDeletionEnabled;
@override
bool get isTwoWaySync;
@override
List<CloudFileModel> get files;
@override
@JsonKey(ignore: true)
Expand Down
2 changes: 2 additions & 0 deletions lib/src/accounts/models/folder_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions lib/src/home/views/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,29 @@ class _HomeViewState extends ConsumerState<HomeView> {
],
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Two way sync',
style: Theme.of(context).textTheme.bodyLarge,
),
SizedBox(
height: 30,
child: FittedBox(
fit: BoxFit.fill,
child: Switch(
value: e.isTwoWaySync,
onChanged: (val) =>
folderNotifier.toggleTwoWaySync(e),
),
),
)
],
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
Expand All @@ -379,9 +402,7 @@ class _HomeViewState extends ConsumerState<HomeView> {
'Delete on sync',
style: Theme.of(context).textTheme.bodyLarge,
),
// Spacer(),
SizedBox(
// width: 10,
height: 30,
child: FittedBox(
fit: BoxFit.fill,
Expand Down

0 comments on commit b8fb7c3

Please sign in to comment.