Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support publish feature on mobile #6343

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:appflowy/mobile/presentation/base/view_page/more_bottom_sheet.da
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/plugins/document/presentation/editor_notification.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/page_style/page_style_bottom_sheet.dart';
import 'package:appflowy/plugins/shared/share/share_bloc.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/view/prelude.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
Expand Down Expand Up @@ -98,6 +99,11 @@ class MobileViewPageMoreButton extends StatelessWidget {
providers: [
BlocProvider.value(value: context.read<ViewBloc>()),
BlocProvider.value(value: context.read<FavoriteBloc>()),
BlocProvider.value(value: context.read<MobileViewPageBloc>()),
BlocProvider(
create: (_) =>
ShareBloc(view: view)..add(const ShareEvent.initial()),
),
],
child: MobileViewPageMoreBottomSheet(view: view),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import 'dart:async';

import 'package:appflowy/core/helpers/url_launcher.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/plugins/document/presentation/editor_notification.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
import 'package:appflowy/plugins/shared/share/publish_name_generator.dart';
import 'package:appflowy/plugins/shared/share/share_bloc.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/view/prelude.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:url_launcher/url_launcher.dart';

class MobileViewPageMoreBottomSheet extends StatelessWidget {
const MobileViewPageMoreBottomSheet({super.key, required this.view});
Expand All @@ -16,7 +27,7 @@ class MobileViewPageMoreBottomSheet extends StatelessWidget {
Widget build(BuildContext context) {
return ViewPageBottomSheet(
view: view,
onAction: (action) {
onAction: (action) async {
switch (action) {
case MobileViewBottomSheetBodyAction.duplicate:
context.pop();
Expand Down Expand Up @@ -52,6 +63,62 @@ class MobileViewPageMoreBottomSheet extends StatelessWidget {
// unimplemented
context.pop();
break;
case MobileViewBottomSheetBodyAction.publish:
final id = context.read<ShareBloc>().view.id;
final publishName = await generatePublishName(
id,
view.name,
);
if (context.mounted) {
context.read<ShareBloc>().add(
ShareEvent.publish(
'',
publishName,
[view.id],
),
);
showToastNotification(
context,
message: LocaleKeys.publish_publishSuccessfully.tr(),
);
context.pop();
}
break;
case MobileViewBottomSheetBodyAction.unpublish:
context.read<ShareBloc>().add(const ShareEvent.unPublish());
showToastNotification(
context,
message: LocaleKeys.publish_unpublishSuccessfully.tr(),
);
context.pop();
break;
case MobileViewBottomSheetBodyAction.copyPublishLink:
final url = context.read<ShareBloc>().state.url;
if (url.isNotEmpty) {
unawaited(
getIt<ClipboardService>().setData(
ClipboardServiceData(plainText: url),
),
);
showToastNotification(
context,
message: LocaleKeys.grid_url_copy.tr(),
);
}
context.pop();
break;
case MobileViewBottomSheetBodyAction.visitSite:
final url = context.read<ShareBloc>().state.url;
if (url.isNotEmpty) {
unawaited(
afLaunchUrl(
Uri.parse(url),
mode: LaunchMode.externalApplication,
),
);
}
context.pop();
break;
case MobileViewBottomSheetBodyAction.rename:
// no need to implement, rename is handled by the onRename callback.
throw UnimplementedError();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/base/mobile_view_page_bloc.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/mobile/presentation/widgets/flowy_mobile_quick_action_button.dart';
import 'package:appflowy/plugins/shared/share/share_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

enum MobileViewBottomSheetBodyAction {
undo,
Expand All @@ -15,7 +19,11 @@ enum MobileViewBottomSheetBodyAction {
delete,
addToFavorites,
removeFromFavorites,
helpCenter;
helpCenter,
publish,
unpublish,
copyPublishLink,
visitSite,
}

typedef MobileViewBottomSheetBodyActionCallback = void Function(
Expand Down Expand Up @@ -115,6 +123,8 @@ class MobileViewBottomSheetBody extends StatelessWidget {
),
),
_divider(),
..._buildPublishActions(context),
_divider(),
MobileQuickActionButton(
text: LocaleKeys.button_delete.tr(),
textColor: Theme.of(context).colorScheme.error,
Expand All @@ -129,6 +139,54 @@ class MobileViewBottomSheetBody extends StatelessWidget {
);
}

List<Widget> _buildPublishActions(BuildContext context) {
final userProfile = context.read<MobileViewPageBloc>().state.userProfilePB;
// the publish feature is only available for AppFlowy Cloud
if (userProfile == null ||
userProfile.authenticator != AuthenticatorPB.AppFlowyCloud) {
return [];
}

final isPublished = context.watch<ShareBloc>().state.isPublished;
if (isPublished) {
return [
// MobileQuickActionButton(
// text: LocaleKeys.shareAction_copyLink.tr(),
// icon: FlowySvgs.copy_s,
// onTap: () => onAction(
// MobileViewBottomSheetBodyAction.copyPublishLink,
// ),
// ),
MobileQuickActionButton(
text: LocaleKeys.shareAction_visitSite.tr(),
icon: FlowySvgs.share_s,
iconSize: const Size.square(20),
onTap: () => onAction(
MobileViewBottomSheetBodyAction.visitSite,
),
),
_divider(),
MobileQuickActionButton(
text: LocaleKeys.shareAction_unPublish.tr(),
icon: FlowySvgs.share_publish_s,
onTap: () => onAction(
MobileViewBottomSheetBodyAction.unpublish,
),
),
];
} else {
return [
MobileQuickActionButton(
text: LocaleKeys.shareAction_publish.tr(),
icon: FlowySvgs.share_publish_s,
onTap: () => onAction(
MobileViewBottomSheetBodyAction.publish,
),
),
];
}
}

Widget _divider() => const Divider(
height: 8.5,
thickness: 0.5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MobileQuickActionButton extends StatelessWidget {
required this.text,
this.textColor,
this.iconColor,
this.iconSize,
this.enable = true,
});

Expand All @@ -18,10 +19,12 @@ class MobileQuickActionButton extends StatelessWidget {
final String text;
final Color? textColor;
final Color? iconColor;
final Size? iconSize;
final bool enable;

@override
Widget build(BuildContext context) {
final iconSize = this.iconSize ?? const Size.square(18);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: InkWell(
Expand All @@ -37,10 +40,10 @@ class MobileQuickActionButton extends StatelessWidget {
children: [
FlowySvg(
icon,
size: const Size.square(18),
size: iconSize,
color: enable ? iconColor : Theme.of(context).disabledColor,
),
const HSpace(12),
HSpace(30 - iconSize.width),
Expanded(
child: FlowyText.regular(
text,
Expand Down
Loading