mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: refacotor share bloc
This commit is contained in:
parent
0709a2d2ee
commit
a2c52508fa
@ -14,7 +14,7 @@ part 'document_share_bloc.freezed.dart';
|
|||||||
class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
|
class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
|
||||||
DocumentShareBloc({
|
DocumentShareBloc({
|
||||||
required this.view,
|
required this.view,
|
||||||
}) : super(const DocumentShareState.initial()) {
|
}) : super(DocumentShareState.initial()) {
|
||||||
on<DocumentShareEvent>((event, emit) async {
|
on<DocumentShareEvent>((event, emit) async {
|
||||||
await event.when(
|
await event.when(
|
||||||
share: (type, path) async {
|
share: (type, path) async {
|
||||||
@ -23,7 +23,9 @@ class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(const DocumentShareState.loading());
|
emit(
|
||||||
|
state.copyWith(isLoading: true),
|
||||||
|
);
|
||||||
|
|
||||||
final exporter = DocumentExporter(view);
|
final exporter = DocumentExporter(view);
|
||||||
final FlowyResult<ExportDataPB, FlowyError> result =
|
final FlowyResult<ExportDataPB, FlowyError> result =
|
||||||
@ -46,7 +48,12 @@ class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
emit(DocumentShareState.finish(result));
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
exportResult: result,
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -93,15 +100,20 @@ enum DocumentShareType {
|
|||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
class DocumentShareEvent with _$DocumentShareEvent {
|
class DocumentShareEvent with _$DocumentShareEvent {
|
||||||
const factory DocumentShareEvent.share(DocumentShareType type, String? path) =
|
const factory DocumentShareEvent.share(
|
||||||
Share;
|
DocumentShareType type,
|
||||||
|
String? path,
|
||||||
|
) = Share;
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
class DocumentShareState with _$DocumentShareState {
|
class DocumentShareState with _$DocumentShareState {
|
||||||
const factory DocumentShareState.initial() = _Initial;
|
const factory DocumentShareState({
|
||||||
const factory DocumentShareState.loading() = _Loading;
|
required bool isLoading,
|
||||||
const factory DocumentShareState.finish(
|
FlowyResult<ExportDataPB, FlowyError>? exportResult,
|
||||||
FlowyResult<ExportDataPB, FlowyError> successOrFail,
|
}) = _DocumentShareState;
|
||||||
) = _Finish;
|
|
||||||
|
factory DocumentShareState.initial() => const DocumentShareState(
|
||||||
|
isLoading: false,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -33,14 +33,12 @@ class DocumentShareButton extends StatelessWidget {
|
|||||||
create: (context) => getIt<DocumentShareBloc>(param1: view),
|
create: (context) => getIt<DocumentShareBloc>(param1: view),
|
||||||
child: BlocListener<DocumentShareBloc, DocumentShareState>(
|
child: BlocListener<DocumentShareBloc, DocumentShareState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
state.mapOrNull(
|
if (state.isLoading == false && state.exportResult != null) {
|
||||||
finish: (state) {
|
state.exportResult!.fold(
|
||||||
state.successOrFail.fold(
|
(data) => _handleExportData(context, data),
|
||||||
(data) => _handleExportData(context, data),
|
_handleExportError,
|
||||||
_handleExportError,
|
);
|
||||||
);
|
}
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
child: BlocBuilder<DocumentShareBloc, DocumentShareState>(
|
child: BlocBuilder<DocumentShareBloc, DocumentShareState>(
|
||||||
builder: (context, state) => SizedBox(
|
builder: (context, state) => SizedBox(
|
||||||
|
Loading…
Reference in New Issue
Block a user