From 778451fa4c6323a25dd956e27dcc732e81872487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Fri, 12 Jul 2024 23:08:56 +0200 Subject: [PATCH] channel list fixes --- .../lib/pages/channel_list/channel_list.dart | 36 ++++++++++++------- .../lib/pages/channel_view/channel_view.dart | 20 ++++++----- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/flutter/lib/pages/channel_list/channel_list.dart b/flutter/lib/pages/channel_list/channel_list.dart index e3323ba..f3149a8 100644 --- a/flutter/lib/pages/channel_list/channel_list.dart +++ b/flutter/lib/pages/channel_list/channel_list.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:provider/provider.dart'; import 'package:simplecloudnotifier/api/api_client.dart'; @@ -142,22 +143,31 @@ class _ChannelRootPageState extends State with RouteAware { @override Widget build(BuildContext context) { - return RefreshIndicator( - onRefresh: () => Future.sync( - () => _pagingController.refresh(), - ), - child: PagedListView( - pagingController: _pagingController, - builderDelegate: PagedChildBuilderDelegate( - itemBuilder: (context, item, index) => ChannelListItem( - channel: item.channel, - subscription: item.subscription, - onPressed: () { - Navi.push(context, () => ChannelViewPage(channel: item.channel, subscription: item.subscription, needsReload: _enqueueReload)); - }, + return Scaffold( + body: RefreshIndicator( + onRefresh: () => Future.sync( + () => _pagingController.refresh(), + ), + child: PagedListView( + pagingController: _pagingController, + builderDelegate: PagedChildBuilderDelegate( + itemBuilder: (context, item, index) => ChannelListItem( + channel: item.channel, + subscription: item.subscription, + onPressed: () { + Navi.push(context, () => ChannelViewPage(channel: item.channel, subscription: item.subscription, needsReload: _enqueueReload)); + }, + ), ), ), ), + floatingActionButton: FloatingActionButton( + onPressed: () { + //TODO scan qr code to subscribe channel + }, + backgroundColor: , + child: const Icon(FontAwesomeIcons.qrcode), + ), ); } diff --git a/flutter/lib/pages/channel_view/channel_view.dart b/flutter/lib/pages/channel_view/channel_view.dart index 404fdbe..6b2a77e 100644 --- a/flutter/lib/pages/channel_view/channel_view.dart +++ b/flutter/lib/pages/channel_view/channel_view.dart @@ -37,7 +37,7 @@ enum EditState { none, editing, saving } class _ChannelViewPageState extends State { late ImmediateFuture _futureSubscribeKey; - late ImmediateFuture> _futureSubscriptions; + late ImmediateFuture> _futureSubscriptions; late ImmediateFuture _futureOwner; final TextEditingController _ctrlDisplayName = TextEditingController(); @@ -61,10 +61,10 @@ class _ChannelViewPageState extends State { } else { _futureSubscribeKey = ImmediateFuture.ofFuture(_getSubScribeKey(userAcc)); } - _futureSubscriptions = ImmediateFuture>.ofFuture(_listSubscriptions(userAcc)); + _futureSubscriptions = ImmediateFuture>.ofFuture(_listSubscriptions(userAcc)); } else { _futureSubscribeKey = ImmediateFuture.ofValue(null); - _futureSubscriptions = ImmediateFuture>.ofValue([]); + _futureSubscriptions = ImmediateFuture>.ofValue([]); } if (widget.channel.ownerUserID == userAcc.userID) { @@ -156,13 +156,13 @@ class _ChannelViewPageState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - for (final sub in snapshot.data!.where((sub) => sub.subscriptionID != widget.subscription?.subscriptionID)) + for (final (sub, user) in snapshot.data!.where((v) => v.$1.subscriptionID != widget.subscription?.subscriptionID)) UI.metaCard( context: context, icon: FontAwesomeIcons.solidDiagramSuccessor, - title: 'Subscription (other)', + title: 'Subscription (' + (user?.username ?? user?.userID ?? 'other') + ')', values: [_formatSubscriptionStatus(sub)], - iconActions: _getForignSubActions(sub), + iconActions: _getForeignSubActions(sub), ), ], ); @@ -461,7 +461,7 @@ class _ChannelViewPageState extends State { } } - Future> _listSubscriptions(AppAuth auth) async { + Future> _listSubscriptions(AppAuth auth) async { try { await Future.delayed(const Duration(seconds: 0), () {}); // this is annoyingly important - otherwise we call setLoadingIndeterminate directly in initStat() and get an exception.... @@ -469,9 +469,11 @@ class _ChannelViewPageState extends State { var subs = await APIClient.getChannelSubscriptions(auth, widget.channel.channelID); + var userMap = {for (var v in (await Future.wait(subs.map((e) => e.subscriberUserID).toSet().map((e) => APIClient.getUserPreview(auth, e)).toList()))) v.userID: v}; + //await Future.delayed(const Duration(seconds: 10), () {}); - return subs; + return subs.map((e) => (e, userMap[e.subscriberUserID] ?? null)).toList(); } finally { _incLoadingIndeterminateCounter(-1); } @@ -493,7 +495,7 @@ class _ChannelViewPageState extends State { } } - List<(IconData, void Function())> _getForignSubActions(Subscription sub) { + List<(IconData, void Function())> _getForeignSubActions(Subscription sub) { if (sub.confirmed) { return [(FontAwesomeIcons.solidSquareXmark, () => _cancelForeignSubscription(sub))]; } else {