Refactoring: extract create share fn

This commit is contained in:
Ming Ming 2021-09-28 14:37:16 +08:00
parent 20dfc2e00e
commit 19367e2a0d
2 changed files with 11 additions and 1 deletions

View file

@ -2,6 +2,15 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/share.dart'; import 'package:nc_photos/entity/share.dart';
class CreateUserShare {
const CreateUserShare(this.shareRepo);
Future<Share> call(Account account, File file, String shareWith) =>
shareRepo.create(account, file, shareWith);
final ShareRepo shareRepo;
}
class CreateLinkShare { class CreateLinkShare {
const CreateLinkShare(this.shareRepo); const CreateLinkShare(this.shareRepo);

View file

@ -14,6 +14,7 @@ import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/iterable_extension.dart';
import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/use_case/create_share.dart';
class ShareAlbumDialog extends StatefulWidget { class ShareAlbumDialog extends StatefulWidget {
const ShareAlbumDialog({ const ShareAlbumDialog({
@ -146,7 +147,7 @@ class _ShareAlbumDialogState extends State<ShareAlbumDialog> {
if (share == null) { if (share == null) {
// create new share // create new share
try { try {
final newShare = await shareRepo.create( final newShare = await CreateUserShare(shareRepo)(
widget.account, widget.file, sharee.shareWith); widget.account, widget.file, sharee.shareWith);
_overrideSharee[sharee.shareWith] = newShare; _overrideSharee[sharee.shareWith] = newShare;
} catch (e, stackTrace) { } catch (e, stackTrace) {