Skip to content

Commit

Permalink
feat: init following screen
Browse files Browse the repository at this point in the history
  • Loading branch information
papo1011 committed Oct 11, 2023
1 parent 98c993f commit d489404
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/src/model/auth/auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:lichess_mobile/src/constants.dart';
part 'auth_repository.g.dart';

const redirectUri = 'org.lichess.mobile://login-callback';
const oauthScopes = ['web:mobile'];
const oauthScopes = ['web:mobile', 'follow:read', 'follow:write'];

@Riverpod(keepAlive: true)
AuthRepository authRepository(AuthRepositoryRef ref) {
Expand Down
105 changes: 105 additions & 0 deletions lib/src/view/relation/following_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/model/relation/relation_repository_providers.dart';
import 'package:lichess_mobile/src/widgets/list.dart';

import 'package:lichess_mobile/src/widgets/platform.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/styles/lichess_colors.dart';
import 'package:lichess_mobile/src/widgets/shimmer.dart';

class FollowingScreen extends StatelessWidget {
const FollowingScreen({super.key});

@override
Widget build(BuildContext context) {
return PlatformWidget(androidBuilder: _buildAndroid, iosBuilder: _buildIos);
}

Widget _buildIos(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
previousPageTitle: context.l10n.friends,
middle: const Text("Following"),
),
child: const _Body(),
);
}

Widget _buildAndroid(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(context.l10n.leaderboard),
),
body: const _Body(),
);
}
}

class _Body extends ConsumerWidget {
const _Body();

@override
Widget build(BuildContext context, WidgetRef ref) {
final following = ref.watch(followingProvider);

return following.when(
data: (data) {
if (data.isEmpty) {
const Center(
child: Text("You are not following any user"),
);
}
return SafeArea(
child: ListSection(
children: [
for (final user in data)
PlatformListTile(
onTap: () => {},
title: Padding(
padding: const EdgeInsets.only(right: 5.0),
child: Row(
children: [
if (user.title != null) ...[
Text(
user.title!,
style: const TextStyle(
color: LichessColors.brag,
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 5),
],
Flexible(
child: Text(
user.username,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
),
],
),
);
},
error: (error, stackTrace) {
debugPrint(
'SEVERE: [FollowingScreen] could not following users; $error\n$stackTrace',
);
return const Text('Could not load following users.');
},
loading: () => Shimmer(
child: ShimmerLoading(
isLoading: true,
child: ListSection.loading(
itemsNumber: 10,
header: true,
),
),
),
);
}
}
33 changes: 26 additions & 7 deletions lib/src/view/relation/relation_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/model/relation/relation_ctrl.dart';
import 'package:lichess_mobile/src/view/relation/following_screen.dart';
import 'package:lichess_mobile/src/widgets/list.dart';
import 'package:lichess_mobile/src/widgets/platform.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/widgets/buttons.dart';
import 'package:lichess_mobile/src/widgets/shimmer.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';

class RelationScreen extends ConsumerStatefulWidget {
const RelationScreen({super.key});
Expand Down Expand Up @@ -64,37 +66,46 @@ class _OnlineFriendsWidget extends ConsumerWidget {
return relationState.when(
data: (data) {
return ListSection(
hasLeading: true,
header: Text(
'${data.followingOnlines.length} Online ${context.l10n.friends}', // TODO: we need good translations for this
),
headerTrailing: data.followingOnlines.isEmpty
? null
: NoPaddingTextButton(
onPressed: () {},
onPressed: () => _handleTap(context),
child: Text(
context.l10n.more,
),
),
children: [
if (data.followingOnlines.isEmpty)
PlatformListTile(
title: Text(
context.l10n.friends,
title: const Text(
"Following",
),
trailing: const Icon(
Icons.chevron_right,
),
onTap: () {},
onTap: () => _handleTap(context),
),
for (final username in data.followingOnlines)
PlatformListTile(title: Text(username.toString())),
PlatformListTile(
title: Padding(
padding: const EdgeInsets.only(right: 5.0),
child: Flexible(
child: Text(
username.toString(),
overflow: TextOverflow.ellipsis,
),
),
),
),
],
);
},
error: (error, stackTrace) {
debugPrint(
'SEVERE: [OnlineFriendsWidget] could not lead leaderboard data; $error\n $stackTrace',
'SEVERE: [RelationScreen] could not lead online friends data; $error\n $stackTrace',
);
return Padding(
padding: Styles.bodySectionPadding,
Expand All @@ -112,4 +123,12 @@ class _OnlineFriendsWidget extends ConsumerWidget {
),
);
}

void _handleTap(BuildContext context) {
pushPlatformRoute(
context,
title: "Following",
builder: (_) => const FollowingScreen(),
);
}
}

0 comments on commit d489404

Please sign in to comment.