Skip to content

Commit

Permalink
dataRowsProvider is no longer a family provider because the app does …
Browse files Browse the repository at this point in the history
…not need to use multiple dataRowsProviders at the same time
  • Loading branch information
enm10k committed Jun 13, 2024
1 parent 9cbe883 commit e8027fb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/features/core/components/cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Cell {
final view = ref.watch(viewProvider)!;
return () {
ref
.watch(dataRowsProvider(view).notifier)
.watch(dataRowsProvider.notifier)
.updateRow(
rowId: rowId!,
data: {column.title: value != true},
Expand All @@ -102,7 +102,7 @@ class Cell {
required NcView view,
}) {
ref
.watch(dataRowsProvider(view).notifier)
.watch(dataRowsProvider.notifier)
.updateRow(
rowId: rowId,
data: {title: value},
Expand Down
4 changes: 2 additions & 2 deletions lib/features/core/components/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class Editor extends HookConsumerWidget {

final onUpdate = isNew
? (Map<String, dynamic> data) {
final form = ref.watch(formProvider);
final form = ref.read(formProvider);
final newForm = {...form, ...data};
logger.info('form updated: $newForm');
ref.watch(formProvider.notifier).state = newForm;
}
: (data) {
ref
.read(dataRowsProvider(view).notifier)
.read(dataRowsProvider.notifier)
.updateRow(
rowId: rowId!,
data: data,
Expand Down
4 changes: 2 additions & 2 deletions lib/features/core/components/views/grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Grid extends HookConsumerWidget {
logger.info('view: ${view.title} has ${columns.length} columns(s).');
logger.info('columns: ${columns.map((e) => e.title).toList()}');

final dataRow = ref.watch(dataRowsProvider(view)).valueOrNull;
final dataRow = ref.watch(dataRowsProvider).valueOrNull;
final rows = dataRow?.list ?? [];

if (columns.isEmpty) {
Expand Down Expand Up @@ -169,7 +169,7 @@ class Grid extends HookConsumerWidget {
onEnd: () async {
context.loaderOverlay.show();

await ref.read(dataRowsProvider(view).notifier).loadNextPage().then(
await ref.read(dataRowsProvider.notifier).loadNextPage().then(
(_) => Future.delayed(
const Duration(milliseconds: 500),
() => context.loaderOverlay.hide(),
Expand Down
2 changes: 1 addition & 1 deletion lib/features/core/pages/attachment_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class AttachmentEditorPage extends HookConsumerWidget {
return const SizedBox();
}
onUpdate(row) {
final dataRowsNotifier = ref.read(dataRowsProvider(view).notifier);
final dataRowsNotifier = ref.read(dataRowsProvider.notifier);
dataRowsNotifier
.updateRow(rowId: rowId, data: row)
.then(
Expand Down
6 changes: 3 additions & 3 deletions lib/features/core/pages/row_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class RowEditor extends HookConsumerWidget {
required BuildContext context,
required String? rowId,
}) {
final rows = ref.watch(dataRowsProvider(view)).valueOrNull?.list ?? [];
final rows = ref.watch(dataRowsProvider).valueOrNull?.list ?? [];
final table = ref.watch(tableProvider);
final rowData = rows.firstWhereOrNull((row) {
return table?.getPkFromRow(row) == rowId;
Expand Down Expand Up @@ -171,7 +171,7 @@ class RowEditor extends HookConsumerWidget {
onPressed: () {
Navigator.pop(context);
ref
.watch(dataRowsProvider(view).notifier)
.watch(dataRowsProvider.notifier)
.deleteRow(rowId: rowId_!)
.then(
(_) => Navigator.pop(context),
Expand Down Expand Up @@ -217,7 +217,7 @@ class RowEditor extends HookConsumerWidget {

if (isReadyToSave) {
// TODO: This should be passed to Editor as a callback of onUpdate,
ref.read(dataRowsProvider(view).notifier).createRow(next).then((row) {
ref.read(dataRowsProvider.notifier).createRow(next).then((row) {
notifySuccess(context, message: 'Saved');
final pk = tables.table.getPkFromRow(row);
rowId.value = pk;
Expand Down
11 changes: 8 additions & 3 deletions lib/features/core/providers/providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,14 @@ class DataRows extends _$DataRows {
}

@override
Future<NcRowList?> build(NcView view) async {
Future<NcRowList?> build() async {
final isLoaded = ref.watch(isLoadedProvider);
if (!isLoaded) {
return null;
}
final table = ref.watch(tableProvider)!;
final tables = ref.watch(tablesProvider)!;
final view = ref.watch(viewProvider)!;

// This provider should be updated every time sort is updated.
// final _ = ref.watch(sortListProvider(view.id));
Expand All @@ -232,7 +233,8 @@ class DataRows extends _$DataRows {
return;
}

final tables = ref.watch(tablesProvider)!;
final tables = ref.read(tablesProvider)!;
final view = ref.read(viewProvider)!;
final value = state.value;
if (value == null) {
assert(false);
Expand Down Expand Up @@ -267,6 +269,7 @@ class DataRows extends _$DataRows {
Future<void> deleteRow({
required String rowId,
}) async {
final view = ref.read(viewProvider)!;
await api.dbViewRowDelete(
view: view,
rowId: rowId,
Expand Down Expand Up @@ -297,6 +300,7 @@ class DataRows extends _$DataRows {
required Map<String, dynamic> data,
}) async {
// The result doesn't contain related fields.
final view = ref.read(viewProvider)!;
final result = await api.dbViewRowUpdate(
view: view,
rowId: rowId,
Expand Down Expand Up @@ -336,6 +340,7 @@ class DataRows extends _$DataRows {
}

Future<Map<String, dynamic>> createRow(Map<String, dynamic> row) async {
final view = ref.read(viewProvider)!;
final newRow = await api.dbViewRowCreate(
view: view,
data: row,
Expand Down Expand Up @@ -552,7 +557,7 @@ class SortList extends _$SortList {
class Attachments extends _$Attachments {
@override
List<NcAttachedFile> build(NcView view, String? rowId, String columnTitle) {
final rows = ref.watch(dataRowsProvider(view)).valueOrNull?.list ?? [];
final rows = ref.watch(dataRowsProvider).valueOrNull?.list ?? [];
final table = ref.watch(tableProvider);
final row = rows.firstWhereOrNull((row) {
return table?.getPkFromRow(row) == rowId;
Expand Down

0 comments on commit e8027fb

Please sign in to comment.