From 83778635ae51081d7f027ce9acbdabafc70ff05c Mon Sep 17 00:00:00 2001 From: appflowy Date: Thu, 22 Jul 2021 12:23:14 +0800 Subject: [PATCH] show app list on home screen --- .../lib/home/application/app/app_bloc.dart | 7 +- .../home/application/app/app_watch_bloc.dart | 2 +- .../home/infrastructure/deps_resolver.dart | 6 ++ .../widgets/app/app_list_widget.dart | 77 ------------------- .../presentation/widgets/app/app_widget.dart | 50 ++++++++---- .../presentation/widgets/app/view_list.dart | 1 + .../home/presentation/widgets/menu/menu.dart | 10 ++- 7 files changed, 50 insertions(+), 103 deletions(-) delete mode 100644 app_flowy/lib/home/presentation/widgets/app/app_list_widget.dart diff --git a/app_flowy/lib/home/application/app/app_bloc.dart b/app_flowy/lib/home/application/app/app_bloc.dart index b2e555d9e1..81929a6540 100644 --- a/app_flowy/lib/home/application/app/app_bloc.dart +++ b/app_flowy/lib/home/application/app/app_bloc.dart @@ -16,12 +16,7 @@ class AppBloc extends Bloc { AppEvent event, ) async* { yield* event.map( - initial: (e) async* { - iAppImpl.startWatching( - updatedCallback: (name, desc) {}, - addViewCallback: (views) {}, - ); - }, + initial: (e) async* {}, viewsReceived: (e) async* { yield state; }, diff --git a/app_flowy/lib/home/application/app/app_watch_bloc.dart b/app_flowy/lib/home/application/app/app_watch_bloc.dart index 2edbb151dc..345d8984e0 100644 --- a/app_flowy/lib/home/application/app/app_watch_bloc.dart +++ b/app_flowy/lib/home/application/app/app_watch_bloc.dart @@ -15,7 +15,7 @@ class AppWatchBloc extends Bloc { Stream mapEventToState( AppWatchEvent event, ) async* { - yield* event.map(started: (_) { + yield* event.map(started: (_) async* { watcher.startWatching( addViewCallback: (viewsOrFail) => _handleViewsOrFail(viewsOrFail), ); diff --git a/app_flowy/lib/home/infrastructure/deps_resolver.dart b/app_flowy/lib/home/infrastructure/deps_resolver.dart index 8043e963d6..2403d8547c 100644 --- a/app_flowy/lib/home/infrastructure/deps_resolver.dart +++ b/app_flowy/lib/home/infrastructure/deps_resolver.dart @@ -1,3 +1,5 @@ +import 'package:app_flowy/home/application/app/app_bloc.dart'; +import 'package:app_flowy/home/application/app/app_watch_bloc.dart'; import 'package:app_flowy/home/application/menu/menu_bloc.dart'; import 'package:app_flowy/home/application/menu/menu_watch.dart'; import 'package:app_flowy/home/infrastructure/i_app_impl.dart'; @@ -36,6 +38,10 @@ class HomeDepsResolver { getIt.registerFactoryParam((workspaceId, _) => MenuWatchBloc(getIt(param1: workspaceId))); + getIt.registerFactoryParam( + (appId, _) => AppBloc(getIt(param1: appId))); + getIt.registerFactoryParam( + (appId, _) => AppWatchBloc(getIt(param1: appId))); // AppWatchBloc } } diff --git a/app_flowy/lib/home/presentation/widgets/app/app_list_widget.dart b/app_flowy/lib/home/presentation/widgets/app/app_list_widget.dart deleted file mode 100644 index 0db1b2504c..0000000000 --- a/app_flowy/lib/home/presentation/widgets/app/app_list_widget.dart +++ /dev/null @@ -1,77 +0,0 @@ -import 'package:app_flowy/home/application/app/app_bloc.dart'; -import 'package:app_flowy/startup/startup.dart'; -// ignore: import_of_legacy_library_into_null_safe -import 'package:expandable/expandable.dart'; -import 'package:flowy_infra/flowy_logger.dart'; -import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flowy_infra_ui/widget/error_page.dart'; - -import 'app_widget.dart'; - -// class AppList extends StatelessWidget { -// const AppList({Key? key}) : super(key: key); -// @override -// Widget build(BuildContext context) { -// return MultiBlocProvider( -// providers: [ -// BlocProvider( -// create: (context) => getIt()..add(const AppEvent.initial()), -// ), -// ], -// child: BlocBuilder( -// buildWhen: (p, c) => p.apps != c.apps, -// builder: (context, state) { -// Log.info('AppList build'); -// if (state.isLoading) { -// return const Center( -// child: CircularProgressIndicator.adaptive(), -// ); -// } - -// return state.apps.fold( -// () => state.successOrFailure.fold( -// (_) => const Text('You have no apps, create one?'), -// (error) => FlowyErrorPage(error.toString()), -// ), -// (apps) => _buildBody(apps), -// ); -// }, -// ), -// ); -// } - -class AppList extends StatelessWidget { - final List apps; - const AppList({required this.apps, Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - return ExpandableTheme( - data: const ExpandableThemeData( - iconColor: Colors.blue, - useInkWell: true, - ), - child: Expanded( - child: ListView( - physics: const BouncingScrollPhysics(), - children: apps.map((app) => AppWidget(app)).toList(), - ), - )); - } - - // Widget _buildBody(List apps) { - // return ExpandableTheme( - // data: const ExpandableThemeData( - // iconColor: Colors.blue, - // useInkWell: true, - // ), - // child: Expanded( - // child: ListView( - // physics: const BouncingScrollPhysics(), - // children: apps.map((app) => AppWidget(app)).toList(), - // ), - // )); - // } -} diff --git a/app_flowy/lib/home/presentation/widgets/app/app_widget.dart b/app_flowy/lib/home/presentation/widgets/app/app_widget.dart index 7fc0b5dfc1..ef63c602aa 100644 --- a/app_flowy/lib/home/presentation/widgets/app/app_widget.dart +++ b/app_flowy/lib/home/presentation/widgets/app/app_widget.dart @@ -1,4 +1,5 @@ import 'package:app_flowy/home/application/app/app_bloc.dart'; +import 'package:app_flowy/home/application/app/app_watch_bloc.dart'; import 'package:app_flowy/home/presentation/widgets/menu/menu_size.dart'; import 'package:app_flowy/startup/startup.dart'; import 'package:expandable/expandable.dart'; @@ -15,23 +16,40 @@ class AppWidget extends StatelessWidget { @override Widget build(BuildContext context) { - // return MultiBlocProvider( - // providers: [ - // BlocProvider(create: (context) => getIt()), - // ], - // child: BlocBuilder( - // builder: (context, state) { - // // final child = state.map( - // // initial: (_) => const CircularProgressIndicator.adaptive(), - // // loadViews: (s) => ViewList(s.views), - // // successOrFailure: (s) => FlowyErrorPage(s.error), - // // ); + return MultiBlocProvider( + providers: [ + BlocProvider( + create: (context) => getIt(param1: app.id)), + BlocProvider( + create: (context) => getIt(param1: app.id)), + ], + child: BlocBuilder( + builder: (context, state) { + final child = state.map( + initial: (_) => BlocBuilder( + builder: (context, state) { + return Container(); + }, + ), + loadViews: (s) { + return Container(); + // final child = state.map( + // initial: (_) => const CircularProgressIndicator.adaptive(), + // loadViews: (s) => ViewList(s.views), + // successOrFailure: (s) => FlowyErrorPage(s.error), + // ); - // return expandableWrapper(context, Container()); - // }, - // ), - // ); - return Container(); + // return expandableWrapper(context, Container()); + }, + loadFail: (s) { + return FlowyErrorPage(s.error.toString()); + }, + ); + + return expandableWrapper(context, child); + }, + ), + ); } ExpandableNotifier expandableWrapper(BuildContext context, Widget child) { diff --git a/app_flowy/lib/home/presentation/widgets/app/view_list.dart b/app_flowy/lib/home/presentation/widgets/app/view_list.dart index e69de29bb2..8b13789179 100644 --- a/app_flowy/lib/home/presentation/widgets/app/view_list.dart +++ b/app_flowy/lib/home/presentation/widgets/app/view_list.dart @@ -0,0 +1 @@ + diff --git a/app_flowy/lib/home/presentation/widgets/menu/menu.dart b/app_flowy/lib/home/presentation/widgets/menu/menu.dart index cdd2ca3e4d..f8a23a7a2c 100644 --- a/app_flowy/lib/home/presentation/widgets/menu/menu.dart +++ b/app_flowy/lib/home/presentation/widgets/menu/menu.dart @@ -77,9 +77,13 @@ class HomeMenu extends StatelessWidget { Widget _renderAppList(BuildContext context) { return BlocBuilder( builder: (context, state) => state.map( - initial: (_) => AppList(apps: context.read().state.apps), - loadApps: (event) => AppList(apps: some(event.apps)), - loadFail: (error) => FlowyErrorPage(error.toString()), + initial: (_) => BlocBuilder( + builder: (context, state) { + return AppList(apps: state.apps); + }, + ), + loadApps: (s) => AppList(apps: some(s.apps)), + loadFail: (s) => FlowyErrorPage(s.error.toString()), ), ); }