Skip to content

Commit

Permalink
Merge branch 'develop' into insert-comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsosa committed Sep 12, 2023
2 parents aa8515f + 5a7efc3 commit 5160223
Show file tree
Hide file tree
Showing 43 changed files with 880 additions and 605 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Added setting to import and export settings
- Added liveness and latency indicators for instances in profile switcher - contribution from @micahmo
- Add option to disabling graying out read posts - contribution from @micahmo
- Show sort type icon - contribution from @micahmo
- Downvote actions will be disabled when instances have downvotes disabled
- Automatically save drafts for posts and comments - contribution from @micahmo
- Newly created comments get inserted into comment list correctly without losing your scroll position. If comment is top level, the list scrolls to your comment. The comment also gets highlighted - contribution from @ajsosa
Expand All @@ -35,6 +36,7 @@
- Improve contrast and distinction of special user identifiers - contribution from @micahmo
- Show swatches and live previews for accent color selection - contribution from @micahmo
- Use Android system back button to navigate from Saved to History on profile page - contribution from @micahmo
- Hide community name and show usernames when viewing a community - contribution from @micahmo

### Fixed

Expand Down
4 changes: 3 additions & 1 deletion lib/community/bloc/community_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import 'package:thunder/core/models/post_view_media.dart';
import 'package:thunder/core/singletons/lemmy_client.dart';
import 'package:thunder/core/singletons/preferences.dart';
import 'package:thunder/utils/constants.dart';
import 'package:thunder/utils/error_messages.dart';
import 'package:thunder/utils/global_context.dart';
import 'package:thunder/utils/post.dart';

part 'community_event.dart';
Expand Down Expand Up @@ -434,7 +436,7 @@ class CommunityBloc extends Bloc<CommunityEvent, CommunityState> {
return emit(
state.copyWith(
status: CommunityStatus.failure,
errorMessage: e.toString(),
errorMessage: e is LemmyApiException ? getErrorMessage(GlobalContext.context, e.message) : e.toString(),
communityId: state.communityId,
listingType: state.listingType,
),
Expand Down
16 changes: 15 additions & 1 deletion lib/community/pages/community_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ class _CommunityPageState extends State<CommunityPage> with AutomaticKeepAliveCl
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
subtitle: Text(getSortName(state)),
subtitle: Row(
children: [
Icon(getSortIcon(state), size: 13),
const SizedBox(width: 4),
Text(getSortName(state)),
],
),
contentPadding: const EdgeInsets.symmetric(horizontal: 0),
),
centerTitle: false,
Expand Down Expand Up @@ -494,6 +500,14 @@ class _CommunityPageState extends State<CommunityPage> with AutomaticKeepAliveCl
return sortTypeLabel ?? '';
}

IconData? getSortIcon(CommunityState state) {
if (state.status == CommunityStatus.initial || state.status == CommunityStatus.loading) {
return null;
}

return sortTypeIcon;
}

FutureOr<bool> _handleBack(bool stopDefaultButtonEvent, RouteInfo info) async {
if (context.read<ThunderBloc>().state.isFabOpen) {
context.read<ThunderBloc>().add(const OnFabToggle(false));
Expand Down
56 changes: 5 additions & 51 deletions lib/community/utils/post_card_action_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import 'package:thunder/shared/picker_item.dart';
import 'package:thunder/shared/snackbar.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/user/pages/user_page.dart';
import 'package:thunder/utils/navigate_community.dart';
import 'package:thunder/utils/navigate_user.dart';
import 'package:thunder/utils/swipe.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

Expand Down Expand Up @@ -116,23 +118,7 @@ void showPostActionBottomModalSheet(BuildContext context, PostViewMedia postView
onTapCommunityName(context, postViewMedia.postView.community.id);
break;
case PostCardAction.visitProfile:
AccountBloc accountBloc = context.read<AccountBloc>();
AuthBloc authBloc = context.read<AuthBloc>();
ThunderBloc thunderBloc = context.read<ThunderBloc>();

Navigator.of(context).push(
SwipeablePageRoute(
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isFeedPage: true),
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: accountBloc),
BlocProvider.value(value: authBloc),
BlocProvider.value(value: thunderBloc),
],
child: UserPage(userId: postViewMedia.postView.post.creatorId),
),
),
);
navigateToUserPage(context, userId: postViewMedia.postView.post.creatorId);
break;
case PostCardAction.sharePost:
Share.share(postViewMedia.postView.post.apId);
Expand Down Expand Up @@ -183,41 +169,9 @@ void showPostActionBottomModalSheet(BuildContext context, PostViewMedia postView
}

void onTapCommunityName(BuildContext context, int communityId) {
AccountBloc accountBloc = context.read<AccountBloc>();
AuthBloc authBloc = context.read<AuthBloc>();
ThunderBloc thunderBloc = context.read<ThunderBloc>();

Navigator.of(context).push(
SwipeablePageRoute(
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isFeedPage: true),
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: accountBloc),
BlocProvider.value(value: authBloc),
BlocProvider.value(value: thunderBloc),
],
child: CommunityPage(communityId: communityId),
),
),
);
navigateToCommunityPage(context, communityId: communityId);
}

void onTapUserName(BuildContext context, int userId) {
AccountBloc accountBloc = context.read<AccountBloc>();
AuthBloc authBloc = context.read<AuthBloc>();
ThunderBloc thunderBloc = context.read<ThunderBloc>();

Navigator.of(context).push(
SwipeablePageRoute(
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isFeedPage: true),
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: accountBloc),
BlocProvider.value(value: authBloc),
BlocProvider.value(value: thunderBloc),
],
child: UserPage(userId: userId),
),
),
);
navigateToUserPage(context, userId: userId);
}
27 changes: 9 additions & 18 deletions lib/community/widgets/community_sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import 'package:thunder/core/singletons/preferences.dart';
import 'package:thunder/shared/snackbar.dart';
import 'package:thunder/shared/user_avatar.dart';
import 'package:thunder/utils/instance.dart';
import 'package:thunder/utils/navigate_user.dart';
import 'package:thunder/utils/swipe.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import '../../shared/common_markdown_body.dart';
Expand Down Expand Up @@ -156,8 +158,11 @@ class _CommunitySidebarState extends State<CommunitySidebar> with TickerProvider
}
});

Navigator.of(context).push(
Navigator.of(context)
.push(
SwipeablePageRoute(
canOnlySwipeFromEdge: true,
backGestureDetectionWidth: 45,
builder: (context) {
return MultiBlocProvider(
providers: [
Expand All @@ -174,7 +179,8 @@ class _CommunitySidebarState extends State<CommunitySidebar> with TickerProvider
);
},
),
).whenComplete(() async {
)
.whenComplete(() async {
timer.cancel();

if (newDraftPost?.saveAsDraft == true && newDraftPost?.isNotEmpty == true) {
Expand Down Expand Up @@ -513,22 +519,7 @@ class _CommunitySidebarState extends State<CommunitySidebar> with TickerProvider
for (var mods in widget.communityInfo!.moderators)
GestureDetector(
onTap: () {
AccountBloc accountBloc = context.read<AccountBloc>();
AuthBloc authBloc = context.read<AuthBloc>();
ThunderBloc thunderBloc = context.read<ThunderBloc>();

Navigator.of(context).push(
SwipeablePageRoute(
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: accountBloc),
BlocProvider.value(value: authBloc),
BlocProvider.value(value: thunderBloc),
],
child: UserPage(userId: mods.moderator!.id),
),
),
);
navigateToUserPage(context, userId: mods.moderator!.id);
},
child: Padding(
padding: const EdgeInsets.only(bottom: 8.0),
Expand Down
13 changes: 8 additions & 5 deletions lib/community/widgets/post_card.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

Expand All @@ -23,7 +25,7 @@ import '../../user/bloc/user_bloc.dart';

class PostCard extends StatefulWidget {
final PostViewMedia postViewMedia;
final bool showInstanceName;
final bool communityMode;
final bool indicateRead;

final Function(VoteType) onVoteAction;
Expand All @@ -35,7 +37,7 @@ class PostCard extends StatefulWidget {
const PostCard({
super.key,
required this.postViewMedia,
this.showInstanceName = true,
required this.communityMode,
required this.onVoteAction,
required this.onSaveAction,
required this.onToggleReadAction,
Expand Down Expand Up @@ -202,7 +204,7 @@ class _PostCardState extends State<PostCard> {
showPostAuthor: state.showPostAuthor,
hideNsfwPreviews: state.hideNsfwPreviews,
markPostReadOnMediaView: state.markPostReadOnMediaView,
showInstanceName: widget.showInstanceName,
communityMode: widget.communityMode,
isUserLoggedIn: isUserLoggedIn,
listingType: widget.listingType,
navigateToPost: () async => await navigateToPost(context),
Expand All @@ -213,7 +215,7 @@ class _PostCardState extends State<PostCard> {
showThumbnailPreviewOnRight: state.showThumbnailPreviewOnRight,
hideNsfwPreviews: state.hideNsfwPreviews,
markPostReadOnMediaView: state.markPostReadOnMediaView,
showInstanceName: widget.showInstanceName,
communityMode: widget.communityMode,
showPostAuthor: state.showPostAuthor,
showFullHeightImages: state.showFullHeightImages,
edgeToEdgeImages: state.showEdgeToEdgeImages,
Expand Down Expand Up @@ -269,7 +271,8 @@ class _PostCardState extends State<PostCard> {

await Navigator.of(context).push(
SwipeablePageRoute(
backGestureDetectionStartOffset: 45,
backGestureDetectionStartOffset: Platform.isAndroid ? 45 : 0,
backGestureDetectionWidth: 45,
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isPostPage: true),
builder: (context) {
return MultiBlocProvider(
Expand Down
2 changes: 1 addition & 1 deletion lib/community/widgets/post_card_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class _PostCardListState extends State<PostCardList> with TickerProviderStateMix
child: !toRemoveSet.contains(postViewMedia.postView.post.id)
? PostCard(
postViewMedia: postViewMedia,
showInstanceName: widget.communityId == null,
communityMode: widget.communityId != null || widget.communityName != null,
onVoteAction: (VoteType voteType) => widget.onVoteAction(postViewMedia.postView.post.id, voteType),
onSaveAction: (bool saved) => widget.onSaveAction(postViewMedia.postView.post.id, saved),
onToggleReadAction: (bool read) => widget.onToggleReadAction(postViewMedia.postView.post.id, read),
Expand Down
30 changes: 16 additions & 14 deletions lib/community/widgets/post_card_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ class PostCommunityAndAuthor extends StatelessWidget {
super.key,
required this.postView,
required this.showCommunityIcons,
required this.showInstanceName,
required this.communityMode,
this.textStyleAuthor,
this.textStyleCommunity,
required this.compactMode,
required this.showCommunitySubscription,
});

final bool showCommunityIcons;
final bool showInstanceName;
final bool communityMode;
final bool compactMode;
final PostView postView;
final TextStyle? textStyleAuthor;
Expand Down Expand Up @@ -252,21 +252,22 @@ class PostCommunityAndAuthor extends StatelessWidget {
alignment: WrapAlignment.start,
crossAxisAlignment: WrapCrossAlignment.end,
children: [
if (state.showPostAuthor)
if (state.showPostAuthor || communityMode)
Row(
mainAxisSize: MainAxisSize.min,
children: [
InkWell(
borderRadius: BorderRadius.circular(6),
onTap: (compactMode && !state.tappableAuthorCommunity) ? null : () => onTapUserName(context, postView.creator.id),
child: Text('$creatorName', textScaleFactor: MediaQuery.of(context).textScaleFactor * state.metadataFontSizeScale.textScaleFactor, style: textStyleAuthor)),
Text(
' to ',
textScaleFactor: MediaQuery.of(context).textScaleFactor * state.metadataFontSizeScale.textScaleFactor,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.textTheme.bodyMedium?.color?.withOpacity(0.4),
if (!communityMode)
Text(
' to ',
textScaleFactor: MediaQuery.of(context).textScaleFactor * state.metadataFontSizeScale.textScaleFactor,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.textTheme.bodyMedium?.color?.withOpacity(0.4),
),
),
),
],
),
InkWell(
Expand All @@ -275,11 +276,12 @@ class PostCommunityAndAuthor extends StatelessWidget {
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'${postView.community.name}${showInstanceName ? ' · ${fetchInstanceNameFromUrl(postView.community.actorId)}' : ''}',
textScaleFactor: MediaQuery.of(context).textScaleFactor * state.metadataFontSizeScale.textScaleFactor,
style: textStyleCommunity,
),
if (!communityMode)
Text(
'${postView.community.name} · ${fetchInstanceNameFromUrl(postView.community.actorId)}',
textScaleFactor: MediaQuery.of(context).textScaleFactor * state.metadataFontSizeScale.textScaleFactor,
style: textStyleCommunity,
),
if (showCommunitySubscription)
Padding(
padding: const EdgeInsets.only(
Expand Down
Loading

0 comments on commit 5160223

Please sign in to comment.