-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from enm10k/feature/small-refactor-and-reload
Add reload button + small refactoring
- Loading branch information
Showing
17 changed files
with
415 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
} | ||
} |
Oops, something went wrong.