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

Boost with pin action #2376

Merged
merged 11 commits into from
Nov 22, 2024
1 change: 1 addition & 0 deletions .changes/2376-boost-pin-action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [New] : Now you can share Pin as action item to Boost slide post.
93 changes: 10 additions & 83 deletions app/lib/common/widgets/event/event_selector_drawer.dart
Original file line number Diff line number Diff line change
@@ -1,92 +1,19 @@
import 'package:acter/features/events/providers/event_providers.dart';
import 'package:acter/features/events/widgets/event_item.dart';
import 'package:acter/features/events/widgets/skeletons/event_list_skeleton_widget.dart';
import 'package:atlas_icons/atlas_icons.dart';
import 'package:acter/features/events/pages/event_list_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';

final _log = Logger('a3::common::cal_event::select_drawer');

const Key selectEventDrawerKey = Key('event-widgets-select-event-drawer');

Future<String?> selectEventDrawer({
required BuildContext context,
required String spaceId,
Key? key = selectEventDrawerKey,
Widget? title,
String? spaceId,
}) async {
final selected = await showModalBottomSheet(
showDragHandle: true,
enableDrag: true,
final eventId = await showModalBottomSheet(
context: context,
isDismissible: true,
builder: (context) => Consumer(
builder: (context, ref, child) {
final calEventsLoader = ref.watch(allEventListProvider(spaceId));
return calEventsLoader.when(
data: (calEvents) => Column(
key: key,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Row(
children: [
Expanded(
child: title ?? const Text('Select event'),
),
OutlinedButton.icon(
icon: const Icon(Atlas.minus_circle_thin),
onPressed: () {
Navigator.pop(context, null);
},
label: const Text('Clear'),
),
],
),
),
Flexible(
child: calEvents.isEmpty
? Container(
height: 200,
alignment: Alignment.center,
child: const Text('No events found'),
)
: ListView.builder(
padding: const EdgeInsets.all(8),
itemCount: calEvents.length,
itemBuilder: (context, index) => EventItem(
event: calEvents[index],
isShowRsvp: false,
onTapEventItem: (event) {
Navigator.pop(context, event);
},
),
),
),
],
),
error: (e, s) {
_log.severe('Failed to load all cal events', e, s);
return Center(
child: Text(L10n.of(context).failedToLoadEventsDueTo(e)),
);
},
loading: () => const SizedBox(
height: 500,
child: EventListSkeleton(),
),
);
},
isScrollControlled: true,
useSafeArea: true,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
builder: (context) => EventListPage(
spaceId: spaceId,
onSelectEventItem: (eventId) => Navigator.pop(context, eventId),
),
);
if (selected == '') {
// in case of being cleared, we return null
return null;
}
return selected;
return eventId == '' ? null : eventId;
}
21 changes: 21 additions & 0 deletions app/lib/common/widgets/pin/pin_selector_drawer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:acter/features/pins/pages/pins_list_page.dart';
import 'package:flutter/material.dart';

const Key selectPinDrawerKey = Key('select-pin-drawer');

Future<String?> selectPinDrawer({
required BuildContext context,
String? spaceId,
}) async {
final pinId = await showModalBottomSheet(
context: context,
isScrollControlled: true,
useSafeArea: true,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
builder: (context) => PinsListPage(
spaceId: spaceId,
onSelectPinItem: (pinId) => Navigator.pop(context, pinId),
),
);
return pinId == '' ? null : pinId;
}
36 changes: 21 additions & 15 deletions app/lib/features/events/pages/event_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import 'package:go_router/go_router.dart';
class EventListPage extends ConsumerStatefulWidget {
final String? spaceId;
final String? searchQuery;
final Function(String)? onSelectEventItem;

const EventListPage({
super.key,
this.spaceId,
this.searchQuery,
this.onSelectEventItem,
});

@override
Expand Down Expand Up @@ -46,23 +48,26 @@ class _EventListPageState extends ConsumerState<EventListPage> {
final spaceId = widget.spaceId;
return AppBar(
centerTitle: false,
title: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(L10n.of(context).events),
if (spaceId != null) SpaceNameWidget(spaceId: spaceId),
],
),
title: widget.onSelectEventItem != null
? Text(L10n.of(context).selectEvent)
: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(L10n.of(context).events),
if (spaceId != null) SpaceNameWidget(spaceId: spaceId),
],
),
actions: [
AddButtonWithCanPermission(
canString: 'CanPostEvent',
spaceId: widget.spaceId,
onPressed: () => context.pushNamed(
Routes.createEvent.name,
queryParameters: {'spaceId': widget.spaceId},
if (widget.onSelectEventItem == null)
AddButtonWithCanPermission(
canString: 'CanPostEvent',
spaceId: widget.spaceId,
onPressed: () => context.pushNamed(
Routes.createEvent.name,
queryParameters: {'spaceId': widget.spaceId},
),
),
),
],
);
}
Expand All @@ -89,6 +94,7 @@ class _EventListPageState extends ConsumerState<EventListPage> {
child: EventListWidget(
isShowSpaceName: widget.spaceId == null,
shrinkWrap: false,
onTapEventItem: widget.onSelectEventItem,
listProvider: eventListSearchedAndFilterProvider(widget.spaceId),
emptyStateBuilder: () => EventListEmptyState(
spaceId: widget.spaceId,
Expand Down
3 changes: 3 additions & 0 deletions app/lib/features/events/widgets/event_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EventListWidget extends ConsumerWidget {
final String? sectionHeaderTitle;
final bool? isShowSeeAllButton;
final bool showSectionBg;
final Function(String)? onTapEventItem;
final bool shrinkWrap;
final bool isShowSpaceName;
final Widget Function()? emptyStateBuilder;
Expand All @@ -32,6 +33,7 @@ class EventListWidget extends ConsumerWidget {
this.sectionHeaderTitle,
this.isShowSeeAllButton,
this.showSectionBg = true,
this.onTapEventItem,
this.shrinkWrap = true,
this.emptyStateBuilder,
});
Expand Down Expand Up @@ -105,6 +107,7 @@ class EventListWidget extends ConsumerWidget {
return EventItem(
event: eventList[index],
isShowSpaceName: isShowSpaceName,
onTapEventItem: onTapEventItem,
);
},
);
Expand Down
7 changes: 7 additions & 0 deletions app/lib/features/news/actions/submit_news.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ ObjRef getSlideReference(ActerSdk sdk, NewsReferencesModel refModel) {
null,
)
.build(),
NewsReferencesType.pin => sdk.api
.newPinRefBuilder(
refModel.id.expect('Referenced Pin misses id'),
null,
null,
)
.build(),
NewsReferencesType.link => sdk.api
.newLinkRefBuilder(
refModel.title.expect('Referenced link misses title'),
Expand Down
1 change: 1 addition & 0 deletions app/lib/features/news/model/news_references_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
enum NewsReferencesType {
calendarEvent,
pin,
link;

static NewsReferencesType? fromStr(String typeStr) {
Expand Down
68 changes: 15 additions & 53 deletions app/lib/features/news/pages/add_news_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,21 @@ import 'package:acter/common/extensions/options.dart';
import 'package:acter/common/toolkit/buttons/danger_action_button.dart';
import 'package:acter/common/widgets/acter_video_player.dart';
import 'package:acter/common/widgets/html_editor.dart';
import 'package:acter/features/events/providers/event_providers.dart';
import 'package:acter/features/events/widgets/event_item.dart';
import 'package:acter/features/events/widgets/skeletons/event_item_skeleton_widget.dart';
import 'package:acter/features/news/actions/submit_news.dart';
import 'package:acter/features/news/model/keys.dart';
import 'package:acter/features/news/model/news_references_model.dart';
import 'package:acter/features/news/model/news_slide_model.dart';
import 'package:acter/features/news/news_utils/news_utils.dart';
import 'package:acter/features/news/providers/news_post_editor_providers.dart';
import 'package:acter/features/news/widgets/news_post_editor/news_slide_options.dart';
import 'package:acter/features/news/widgets/news_post_editor/select_action_item.dart';
import 'package:acter/features/news/widgets/news_post_editor/selected_action_button.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:atlas_icons/atlas_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:logging/logging.dart';

final _log = Logger('a3::news::add');

const addNewsKey = Key('add-news');

Expand Down Expand Up @@ -201,7 +195,7 @@ class AddNewsState extends ConsumerState<AddNewsPage> {
}

//Select any widget for action button
void selectActionItemDialog(BuildContext context) {
void selectActionItemDialog(BuildContext buildContext) {
showAdaptiveDialog(
context: context,
builder: (context) {
Expand All @@ -212,7 +206,12 @@ class AddNewsState extends ConsumerState<AddNewsPage> {
onShareEventSelected: () async {
Navigator.pop(context);
final notifier = ref.read(newsStateProvider.notifier);
await notifier.selectEventToShare(context);
await notifier.selectEventToShare(buildContext);
},
onSharePinSelected: () async {
Navigator.pop(context);
final notifier = ref.read(newsStateProvider.notifier);
await notifier.selectPinToShare(buildContext);
},
),
);
Expand All @@ -239,7 +238,13 @@ class AddNewsState extends ConsumerState<AddNewsPage> {
//Selected Slide Data View
slidePostUI(context),
//Selected Action Buttons View
selectedActionButtonsUI(),
Positioned(
bottom: 10,
left: 10,
child: SelectedActionButton(
newsReferences: selectedNewsPost?.newsReferencesModel,
),
),
],
);
}
Expand All @@ -256,49 +261,6 @@ class AddNewsState extends ConsumerState<AddNewsPage> {
emptySlidePostUI(context);
}

//Show selected Action Buttons
Widget selectedActionButtonsUI() {
final newsReferences = selectedNewsPost?.newsReferencesModel;
if (newsReferences == null) return const SizedBox();
final lang = L10n.of(context);
final calEventId = newsReferences.id;
return Positioned(
bottom: 10,
left: 10,
child: Row(
children: [
if (newsReferences.type == NewsReferencesType.calendarEvent &&
calEventId != null)
ref.watch(calendarEventProvider(calEventId)).when(
data: (calendarEvent) {
return SizedBox(
width: 300,
child: EventItem(
event: calendarEvent,
isShowRsvp: false,
onTapEventItem: (event) async {
final notifier = ref.read(newsStateProvider.notifier);
await notifier.selectEventToShare(context);
},
),
);
},
loading: () => const SizedBox(
width: 300,
child: EventItemSkeleton(),
),
error: (e, s) {
_log.severe('Failed to load cal event', e, s);
return Center(
child: Text(lang.failedToLoadEvent(e)),
);
},
),
],
),
);
}

Widget emptySlidePostUI(BuildContext context) {
final lang = L10n.of(context);
return Container(
Expand Down
Loading
Loading