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

[Experimental] enhancement of user account page #1552

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions lib/account/pages/account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import 'package:lemmy_api_client/v3.dart';

import 'package:thunder/account/widgets/account_placeholder.dart';
import 'package:thunder/core/auth/bloc/auth_bloc.dart';

import 'package:thunder/shared/primitive_wrapper.dart';
import 'package:thunder/user/pages/old_user_page.dart';

import 'package:thunder/feed/feed.dart';

class AccountPage extends StatefulWidget {
Expand Down
113 changes: 113 additions & 0 deletions lib/comment/widgets/comments_card_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:lemmy_api_client/v3.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:thunder/community/bloc/community_bloc_old.dart';
import 'package:thunder/core/models/comment_view_tree.dart';
import 'package:thunder/shared/comment_reference.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
//import 'package:thunder/user/bloc/user_bloc_old.dart';

class CommentsCardList extends StatefulWidget {
final List<CommentViewTree>? commentViewTrees;
final int? personId;
final bool? hasReachedEnd;
final bool isOwnComment;
final bool disableActions;

final VoidCallback onScrollEndReached;
final Function(int, int)? onVoteAction;
final Function(int, bool)? onSaveAction;
final Function(int, bool)? onDeleteAction;
final Function(int)? onReportAction;
final Function(CommentView, bool)? onReplyEditAction;

const CommentsCardList({
super.key,
this.commentViewTrees,
this.hasReachedEnd,
required this.personId,
required this.onScrollEndReached,
required this.onVoteAction,
required this.onSaveAction,
required this.onReportAction,
required this.onReplyEditAction,
required this.isOwnComment,
required this.disableActions,
this.onDeleteAction,
});

@override
State<CommentsCardList> createState() => _CommentsCardListState();
}

class _CommentsCardListState extends State<CommentsCardList> {
final _scrollController = ScrollController(initialScrollOffset: 0);

@override
void initState() {
_scrollController.addListener(_onScroll);

// Check to see if the initial load did not load enough items to allow for scrolling to occur and fetches more items
WidgetsBinding.instance.addPostFrameCallback((_) {
bool isScrollable = _scrollController.position.maxScrollExtent > _scrollController.position.viewportDimension;

if (context.read<CommunityBloc>().state.hasReachedEnd == false && isScrollable == false) {
widget.onScrollEndReached();
}
});

super.initState();
}

@override
void dispose() {
_scrollController.dispose();
super.dispose();
}

void _onScroll() {
if (_scrollController.position.pixels >= _scrollController.position.maxScrollExtent * 0.7) {
widget.onScrollEndReached();
}
}

@override
Widget build(BuildContext context) {
return BlocListener<ThunderBloc, ThunderState>(
listenWhen: (previous, current) => (previous.status == ThunderStatus.refreshing && current.status == ThunderStatus.success),
listener: (context, state) {},
child: RefreshIndicator(
onRefresh: () async {
HapticFeedback.mediumImpact();
if (widget.personId != null) {
//context.read<UserBloc>().add(GetUserEvent(userId: widget.personId, reset: true));
} else {
// context.read<CommunityBloc>().add(GetCommunityPostsEvent(
// reset: true,
// listingType: widget.communityId != null ? null : widget.listingType,
// communityId: widget.listingType != null ? null : widget.communityId,
// communityName: widget.listingType != null ? null : widget.communityName,
// ));
}
},
child: ListView.builder(
controller: _scrollController,
itemCount: widget.commentViewTrees?.length,
itemBuilder: (context, index) {
return CommentReference(
comment: widget.commentViewTrees![index].commentView!,
onVoteAction: widget.onVoteAction,
onSaveAction: widget.onSaveAction,
onDeleteAction: widget.onDeleteAction,
onReportAction: widget.onReportAction,
onReplyEditAction: widget.onReplyEditAction,
isOwnComment: widget.isOwnComment,
);
}),
),
);
}
}
8 changes: 8 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,14 @@
},
"saved": "Saved",
"@saved": {},
"savedComments": "Saved Comments",
"@savedComments": {
"description": "Comments a user has saved for future reference or review."
},
"savedPosts": "Saved Posts",
"@savedPosts": {
"description": "Posts a user has saved for future reference or review."
},
"scaled": "Scaled",
"@scaled": {},
"scrapeMissingLinkPreviews": "Scrape Missing Link Previews",
Expand Down
6 changes: 6 additions & 0 deletions lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'package:thunder/settings/pages/video_player_settings.dart';
import 'package:thunder/settings/settings.dart';
import 'package:thunder/thunder/thunder.dart';
import 'package:thunder/user/bloc/user_settings_bloc.dart';
import 'package:thunder/user/pages/user_saved.dart';
import 'package:thunder/user/pages/user_settings_page.dart';

PageController thunderPageController = PageController(initialPage: 0);
Expand Down Expand Up @@ -192,5 +193,10 @@ final GoRouter router = GoRouter(
),
],
),
GoRoute(
name: 'saved',
path: '/saved',
builder: (BuildContext context, GoRouterState state) => const UserSavedPage(),
),
],
);
188 changes: 188 additions & 0 deletions lib/user/pages/old_user_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
// import 'dart:io';

// 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';
// import 'package:thunder/account/utils/profiles.dart';
// import 'package:thunder/core/singletons/lemmy_client.dart';
// import 'package:thunder/shared/primitive_wrapper.dart';
// import 'package:thunder/shared/snackbar.dart';
// import 'package:thunder/thunder/bloc/thunder_bloc.dart';
// import 'package:thunder/user/bloc/user_settings_bloc.dart';
// import 'package:thunder/user/pages/user_page_new.dart';
// import 'package:thunder/user/pages/user_page_success.dart';
// import 'package:thunder/shared/error_message.dart';
// import 'package:thunder/user/bloc/user_bloc_old.dart';
// import 'package:thunder/user/pages/user_settings_page.dart';

// class UserPage extends StatefulWidget {
// final int? userId;
// final bool isAccountUser;
// final String? username;
// final List<bool>? selectedUserOption;
// final PrimitiveWrapper<bool>? savedToggle;

// const UserPage({
// super.key,
// this.userId,
// this.isAccountUser = false,
// this.username,
// this.selectedUserOption,
// this.savedToggle,
// });

// @override
// State<UserPage> createState() => _UserPageState();
// }

// 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 BlocProvider<UserBloc>(
// create: (BuildContext context) => UserBloc(lemmyClient: LemmyClient.instance),
// 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
// // ? 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,
// // ),
// // )
// // : 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.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,
// // ),
// // tooltip: AppLocalizations.of(context)!.share,
// // ),
// // ),
// // 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>();
// // final UserSettingsBloc userSettingsBloc = UserSettingsBloc();

// // Navigator.of(context).push(
// // SwipeablePageRoute(
// // transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null,
// // canSwipe: Platform.isIOS || state.enableFullScreenSwipeNavigationGesture,
// // canOnlySwipeFromEdge: !state.enableFullScreenSwipeNavigationGesture,
// // builder: (context) => MultiBlocProvider(
// // providers: [
// // BlocProvider.value(value: accountBloc),
// // BlocProvider.value(value: thunderBloc),
// // BlocProvider.value(value: userSettingsBloc),
// // ],
// // child: const UserSettingsPage(),
// // ),
// // ),
// // );
// // },
// // icon: Icon(
// // Icons.settings_rounded,
// // semanticLabel: AppLocalizations.of(context)!.accountSettings,
// // ),
// // tooltip: AppLocalizations.of(context)!.accountSettings,
// // ),
// // ),
// // ],
// // ),
// body: BlocBuilder<UserBloc, UserState>(builder: (context, state) {
// userBloc = context.read<UserBloc>();

// if (state.status == UserStatus.failedToBlock) {
// showSnackbar(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));
// return const Center(child: CircularProgressIndicator());
// case UserStatus.loading:
// return const Center(child: CircularProgressIndicator());
// case UserStatus.refreshing:
// case UserStatus.success:
// case UserStatus.failedToBlock:
// if (state.personView == null) {
// return const Center(child: CircularProgressIndicator());
// }
// return UserPageNew(
// 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,
// fullPersonView: state.fullPersonView,
// );
// case UserStatus.empty:
// return Container();
// case UserStatus.failure:
// return ErrorMessage(
// message: state.errorMessage,
// actions: [
// (
// text: AppLocalizations.of(context)!.refreshContent,
// action: () => context.read<UserBloc>().add(GetUserEvent(userId: widget.userId, reset: true)),
// loading: false,
// ),
// ],
// );
// }
// }),
// ),
// ),
// );
// }
// }
Loading
Loading