2024-05-30 09:56:44 +08:00
|
|
|
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
2024-03-21 11:02:03 +07:00
|
|
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
2023-10-23 18:35:07 +08:00
|
|
|
import 'package:appflowy/mobile/application/mobile_router.dart';
|
2024-05-30 09:56:44 +08:00
|
|
|
import 'package:appflowy/mobile/presentation/home/home.dart';
|
2024-03-21 11:02:03 +07:00
|
|
|
import 'package:appflowy/mobile/presentation/home/section_folder/mobile_home_section_folder.dart';
|
2024-06-13 14:14:18 +08:00
|
|
|
import 'package:appflowy/mobile/presentation/home/space/mobile_space.dart';
|
2023-10-23 18:35:07 +08:00
|
|
|
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
|
2024-03-21 11:02:03 +07:00
|
|
|
import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart';
|
2024-03-25 22:08:52 +07:00
|
|
|
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
|
2024-06-13 13:43:29 +08:00
|
|
|
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
|
2024-03-22 16:15:18 +07:00
|
|
|
import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
|
2024-03-21 11:02:03 +07:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2023-10-23 18:35:07 +08:00
|
|
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
2024-05-30 09:56:44 +08:00
|
|
|
import 'package:go_router/go_router.dart';
|
2023-10-23 18:35:07 +08:00
|
|
|
|
2024-03-21 11:02:03 +07:00
|
|
|
// Contains Public And Private Sections
|
2023-10-23 18:35:07 +08:00
|
|
|
class MobileFolders extends StatelessWidget {
|
|
|
|
const MobileFolders({
|
|
|
|
super.key,
|
|
|
|
required this.user,
|
2024-03-26 10:21:49 +07:00
|
|
|
required this.workspaceId,
|
2023-10-23 18:35:07 +08:00
|
|
|
required this.showFavorite,
|
|
|
|
});
|
|
|
|
|
|
|
|
final UserProfilePB user;
|
2024-03-26 10:21:49 +07:00
|
|
|
final String workspaceId;
|
2023-10-23 18:35:07 +08:00
|
|
|
final bool showFavorite;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MultiBlocProvider(
|
|
|
|
providers: [
|
|
|
|
BlocProvider(
|
2024-03-21 11:02:03 +07:00
|
|
|
create: (_) => SidebarSectionsBloc()
|
2024-06-13 13:43:29 +08:00
|
|
|
..add(SidebarSectionsEvent.initial(user, workspaceId)),
|
2023-10-23 18:35:07 +08:00
|
|
|
),
|
|
|
|
BlocProvider(
|
|
|
|
create: (_) => FavoriteBloc()..add(const FavoriteEvent.initial()),
|
2023-11-14 22:33:07 +08:00
|
|
|
),
|
2024-06-13 13:43:29 +08:00
|
|
|
BlocProvider(
|
2024-06-17 16:23:17 +08:00
|
|
|
create: (_) => SpaceBloc()
|
|
|
|
..add(SpaceEvent.initial(user, workspaceId, openFirstPage: false)),
|
2024-06-13 13:43:29 +08:00
|
|
|
),
|
2023-10-23 18:35:07 +08:00
|
|
|
],
|
2024-03-26 10:21:49 +07:00
|
|
|
child: BlocListener<UserWorkspaceBloc, UserWorkspaceState>(
|
2024-03-21 11:02:03 +07:00
|
|
|
listener: (context, state) {
|
2024-03-26 10:21:49 +07:00
|
|
|
context.read<SidebarSectionsBloc>().add(
|
|
|
|
SidebarSectionsEvent.initial(
|
|
|
|
user,
|
|
|
|
state.currentWorkspace?.workspaceId ?? workspaceId,
|
|
|
|
),
|
|
|
|
);
|
2024-06-13 14:14:18 +08:00
|
|
|
context.read<SpaceBloc>().add(
|
|
|
|
SpaceEvent.reset(
|
|
|
|
user,
|
|
|
|
state.currentWorkspace?.workspaceId ?? workspaceId,
|
|
|
|
),
|
|
|
|
);
|
2024-03-21 11:02:03 +07:00
|
|
|
},
|
2024-06-13 14:14:18 +08:00
|
|
|
child: MultiBlocListener(
|
|
|
|
listeners: [
|
|
|
|
BlocListener<SpaceBloc, SpaceState>(
|
|
|
|
listenWhen: (p, c) =>
|
|
|
|
p.lastCreatedPage?.id != c.lastCreatedPage?.id,
|
|
|
|
listener: (context, state) {
|
|
|
|
final lastCreatedPage = state.lastCreatedPage;
|
|
|
|
if (lastCreatedPage != null) {
|
|
|
|
context.pushView(lastCreatedPage);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
BlocListener<SidebarSectionsBloc, SidebarSectionsState>(
|
|
|
|
listenWhen: (p, c) =>
|
|
|
|
p.lastCreatedRootView?.id != c.lastCreatedRootView?.id,
|
|
|
|
listener: (context, state) {
|
|
|
|
final lastCreatedPage = state.lastCreatedRootView;
|
|
|
|
if (lastCreatedPage != null) {
|
|
|
|
context.pushView(lastCreatedPage);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
child: BlocBuilder<SidebarSectionsBloc, SidebarSectionsState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
return SlidableAutoCloseBehavior(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
..._buildSpaceOrSection(context, state),
|
|
|
|
const VSpace(4.0),
|
|
|
|
const _TrashButton(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2024-03-26 10:21:49 +07:00
|
|
|
),
|
2023-10-23 18:35:07 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-06-13 14:14:18 +08:00
|
|
|
|
|
|
|
List<Widget> _buildSpaceOrSection(
|
|
|
|
BuildContext context,
|
|
|
|
SidebarSectionsState state,
|
|
|
|
) {
|
|
|
|
if (context.watch<SpaceBloc>().state.spaces.isNotEmpty) {
|
|
|
|
return [
|
|
|
|
const MobileSpace(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context.read<UserWorkspaceBloc>().state.isCollabWorkspaceOn) {
|
|
|
|
return [
|
|
|
|
MobileSectionFolder(
|
|
|
|
title: LocaleKeys.sideBar_workspace.tr(),
|
|
|
|
spaceType: FolderSpaceType.public,
|
|
|
|
views: state.section.publicViews,
|
|
|
|
),
|
|
|
|
const VSpace(8.0),
|
|
|
|
MobileSectionFolder(
|
|
|
|
title: LocaleKeys.sideBar_private.tr(),
|
|
|
|
spaceType: FolderSpaceType.private,
|
|
|
|
views: state.section.privateViews,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
MobileSectionFolder(
|
|
|
|
title: LocaleKeys.sideBar_personal.tr(),
|
|
|
|
spaceType: FolderSpaceType.public,
|
|
|
|
views: state.section.publicViews,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2023-10-23 18:35:07 +08:00
|
|
|
}
|
2024-05-30 09:56:44 +08:00
|
|
|
|
|
|
|
class _TrashButton extends StatelessWidget {
|
|
|
|
const _TrashButton();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SizedBox(
|
|
|
|
height: 52,
|
|
|
|
child: FlowyButton(
|
|
|
|
expand: true,
|
2024-06-05 09:18:43 +08:00
|
|
|
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 2.0),
|
2024-05-30 09:56:44 +08:00
|
|
|
leftIcon: const FlowySvg(
|
|
|
|
FlowySvgs.m_delete_s,
|
|
|
|
),
|
|
|
|
leftIconSize: const Size.square(18),
|
|
|
|
iconPadding: 10.0,
|
|
|
|
text: FlowyText.regular(
|
|
|
|
LocaleKeys.trash_text.tr(),
|
|
|
|
fontSize: 16.0,
|
|
|
|
),
|
|
|
|
onTap: () => context.push(MobileHomeTrashPage.routeName),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|