Skip to content

Commit

Permalink
Merge pull request #28 from enm10k/feature/small-refactor-and-reload
Browse files Browse the repository at this point in the history
Add reload button + small refactoring
  • Loading branch information
enm10k authored Jun 28, 2024
2 parents bf053cf + f20cb88 commit 65cd897
Show file tree
Hide file tree
Showing 17 changed files with 415 additions and 255 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
run_integration_test rit:
flutter run --dart-define-from-file=integration_test/.env -t integration_test/hello_test.dart

run_unit_test rut:
flutter run --dart-define-from-file=test/.env -t test/provider_test.dart
# dart test test/provider_test.dart

fix:
dart fix --apply lib
dart fix --apply integration_test
Expand Down
1 change: 0 additions & 1 deletion lib/features/core/components/cells/single_select.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import 'package:nocodb/nocodb_sdk/models.dart';

class SingleSelect extends HookConsumerWidget {
Expand Down
1 change: 1 addition & 0 deletions lib/features/core/components/dialog/sort_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nocodb/common/flash_wrapper.dart';
import 'package:nocodb/common/logger.dart';
import 'package:nocodb/features/core/providers/providers.dart';
import 'package:nocodb/features/core/providers/sort_list_provider.dart';
import 'package:nocodb/nocodb_sdk/models.dart';
import 'package:nocodb/nocodb_sdk/symbols.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/features/core/components/editors/attachment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nocodb/features/core/components/attachment_file_card.dart';
import 'package:nocodb/features/core/components/attachment_image_card.dart';
import 'package:nocodb/features/core/pages/attachment_editor.dart';
import 'package:nocodb/features/core/providers/providers.dart';
import 'package:nocodb/features/core/providers/attachments_provider.dart';
import 'package:nocodb/nocodb_sdk/models.dart' as model;
import 'package:nocodb/nocodb_sdk/models.dart';
import 'package:nocodb/nocodb_sdk/symbols.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/features/core/pages/attachment_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:nocodb/common/logger.dart';
import 'package:nocodb/features/core/components/attachment_file_card.dart';
import 'package:nocodb/features/core/components/attachment_image_card.dart';
import 'package:nocodb/features/core/components/dialog/file_rename_dialog.dart';
import 'package:nocodb/features/core/providers/attachments_provider.dart';
import 'package:nocodb/features/core/providers/providers.dart';
import 'package:nocodb/features/core/utils.dart';
import 'package:nocodb/nocodb_sdk/client.dart';
Expand Down
6 changes: 4 additions & 2 deletions lib/features/core/pages/cloud_project_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nocodb/common/settings.dart';
import 'package:nocodb/features/core/components/dialog/new_project_dialog.dart';
import 'package:nocodb/features/core/providers/providers.dart';
import 'package:nocodb/features/core/providers/utils.dart';
import 'package:nocodb/nocodb_sdk/models.dart';
import 'package:nocodb/routes.dart';

Expand Down Expand Up @@ -36,8 +37,9 @@ class _ProjectList extends HookConsumerWidget {
child: ListTile(
title: Text(project.title),
onTap: () async {
ref.read(projectProvider.notifier).state = project;
await const SheetRoute().push(context);
await selectProject(ref, project).then(
(data) async => await const SheetRoute().push(context),
);
},
),
);
Expand Down
6 changes: 4 additions & 2 deletions lib/features/core/pages/project_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nocodb/common/settings.dart';
import 'package:nocodb/features/core/components/dialog/new_project_dialog.dart';
import 'package:nocodb/features/core/providers/providers.dart';
import 'package:nocodb/features/core/providers/utils.dart';
import 'package:nocodb/nocodb_sdk/models.dart';
import 'package:nocodb/routes.dart';

Expand Down Expand Up @@ -59,8 +60,9 @@ class ProjectListPage extends HookConsumerWidget {
child: ListTile(
title: Text(project.title),
onTap: () async {
ref.read(projectProvider.notifier).state = project;
await const SheetRoute().push(context);
await selectProject(ref, project).then(
(data) async => await const SheetRoute().push(context),
);
},
),
);
Expand Down
10 changes: 7 additions & 3 deletions lib/features/core/pages/sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class SheetPage extends HookConsumerWidget {
builder: (_) => const SheetSearchDialog(),
),
),
BottomAppBarButton(
iconData: Icons.refresh,
onPressed: () {
ref.invalidate(dataRowsProvider);
},
),
],
),
),
Expand Down Expand Up @@ -95,9 +101,7 @@ class SheetPage extends HookConsumerWidget {
Navigator.pop(context);
},
),
actions: const [
// ReloadButton(),
],
actions: const [],
title: Text(project.title),
),
body: Column(
Expand Down
12 changes: 7 additions & 5 deletions lib/features/core/pages/sheet_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nocodb/common/flash_wrapper.dart';
import 'package:nocodb/common/logger.dart';
import 'package:nocodb/features/core/providers/providers.dart';
import 'package:nocodb/features/core/providers/utils.dart';
import 'package:nocodb/nocodb_sdk/client.dart';
import 'package:nocodb/nocodb_sdk/models.dart';

Expand Down Expand Up @@ -31,9 +32,10 @@ class SheetSelectorPage extends HookConsumerWidget {
title: Text(view.title),
subtitle: Text('type: ${view.type.name}'),
selected: view.id == viewId,
onTap: () {
ref.read(viewProvider.notifier).set(view);
Navigator.pop(context);
onTap: () async {
await selectView(ref, view).then(
(value) => Navigator.pop(context),
);
},
);
},
Expand Down Expand Up @@ -125,8 +127,8 @@ class SheetSelectorPage extends HookConsumerWidget {
final table = tables[index];
await api.dbTableRead(tableId: table.id).then((result) {
result.when(
ok: (table) {
ref.watch(viewProvider.notifier).set(table.views.first);
ok: (table) async {
await selectTable(ref, table);
},
ng: (error, stackTrace) =>
notifyError(context, error, stackTrace),
Expand Down
54 changes: 54 additions & 0 deletions lib/features/core/providers/attachments_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:collection/collection.dart';
import 'package:nocodb/features/core/providers/providers.dart';
import 'package:nocodb/nocodb_sdk/client.dart';
import 'package:nocodb/nocodb_sdk/models.dart';
import 'package:nocodb/nocodb_sdk/symbols.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'attachments_provider.g.dart';

@riverpod
class Attachments extends _$Attachments {
@override
List<NcAttachedFile> build(
String? rowId,
String columnTitle,
) {
final rows = ref.watch(dataRowsProvider).valueOrNull?.list ?? [];
final table = ref.watch(tableProvider);
final row = rows.firstWhereOrNull(
(row) => table?.getPkFromRow(row) == rowId,
) ??
{};

final files = (row[columnTitle] ?? [])
.map<NcAttachedFile>(
(e) => NcAttachedFile.fromJson(e as Map<String, dynamic>),
)
.toList() as List<NcAttachedFile>;
return files;
}

upload(List<NcFile> files, FnOnUpdate onUpdate) async {
final newAttachedFiles = await api.dbStorageUpload(files);
state = [
...state,
...newAttachedFiles,
];
await onUpdate({columnTitle: state});
}

delete(String id, FnOnUpdate onUpdate) async {
state = [...state].where((e) => e.id != id).toList();
await onUpdate({columnTitle: state});
}

rename(String id, String title, FnOnUpdate onUpdate) async {
state = [...state]
.map<NcAttachedFile>(
(e) => e.id == id ? e.copyWith(title: title) : e,
)
.toList();
await onUpdate({columnTitle: state});
}
}
Loading

0 comments on commit 65cd897

Please sign in to comment.