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

Linking to a specific boost #2490

Merged
merged 9 commits into from
Jan 10, 2025
Merged
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
1 change: 1 addition & 0 deletions .changes/2490-sharing-boosts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- You can now share boosts via the QR-code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only via QR Code?
External sharing doesn't yet supported? I have seen external sharing options in video and haven't see any QR Specific restriction in this PR code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog is meant to be user-facing thus I am focusing on the thing that already works nicely. The external sharing - as you point out correctly - still has some bugs so I am not advertising it here yet, despite it already being technically possible...

1 change: 1 addition & 0 deletions app/lib/common/utils/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum Routes {

// --- Updates
updates('/updates'),
update('/updates/:updateId([^/]+)'),
updateList('/updateList'),
actionAddUpdate('/actions/addUpdate'),

Expand Down
4 changes: 4 additions & 0 deletions app/lib/features/deep_linking/actions/forward_to_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Future<void> forwardToObject(
Routes.calendarEvent.name,
pathParameters: {'calendarId': objectId},
),
ObjectType.boost => context.pushNamed(
Routes.update.name,
pathParameters: {'updateId': objectId},
),
_ => EasyLoading.showError(
lang.deepLinkNotSupported(target.objectType),
duration: const Duration(seconds: 3),
Expand Down
46 changes: 45 additions & 1 deletion app/lib/features/news/pages/news_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import 'package:acter/features/news/providers/news_providers.dart';
import 'package:acter/features/news/widgets/news_full_view.dart';
import 'package:acter/features/news/widgets/news_grid_view.dart';
import 'package:acter/features/news/widgets/news_skeleton_widget.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:collection/collection.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:logging/logging.dart';
Expand All @@ -20,11 +22,13 @@ enum NewsViewMode { gridView, fullView }

class NewsListPage extends ConsumerStatefulWidget {
final String? spaceId;
final String? initialEventId;
final NewsViewMode newsViewMode;

const NewsListPage({
super.key,
this.spaceId,
this.initialEventId,
this.newsViewMode = NewsViewMode.gridView,
});

Expand All @@ -34,12 +38,46 @@ class NewsListPage extends ConsumerStatefulWidget {

class _NewsListPageState extends ConsumerState<NewsListPage> {
final ValueNotifier<bool> useGridMode = ValueNotifier(true);
final ValueNotifier<bool> stillLoadingForSelectedItem = ValueNotifier(false);
final ValueNotifier<int> currentIndex = ValueNotifier(0);
late ProviderSubscription<AsyncValue<List<NewsEntry>>>? listener;

@override
void initState() {
super.initState();
useGridMode.value = widget.newsViewMode == NewsViewMode.gridView;
final targetEventId = widget.initialEventId;
if (targetEventId != null) {
stillLoadingForSelectedItem.value = true;
listener = ref.listenManual(
newsListProvider(widget.spaceId),
(prev, next) {
final items = next.valueOrNull;
if (items == null) {
return;
}
int? itemIdx;

items.firstWhereIndexedOrNull((int idx, NewsEntry e) {
if (e.eventId().toString() == targetEventId) {
itemIdx = idx;
return true;
} else {
return false;
}
});
if (itemIdx == null) {
// not found, still loading
return;
Comment on lines +69 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happen if boost is deleted by user/You try to scan QR of different space which he/she haven't joined yet? This will remain in still loading forever?

This can happen specially in ExternalLink sharing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this code - as well as any other where we have that case - this is endlessly loading, yes.

The plan is to have that case figured and caught in the url-parser and show something else in these cases: a message with the room they need to join first.

If it was deleted I am not sure what we want to do instead, but I'd just put that onto the lower burner for now, not a major use case.

}
stillLoadingForSelectedItem.value = false;
currentIndex.value = itemIdx!;
listener?.close();
listener = null;
},
fireImmediately: true,
);
}
}

@override
Expand All @@ -50,7 +88,11 @@ class _NewsListPageState extends ConsumerState<NewsListPage> {
return Scaffold(
extendBodyBehindAppBar: !value,
appBar: _buildAppBar(value),
body: _buildBody(value),
body: ValueListenableBuilder(
valueListenable: stillLoadingForSelectedItem,
builder: (context, loading, child) =>
loading ? const NewsSkeletonWidget() : _buildBody(value),
),
);
},
);
Expand Down Expand Up @@ -119,6 +161,8 @@ class _NewsListPageState extends ConsumerState<NewsListPage> {
},
error: (e, s) => newsErrorUI(context, e, s),
loading: () => const NewsSkeletonWidget(),
skipLoadingOnRefresh: true,
skipLoadingOnReload: true,
);
}

Expand Down
21 changes: 21 additions & 0 deletions app/lib/features/news/widgets/news_item/news_side_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:acter/features/notifications/actions/autosubscribe.dart';
import 'package:acter/features/notifications/types.dart';
import 'package:acter/features/notifications/widgets/object_notification_status.dart';
import 'package:acter/features/read_receipts/widgets/read_counter.dart';
import 'package:acter/features/share/action/share_space_object_action.dart';
import 'package:acter/router/utils.dart';
import 'package:acter_avatar/acter_avatar.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart' show NewsEntry;
Expand All @@ -22,6 +23,7 @@ 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';
import 'package:phosphor_flutter/phosphor_flutter.dart';

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

Expand Down Expand Up @@ -223,6 +225,25 @@ class ActionBox extends ConsumerWidget {
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextButton.icon(
icon: PhosphorIcon(PhosphorIcons.shareFat()),
onPressed: () async {
final refDetails = await news.refDetails();
final internalLink = refDetails.generateInternalLink(true);
if (!context.mounted) return;
await openShareSpaceObjectDialog(
context: context,
refDetails: refDetails,
internalLink: internalLink,
showInternalActions: false,
shareContentBuilder: () async {
Navigator.pop(context);
return await refDetails.generateExternalLink();
},
);
},
label: Text(lang.share),
),
if (canRedact.valueOrNull == true)
Padding(
padding: EdgeInsets.symmetric(
Expand Down
6 changes: 5 additions & 1 deletion app/lib/features/share/action/share_space_object_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Future<void> openShareSpaceObjectDialog({
String? internalLink,
Future<String> Function()? shareContentBuilder,
Future<FileDetails> Function()? fileDetailContentBuilder,
bool showInternalActions = true,
}) async {
await showModalBottomSheet(
showDragHandle: true,
Expand All @@ -33,6 +34,7 @@ Future<void> openShareSpaceObjectDialog({
isDismissible: true,
builder: (context) => ShareSpaceObjectActionUI(
refDetails: refDetails,
showInternalActions: showInternalActions,
internalLink: internalLink,
shareContentBuilder: shareContentBuilder,
fileDetailContentBuilder: fileDetailContentBuilder,
Expand All @@ -43,6 +45,7 @@ Future<void> openShareSpaceObjectDialog({
class ShareSpaceObjectActionUI extends ConsumerWidget {
final RefDetails? refDetails;
final String? internalLink;
final bool showInternalActions;
final Future<String> Function()? shareContentBuilder;
final Future<FileDetails> Function()? fileDetailContentBuilder;

Expand All @@ -52,6 +55,7 @@ class ShareSpaceObjectActionUI extends ConsumerWidget {
this.internalLink,
this.shareContentBuilder,
this.fileDetailContentBuilder,
this.showInternalActions = true,
});

@override
Expand All @@ -63,7 +67,7 @@ class ShareSpaceObjectActionUI extends ConsumerWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.start,
children: [
if (refDetails != null) ...[
if (showInternalActions && refDetails != null) ...[
attachmentOptionsUI(context, ref, refDetails!),
SizedBox(height: 16),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class NewsSection extends ConsumerWidget {
}

Widget newsItemUI(BuildContext context, NewsEntry newsEntry) {
if (newsEntry.slidesCount() == 0) return const SizedBox.shrink();
final newsSlides = newsEntry.slides().toList();
if (newsSlides.isEmpty) return const SizedBox.shrink();
final slide = newsSlides[0];

return InkWell(
Expand Down
14 changes: 14 additions & 0 deletions app/lib/router/shell_routers/update_shell_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@ final updateShellRoutes = [
);
},
),
GoRoute(
name: Routes.update.name,
path: Routes.update.route,
redirect: authGuardRedirect,
pageBuilder: (context, state) {
return MaterialPage(
key: state.pageKey,
child: NewsListPage(
newsViewMode: NewsViewMode.fullView,
initialEventId: state.pathParameters['updateId'],
),
);
},
),
];
Loading
Loading