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';
|
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-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-03-05 13:51:03 +08:00
|
|
|
..add(
|
2024-03-21 11:02:03 +07:00
|
|
|
SidebarSectionsEvent.initial(
|
2024-03-05 13:51:03 +08:00
|
|
|
user,
|
2024-03-26 10:21:49 +07:00
|
|
|
workspaceId,
|
2024-03-05 13:51:03 +08:00
|
|
|
),
|
|
|
|
),
|
2023-10-23 18:35:07 +08:00
|
|
|
),
|
|
|
|
BlocProvider(
|
|
|
|
create: (_) => FavoriteBloc()..add(const FavoriteEvent.initial()),
|
2023-11-14 22:33:07 +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-03-21 11:02:03 +07:00
|
|
|
},
|
2024-03-26 10:21:49 +07:00
|
|
|
child: BlocConsumer<SidebarSectionsBloc, SidebarSectionsState>(
|
|
|
|
listenWhen: (p, c) =>
|
|
|
|
p.lastCreatedRootView?.id != c.lastCreatedRootView?.id,
|
|
|
|
listener: (context, state) {
|
|
|
|
final lastCreatedRootView = state.lastCreatedRootView;
|
|
|
|
if (lastCreatedRootView != null) {
|
|
|
|
context.pushView(lastCreatedRootView);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
builder: (context, state) {
|
|
|
|
final isCollaborativeWorkspace =
|
|
|
|
context.read<UserWorkspaceBloc>().state.isCollabWorkspaceOn;
|
|
|
|
return SlidableAutoCloseBehavior(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
...isCollaborativeWorkspace
|
|
|
|
? [
|
|
|
|
MobileSectionFolder(
|
2024-04-07 23:06:33 +08:00
|
|
|
title: LocaleKeys.sideBar_workspace.tr(),
|
2024-05-27 08:51:49 +08:00
|
|
|
spaceType: FolderSpaceType.public,
|
2024-03-26 10:21:49 +07:00
|
|
|
views: state.section.publicViews,
|
|
|
|
),
|
|
|
|
const VSpace(8.0),
|
|
|
|
MobileSectionFolder(
|
|
|
|
title: LocaleKeys.sideBar_private.tr(),
|
2024-05-27 08:51:49 +08:00
|
|
|
spaceType: FolderSpaceType.private,
|
2024-03-26 10:21:49 +07:00
|
|
|
views: state.section.privateViews,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
: [
|
|
|
|
MobileSectionFolder(
|
|
|
|
title: LocaleKeys.sideBar_personal.tr(),
|
2024-05-27 08:51:49 +08:00
|
|
|
spaceType: FolderSpaceType.public,
|
2024-03-26 10:21:49 +07:00
|
|
|
views: state.section.publicViews,
|
|
|
|
),
|
|
|
|
],
|
2024-05-30 09:56:44 +08:00
|
|
|
const VSpace(4.0),
|
|
|
|
const _TrashButton(),
|
2024-03-26 10:21:49 +07:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
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,
|
|
|
|
margin: const EdgeInsets.symmetric(vertical: 8),
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|