mirror of
				https://github.com/AppFlowy-IO/AppFlowy.git
				synced 2025-10-31 10:03:18 +00:00 
			
		
		
		
	 61fd608200
			
		
	
	
		61fd608200
		
			
		
	
	
	
	
		
			
			* refactor: rename structs * chore: read database id from view * chore: fix open database error because of create a database view for database id * chore: fix tests * chore: rename datbase id to view id in flutter * refactor: move grid and board to database view folder * refactor: rename functions * refactor: move calender to datbase view folder * refactor: rename app_flowy to appflowy_flutter * chore: reanming * chore: fix freeze gen * chore: remove todos * refactor: view process events * chore: add link database test * chore: just open view if there is opened database
		
			
				
	
	
		
			74 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'dart:convert';
 | |
| import 'dart:io';
 | |
| import 'package:appflowy/plugins/document/application/share_service.dart';
 | |
| import 'package:appflowy/plugins/document/presentation/plugins/parsers/divider_node_parser.dart';
 | |
| import 'package:appflowy/plugins/document/presentation/plugins/parsers/math_equation_node_parser.dart';
 | |
| import 'package:appflowy_backend/protobuf/flowy-document/entities.pb.dart';
 | |
| import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
 | |
| import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
 | |
| import 'package:freezed_annotation/freezed_annotation.dart';
 | |
| import 'package:flutter_bloc/flutter_bloc.dart';
 | |
| import 'package:dartz/dartz.dart';
 | |
| import 'package:appflowy_editor/appflowy_editor.dart'
 | |
|     show Document, documentToMarkdown;
 | |
| part 'share_bloc.freezed.dart';
 | |
| 
 | |
| class DocShareBloc extends Bloc<DocShareEvent, DocShareState> {
 | |
|   ShareService service;
 | |
|   ViewPB view;
 | |
|   DocShareBloc({required this.view, required this.service})
 | |
|       : super(const DocShareState.initial()) {
 | |
|     on<DocShareEvent>((event, emit) async {
 | |
|       await event.map(
 | |
|         shareMarkdown: (ShareMarkdown shareMarkdown) async {
 | |
|           await service.exportMarkdown(view).then((result) {
 | |
|             result.fold(
 | |
|               (value) => emit(
 | |
|                 DocShareState.finish(
 | |
|                   left(_saveMarkdown(value, shareMarkdown.path)),
 | |
|                 ),
 | |
|               ),
 | |
|               (error) => emit(DocShareState.finish(right(error))),
 | |
|             );
 | |
|           });
 | |
| 
 | |
|           emit(const DocShareState.loading());
 | |
|         },
 | |
|         shareLink: (ShareLink value) {},
 | |
|         shareText: (ShareText value) {},
 | |
|       );
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   ExportDataPB _saveMarkdown(ExportDataPB value, String path) {
 | |
|     final markdown = _convertDocumentToMarkdown(value);
 | |
|     value.data = markdown;
 | |
|     File(path).writeAsStringSync(markdown);
 | |
|     return value;
 | |
|   }
 | |
| 
 | |
|   String _convertDocumentToMarkdown(ExportDataPB value) {
 | |
|     final json = jsonDecode(value.data);
 | |
|     final document = Document.fromJson(json);
 | |
|     return documentToMarkdown(document, customParsers: [
 | |
|       const DividerNodeParser(),
 | |
|       const MathEquationNodeParser(),
 | |
|     ]);
 | |
|   }
 | |
| }
 | |
| 
 | |
| @freezed
 | |
| class DocShareEvent with _$DocShareEvent {
 | |
|   const factory DocShareEvent.shareMarkdown(String path) = ShareMarkdown;
 | |
|   const factory DocShareEvent.shareText() = ShareText;
 | |
|   const factory DocShareEvent.shareLink() = ShareLink;
 | |
| }
 | |
| 
 | |
| @freezed
 | |
| class DocShareState with _$DocShareState {
 | |
|   const factory DocShareState.initial() = _Initial;
 | |
|   const factory DocShareState.loading() = _Loading;
 | |
|   const factory DocShareState.finish(
 | |
|       Either<ExportDataPB, FlowyError> successOrFail) = _Finish;
 | |
| }
 |