Skip to content

Commit

Permalink
minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hjiangsu committed Jun 15, 2023
1 parent f4d914f commit 5a88a40
Show file tree
Hide file tree
Showing 27 changed files with 375 additions and 270 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ Your passion, contributions, and ideas would be greatly appreciated! Together, l
</p>
<hr />

## Features

Thunder is currently undergoing **active development**, and it is possible that not all features have been fully implemented at this stage.
## Releases
**Note:** As this is still in alpha and WIP, releases will happen through GitHub. There are no plans at the moment to release to Google Play store (and derivatives) or Apple's TestFlight. However, this may change in the future as more progress is made.

All releases will be held in the [Releases](https://github.com/hjiangsu/thunder/releases) section under the corresponding version.
- For iOS users, you can install Thunder using [AltStore](https://altstore.io/)
- For Android users, simply install Thunder with the provided APK file.

Due to this, significant breaking changes may occur between versions. The next section summarizes the features that are currently implemented.
## Features

Thunder is currently undergoing **active development**, and it is possible that not all features have been fully implemented at this stage. Due to this, significant breaking changes may occur between versions. The next section summarizes the features that are currently implemented.

#### **Communities**

Expand All @@ -75,11 +81,11 @@ Due to this, significant breaking changes may occur between versions. The next s

#### **Authentication**

- Singe account login with instance
- Single account login with instance

#### **Theme & Customization**

- N/A
- Basic settings

## Roadmap

Expand All @@ -98,8 +104,6 @@ Contributions are always welcome! To contribute potential features or bug-fixes:

## Building From Source

There are a few prerequisites in order to build and run the application locally.

### Installing Flutter and Related Dependencies

Thunder is developed with Flutter, and is built to support both iOS and Android.
Expand Down
1 change: 0 additions & 1 deletion lib/account/bloc/account_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
posts: getPersonDetailsResponse.posts,
));
} catch (e) {
print('re-attempting: $attemptCount');
attemptCount += 1;
}
}
Expand Down
22 changes: 13 additions & 9 deletions lib/community/bloc/community_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ class CommunityBloc extends Bloc<CommunityEvent, CommunityState> {
Future<void> _getCommunityPostsEvent(GetCommunityPostsEvent event, Emitter<CommunityState> emit) async {
int attemptCount = 0;

print('event: ${event.communityId} state ${state.communityId}');

try {
Stopwatch stopwatch = Stopwatch()..start();

while (attemptCount < 2) {
try {
LemmyClient lemmyClient = LemmyClient.instance;
Expand All @@ -114,7 +114,7 @@ class CommunityBloc extends Bloc<CommunityEvent, CommunityState> {
GetPosts(
auth: jwt,
page: 1,
limit: 30,
limit: 15,
sort: event.sortType ?? SortType.Hot,
type_: event.listingType ?? ListingType.Local,
communityId: event.communityId,
Expand All @@ -125,41 +125,45 @@ class CommunityBloc extends Bloc<CommunityEvent, CommunityState> {

return emit(state.copyWith(
status: CommunityStatus.success,
postViews: posts,
page: 2,
postViews: posts,
listingType: event.listingType ?? ListingType.Local,
communityId: event.communityId,
hasReachedEnd: posts.isEmpty,
));
} else {
if (state.hasReachedEnd) return emit(state.copyWith(status: CommunityStatus.success));
emit(state.copyWith(status: CommunityStatus.refreshing));

GetPostsResponse getPostsResponse = await lemmy.getPosts(
GetPosts(
auth: jwt,
page: state.page,
limit: 30,
limit: 15,
sort: event.sortType ?? SortType.Hot,
type_: state.listingType,
type_: state.listingType ?? ListingType.Local,
communityId: state.communityId,
),
);

List<PostViewMedia> posts = await parsePostViews(getPostsResponse.posts);

List<PostViewMedia> postViews = List.from(state.postViews ?? []);
postViews.addAll(posts);

return emit(
state.copyWith(
status: CommunityStatus.success,
postViews: postViews,
page: state.page + 1,
postViews: postViews,
hasReachedEnd: posts.isEmpty,
),
);
}
} catch (e) {
print('re-attempting: $attemptCount');
attemptCount += 1;
}
}
print('doSomething() executed in ${stopwatch.elapsed}');
} on DioException catch (e) {
emit(state.copyWith(status: CommunityStatus.failure, errorMessage: e.message));
} catch (e) {
Expand Down
7 changes: 6 additions & 1 deletion lib/community/bloc/community_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CommunityState extends Equatable {
this.errorMessage,
this.listingType = ListingType.Local,
this.communityId,
this.hasReachedEnd = false,
});

final CommunityStatus status;
Expand All @@ -23,13 +24,16 @@ class CommunityState extends Equatable {
// Specifies the community we are loading for
final int? communityId;

final bool hasReachedEnd;

CommunityState copyWith({
CommunityStatus? status,
int? page,
List<PostViewMedia>? postViews,
String? errorMessage,
ListingType? listingType,
int? communityId,
bool? hasReachedEnd,
}) {
return CommunityState(
status: status ?? this.status,
Expand All @@ -38,9 +42,10 @@ class CommunityState extends Equatable {
errorMessage: errorMessage ?? this.errorMessage,
listingType: listingType ?? this.listingType,
communityId: communityId ?? this.communityId,
hasReachedEnd: hasReachedEnd ?? this.hasReachedEnd,
);
}

@override
List<Object?> get props => [status, page, postViews, errorMessage, listingType, communityId];
List<Object?> get props => [status, page, postViews, errorMessage, listingType, communityId, hasReachedEnd];
}
35 changes: 15 additions & 20 deletions lib/community/pages/community_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lemmy/lemmy.dart';

import 'package:thunder/community/bloc/community_bloc.dart';
import 'package:thunder/community/pages/create_post_page.dart';
import 'package:thunder/community/widgets/community_drawer.dart';
import 'package:thunder/community/widgets/post_card_list.dart';

Expand Down Expand Up @@ -52,7 +51,6 @@ const sortTypeItems = [

class CommunityPage extends StatefulWidget {
final int? communityId;

const CommunityPage({super.key, this.communityId});

@override
Expand Down Expand Up @@ -88,7 +86,7 @@ class _CommunityPageState extends State<CommunityPage> {
(state.status == CommunityStatus.loading || state.status == CommunityStatus.initial)
? ''
: (state.communityId != null)
? (state.postViews?.first.community.name ?? '')
? (state.postViews?.firstOrNull?.community.name ?? '')
: ((state.listingType != null) ? (destinations.firstWhere((destination) => destination.listingType == state.listingType).label) : ''),
),
centerTitle: false,
Expand Down Expand Up @@ -162,14 +160,14 @@ class _CommunityPageState extends State<CommunityPage> {
],
),
drawer: (widget.communityId != null) ? null : const CommunityDrawer(),
floatingActionButton: (state.communityId != null)
? FloatingActionButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => CreatePostPage(communityId: state.communityId!)));
},
child: const Icon(Icons.add),
)
: null,
// floatingActionButton: (state.communityId != null)
// ? FloatingActionButton(
// onPressed: () {
// Navigator.of(context).push(MaterialPageRoute(builder: (context) => CreatePostPage(communityId: state.communityId!)));
// },
// child: const Icon(Icons.add),
// )
// : null,
body: SafeArea(child: _getBody(context, state)),
);
},
Expand All @@ -191,7 +189,11 @@ class _CommunityPageState extends State<CommunityPage> {
case CommunityStatus.refreshing:
case CommunityStatus.networkFailure:
case CommunityStatus.success:
return PostCardList(postViews: state.postViews, communityId: widget.communityId);
return PostCardList(
postViews: state.postViews,
communityId: widget.communityId,
hasReachedEnd: state.hasReachedEnd,
);
case CommunityStatus.empty:
case CommunityStatus.failure:
return Center(
Expand All @@ -216,14 +218,7 @@ class _CommunityPageState extends State<CommunityPage> {
const SizedBox(height: 32.0),
ElevatedButton(
style: ElevatedButton.styleFrom(minimumSize: const Size.fromHeight(50)),
onPressed: () => {
context.read<CommunityBloc>().add(
GetCommunityPostsEvent(
reset: true,
communityId: widget.communityId,
),
),
},
onPressed: () => context.read<CommunityBloc>().add(GetCommunityPostsEvent(reset: true, communityId: widget.communityId)),
child: const Text('Refresh Content'),
),
],
Expand Down
4 changes: 1 addition & 3 deletions lib/community/pages/create_post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _CreatePostPageState extends State<CreatePostPage> {
bool isClearButtonDisabled = false;
bool isSubmitButtonDisabled = true;

final List<bool> _selectedPostType = <bool>[true, false, false];
// final List<bool> _selectedPostType = <bool>[true, false, false];

String description = '';
TextEditingController controller = TextEditingController();
Expand All @@ -33,8 +33,6 @@ class _CreatePostPageState extends State<CreatePostPage> {
controller.addListener(() {
if (controller.text.isEmpty && !isClearButtonDisabled) setState(() => isClearButtonDisabled = true);
if (controller.text.isNotEmpty && isClearButtonDisabled) setState(() => isClearButtonDisabled = false);

print(controller.text);
});

_titleTextController.addListener(() {
Expand Down
Loading

0 comments on commit 5a88a40

Please sign in to comment.