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

Share user profiles #1013

Merged
merged 3 commits into from
Jan 6, 2024
Merged
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
229 changes: 125 additions & 104 deletions lib/user/pages/user_page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -38,123 +39,143 @@ class UserPage extends StatefulWidget {

class _UserPageState extends State<UserPage> {
UserBloc? userBloc;
String? userActorId;

@override
Widget build(BuildContext context) {
final ThunderState state = context.read<ThunderBloc>().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<UserBloc>(
create: (BuildContext context) => UserBloc(),
child: BlocListener<UserBloc, UserState>(
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<AccountBloc>();
final ThunderBloc thunderBloc = context.read<ThunderBloc>();
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<AccountBloc>();
final ThunderBloc thunderBloc = context.read<ThunderBloc>();
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<UserBloc>(create: (BuildContext context) => UserBloc())],
child: BlocBuilder<UserBloc, UserState>(builder: (context, state) {
userBloc = context.read<UserBloc>();
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<UserBloc, UserState>(builder: (context, state) {
userBloc = context.read<UserBloc>();

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<UserBloc>().add(GetUserEvent(userId: widget.userId, isAccountUser: widget.isAccountUser, username: widget.username, reset: true));
context.read<UserBloc>().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<UserBloc>().add(GetUserEvent(userId: widget.userId, reset: true)),
actionText: AppLocalizations.of(context)!.refreshContent,
);
}
}),
switch (state.status) {
case UserStatus.initial:
context.read<UserBloc>().add(GetUserEvent(userId: widget.userId, isAccountUser: widget.isAccountUser, username: widget.username, reset: true));
context.read<UserBloc>().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<UserBloc>().add(GetUserEvent(userId: widget.userId, reset: true)),
actionText: AppLocalizations.of(context)!.refreshContent,
);
}
}),
),
),
);
}
Expand Down
Loading