mirror of
				https://github.com/AppFlowy-IO/AppFlowy.git
				synced 2025-10-30 17:38:40 +00:00 
			
		
		
		
	 432db0f6d5
			
		
	
	
		432db0f6d5
		
			
		
	
	
	
	
		
			
			* chore: refactor the publish code * feat: integrate publish into database page * feat: add publish database structure * feat: add database row collab * feat: publish the database row collabs * chore: update collab * chore: improve question bubble * feat: publish the database relations * fix: rust ci * feat: select grid view to publish * feat: unable to deselect the primary database * feat: optimize the read recent views speed (#5726) * feat: optimize the read recent views speed * fix: order of recent views should be from the latest to the oldest * chore: update translations * fix: replace the unable to be selected icon * feat: remove left padding of inline database * fix: code review * chore: remove publish api err log * chore: read the database collab and document collab from disk instead of memory * chore: code cleanup * chore: revert beta.appflowy.com * chore: code cleanup * test: add database encode test * test: add publish database test * chore: refresh sidebar layout * chore: update comments
		
			
				
	
	
		
			125 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			125 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:appflowy/generated/flowy_svgs.g.dart';
 | |
| import 'package:appflowy/plugins/ai_chat/chat_page.dart';
 | |
| import 'package:appflowy/plugins/util.dart';
 | |
| import 'package:appflowy/startup/plugin/plugin.dart';
 | |
| import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart';
 | |
| import 'package:appflowy/workspace/presentation/home/home_stack.dart';
 | |
| import 'package:appflowy/workspace/presentation/widgets/tab_bar_item.dart';
 | |
| import 'package:appflowy/workspace/presentation/widgets/view_title_bar.dart';
 | |
| import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
 | |
| import 'package:flutter/material.dart';
 | |
| import 'package:flutter_bloc/flutter_bloc.dart';
 | |
| 
 | |
| class AIChatPluginBuilder extends PluginBuilder {
 | |
|   @override
 | |
|   Plugin build(dynamic data) {
 | |
|     if (data is ViewPB) {
 | |
|       return AIChatPagePlugin(view: data);
 | |
|     }
 | |
| 
 | |
|     throw FlowyPluginException.invalidData;
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   String get menuName => "AI Chat";
 | |
| 
 | |
|   @override
 | |
|   FlowySvgData get icon => FlowySvgs.chat_ai_page_s;
 | |
| 
 | |
|   @override
 | |
|   PluginType get pluginType => PluginType.chat;
 | |
| 
 | |
|   @override
 | |
|   ViewLayoutPB get layoutType => ViewLayoutPB.Chat;
 | |
| }
 | |
| 
 | |
| class AIChatPluginConfig implements PluginConfig {
 | |
|   @override
 | |
|   bool get creatable => true;
 | |
| }
 | |
| 
 | |
| class AIChatPagePlugin extends Plugin {
 | |
|   AIChatPagePlugin({
 | |
|     required ViewPB view,
 | |
|   }) : notifier = ViewPluginNotifier(view: view);
 | |
| 
 | |
|   late final ViewInfoBloc _viewInfoBloc;
 | |
| 
 | |
|   @override
 | |
|   final ViewPluginNotifier notifier;
 | |
| 
 | |
|   @override
 | |
|   PluginWidgetBuilder get widgetBuilder => AIChatPagePluginWidgetBuilder(
 | |
|         bloc: _viewInfoBloc,
 | |
|         notifier: notifier,
 | |
|       );
 | |
| 
 | |
|   @override
 | |
|   PluginId get id => notifier.view.id;
 | |
| 
 | |
|   @override
 | |
|   PluginType get pluginType => PluginType.chat;
 | |
| 
 | |
|   @override
 | |
|   void init() {
 | |
|     _viewInfoBloc = ViewInfoBloc(view: notifier.view)
 | |
|       ..add(const ViewInfoEvent.started());
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void dispose() {
 | |
|     _viewInfoBloc.close();
 | |
|     notifier.dispose();
 | |
|   }
 | |
| }
 | |
| 
 | |
| class AIChatPagePluginWidgetBuilder extends PluginWidgetBuilder
 | |
|     with NavigationItem {
 | |
|   AIChatPagePluginWidgetBuilder({
 | |
|     required this.bloc,
 | |
|     required this.notifier,
 | |
|   });
 | |
| 
 | |
|   final ViewInfoBloc bloc;
 | |
|   final ViewPluginNotifier notifier;
 | |
|   int? deletedViewIndex;
 | |
| 
 | |
|   @override
 | |
|   Widget get leftBarItem =>
 | |
|       ViewTitleBar(key: ValueKey(notifier.view.id), view: notifier.view);
 | |
| 
 | |
|   @override
 | |
|   Widget tabBarItem(String pluginId) => ViewTabBarItem(view: notifier.view);
 | |
| 
 | |
|   @override
 | |
|   Widget buildWidget({
 | |
|     required PluginContext context,
 | |
|     required bool shrinkWrap,
 | |
|     Map<String, dynamic>? data,
 | |
|   }) {
 | |
|     notifier.isDeleted.addListener(() {
 | |
|       final deletedView = notifier.isDeleted.value;
 | |
|       if (deletedView != null && deletedView.hasIndex()) {
 | |
|         deletedViewIndex = deletedView.index;
 | |
|       }
 | |
|     });
 | |
| 
 | |
|     return BlocProvider<ViewInfoBloc>.value(
 | |
|       value: bloc,
 | |
|       child: AIChatPage(
 | |
|         userProfile: context.userProfile!,
 | |
|         key: ValueKey(notifier.view.id),
 | |
|         view: notifier.view,
 | |
|         onDeleted: () =>
 | |
|             context.onDeleted?.call(notifier.view, deletedViewIndex),
 | |
|       ),
 | |
|     );
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   List<NavigationItem> get navigationItems => [this];
 | |
| 
 | |
|   @override
 | |
|   EdgeInsets get contentPadding => EdgeInsets.zero;
 | |
| }
 |