diff --git a/lib/user/pages/user_page.dart b/lib/user/pages/user_page.dart index 1d5e34969..c5f664998 100644 --- a/lib/user/pages/user_page.dart +++ b/lib/user/pages/user_page.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:share_plus/share_plus.dart'; import 'package:swipeable_page_route/swipeable_page_route.dart'; import 'package:thunder/account/bloc/account_bloc.dart'; @@ -38,123 +39,143 @@ class UserPage extends StatefulWidget { class _UserPageState extends State { UserBloc? userBloc; + String? userActorId; @override Widget build(BuildContext context) { final ThunderState state = context.read().state; final bool reduceAnimations = state.reduceAnimations; - return Scaffold( - appBar: AppBar( - scrolledUnderElevation: 0, - leading: widget.isAccountUser - ? IconButton( - onPressed: () => showProfileModalSheet(context, showLogoutDialog: true), - icon: Icon( - Icons.logout, - semanticLabel: AppLocalizations.of(context)!.logOut, + return BlocProvider( + create: (BuildContext context) => UserBloc(), + child: BlocListener( + listener: (context, state) { + if (userActorId == null && state.personView?.person.actorId != null) { + setState(() => userActorId = state.personView!.person.actorId); + } + }, + child: Scaffold( + appBar: AppBar( + scrolledUnderElevation: 0, + leading: widget.isAccountUser + ? IconButton( + onPressed: () => showProfileModalSheet(context, showLogoutDialog: true), + icon: Icon( + Icons.logout, + semanticLabel: AppLocalizations.of(context)!.logOut, + ), + tooltip: AppLocalizations.of(context)!.logOut, + ) + : null, + actions: [ + Padding( + padding: const EdgeInsets.fromLTRB(0.0, 4.0, 0.0, 4.0), + child: IconButton( + onPressed: () => userBloc?.add(ResetUserEvent()), + icon: Icon( + Icons.refresh_rounded, + semanticLabel: AppLocalizations.of(context)!.refresh, + ), + tooltip: AppLocalizations.of(context)!.refresh, ), - tooltip: AppLocalizations.of(context)!.logOut, - ) - : null, - actions: [ - Padding( - padding: const EdgeInsets.fromLTRB(0.0, 4.0, 0.0, 4.0), - child: IconButton( - onPressed: () => userBloc?.add(ResetUserEvent()), - icon: Icon( - Icons.refresh_rounded, - semanticLabel: AppLocalizations.of(context)!.refresh, ), - tooltip: AppLocalizations.of(context)!.refresh, - ), - ), - if (widget.userId != null && widget.isAccountUser) - Padding( - padding: const EdgeInsets.fromLTRB(0.0, 4.0, 0, 4.0), - child: IconButton( - onPressed: () { - final AccountBloc accountBloc = context.read(); - final ThunderBloc thunderBloc = context.read(); - Navigator.of(context).push( - SwipeablePageRoute( - transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null, - canOnlySwipeFromEdge: !state.enableFullScreenSwipeNavigationGesture, - builder: (context) => MultiBlocProvider( - providers: [ - BlocProvider.value(value: accountBloc), - BlocProvider.value(value: thunderBloc), - ], - child: const UserSettingsPage(), - ), + if (!widget.isAccountUser && userActorId != null) + Padding( + padding: const EdgeInsets.fromLTRB(0.0, 4.0, 0.0, 4.0), + child: IconButton( + onPressed: () => Share.share(userActorId!), + icon: Icon( + Icons.share_rounded, + semanticLabel: AppLocalizations.of(context)!.share, ), - ); - }, - icon: Icon( - Icons.settings_rounded, - semanticLabel: AppLocalizations.of(context)!.accountSettings, + tooltip: AppLocalizations.of(context)!.share, + ), ), - tooltip: AppLocalizations.of(context)!.accountSettings, - ), - ), - if (widget.isAccountUser) - Padding( - padding: const EdgeInsets.fromLTRB(0.0, 4.0, 4.0, 4.0), - child: IconButton( - onPressed: () => showProfileModalSheet(context), - icon: Icon( - Icons.people_alt_rounded, - semanticLabel: AppLocalizations.of(context)!.profiles, + if (widget.userId != null && widget.isAccountUser) + Padding( + padding: const EdgeInsets.fromLTRB(0.0, 4.0, 0, 4.0), + child: IconButton( + onPressed: () { + final AccountBloc accountBloc = context.read(); + final ThunderBloc thunderBloc = context.read(); + Navigator.of(context).push( + SwipeablePageRoute( + transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null, + canOnlySwipeFromEdge: !state.enableFullScreenSwipeNavigationGesture, + builder: (context) => MultiBlocProvider( + providers: [ + BlocProvider.value(value: accountBloc), + BlocProvider.value(value: thunderBloc), + ], + child: const UserSettingsPage(), + ), + ), + ); + }, + icon: Icon( + Icons.settings_rounded, + semanticLabel: AppLocalizations.of(context)!.accountSettings, + ), + tooltip: AppLocalizations.of(context)!.accountSettings, + ), ), - tooltip: AppLocalizations.of(context)!.profiles, - ), - ), - ], - ), - body: MultiBlocProvider( - providers: [BlocProvider(create: (BuildContext context) => UserBloc())], - child: BlocBuilder(builder: (context, state) { - userBloc = context.read(); + if (widget.isAccountUser) + Padding( + padding: const EdgeInsets.fromLTRB(0.0, 4.0, 4.0, 4.0), + child: IconButton( + onPressed: () => showProfileModalSheet(context), + icon: Icon( + Icons.people_alt_rounded, + semanticLabel: AppLocalizations.of(context)!.profiles, + ), + tooltip: AppLocalizations.of(context)!.profiles, + ), + ), + ], + ), + body: BlocBuilder(builder: (context, state) { + userBloc = context.read(); - if (state.status == UserStatus.failedToBlock) { - showSnackbar(context, state.errorMessage ?? AppLocalizations.of(context)!.missingErrorMessage); - } + if (state.status == UserStatus.failedToBlock) { + showSnackbar(context, state.errorMessage ?? AppLocalizations.of(context)!.missingErrorMessage); + } - switch (state.status) { - case UserStatus.initial: - context.read().add(GetUserEvent(userId: widget.userId, isAccountUser: widget.isAccountUser, username: widget.username, reset: true)); - context.read().add(GetUserSavedEvent(userId: widget.userId, isAccountUser: widget.isAccountUser, reset: true)); - return const Center(child: CircularProgressIndicator()); - case UserStatus.loading: - return const Center(child: CircularProgressIndicator()); - case UserStatus.refreshing: - case UserStatus.success: - case UserStatus.failedToBlock: - return UserPageSuccess( - userId: widget.userId, - isAccountUser: widget.isAccountUser, - personView: state.personView, - moderates: state.moderates, - commentViewTrees: state.comments, - postViews: state.posts, - savedPostViews: state.savedPosts, - savedComments: state.savedComments, - hasReachedPostEnd: state.hasReachedPostEnd, - hasReachedSavedPostEnd: state.hasReachedSavedPostEnd, - blockedPerson: state.blockedPerson, - selectedUserOption: widget.selectedUserOption, - savedToggle: widget.savedToggle, - ); - case UserStatus.empty: - return Container(); - case UserStatus.failure: - return ErrorMessage( - message: state.errorMessage, - action: () => context.read().add(GetUserEvent(userId: widget.userId, reset: true)), - actionText: AppLocalizations.of(context)!.refreshContent, - ); - } - }), + switch (state.status) { + case UserStatus.initial: + context.read().add(GetUserEvent(userId: widget.userId, isAccountUser: widget.isAccountUser, username: widget.username, reset: true)); + context.read().add(GetUserSavedEvent(userId: widget.userId, isAccountUser: widget.isAccountUser, reset: true)); + return const Center(child: CircularProgressIndicator()); + case UserStatus.loading: + return const Center(child: CircularProgressIndicator()); + case UserStatus.refreshing: + case UserStatus.success: + case UserStatus.failedToBlock: + return UserPageSuccess( + userId: widget.userId, + isAccountUser: widget.isAccountUser, + personView: state.personView, + moderates: state.moderates, + commentViewTrees: state.comments, + postViews: state.posts, + savedPostViews: state.savedPosts, + savedComments: state.savedComments, + hasReachedPostEnd: state.hasReachedPostEnd, + hasReachedSavedPostEnd: state.hasReachedSavedPostEnd, + blockedPerson: state.blockedPerson, + selectedUserOption: widget.selectedUserOption, + savedToggle: widget.savedToggle, + ); + case UserStatus.empty: + return Container(); + case UserStatus.failure: + return ErrorMessage( + message: state.errorMessage, + action: () => context.read().add(GetUserEvent(userId: widget.userId, reset: true)), + actionText: AppLocalizations.of(context)!.refreshContent, + ); + } + }), + ), ), ); }