Skip to content

Commit

Permalink
feat: bookmark button in game screens
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <[email protected]>
  • Loading branch information
ZTL-UwU committed Jul 21, 2024
1 parent b8ed607 commit 8083469
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 26 deletions.
13 changes: 12 additions & 1 deletion lib/src/view/game/archived_game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class ArchivedGameScreen extends ConsumerWidget {
appBar: AppBar(
title: _GameTitle(gameData: gameData),
actions: [
BookmarkButton(
id: gameData.id,
),
ToggleSoundButton(),
],
),
Expand All @@ -71,7 +74,15 @@ class ArchivedGameScreen extends ConsumerWidget {
border: null,
middle: _GameTitle(gameData: gameData),
padding: const EdgeInsetsDirectional.only(end: 16.0),
trailing: ToggleSoundButton(),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
BookmarkButton(
id: gameData.id,
),
ToggleSoundButton(),
],
),
),
child: SafeArea(
bottom: false,
Expand Down
81 changes: 57 additions & 24 deletions lib/src/view/game/game_common_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:lichess_mobile/src/model/common/http.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
import 'package:lichess_mobile/src/model/common/time_increment.dart';
import 'package:lichess_mobile/src/model/game/game.dart';
import 'package:lichess_mobile/src/model/game/game_repository.dart';
import 'package:lichess_mobile/src/model/game/game_share_service.dart';
import 'package:lichess_mobile/src/model/lobby/game_seek.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
Expand All @@ -21,6 +22,42 @@ import 'game_screen_providers.dart';
import 'game_settings.dart';
import 'ping_rating.dart';

class BookmarkButton extends ConsumerWidget {
const BookmarkButton({required this.id});
final GameId id;
@override
Widget build(BuildContext context, WidgetRef ref) {
return AppBarIconButton(
onPressed: () {
ref.withClient(
(client) => GameRepository(client).bookmark(id.gameId, v: 1),
);
},
semanticsLabel: 'Bookmark Game',
icon: const Icon(Icons.star_border_rounded),
);
}
}

class _SettingButton extends ConsumerWidget {
const _SettingButton({required this.id});
final GameFullId id;
@override
Widget build(BuildContext context, WidgetRef ref) {
return AppBarIconButton(
onPressed: () => showAdaptiveBottomSheet<void>(
context: context,
isDismissible: true,
isScrollControlled: true,
showDragHandle: true,
builder: (_) => GameSettings(id: id),
),
semanticsLabel: context.l10n.settingsSettings,
icon: const Icon(Icons.settings),
);
}
}

class GameAppBar extends ConsumerWidget implements PreferredSizeWidget {
const GameAppBar({this.id, this.seek, this.challenge, super.key});

Expand Down Expand Up @@ -52,18 +89,14 @@ class GameAppBar extends ConsumerWidget implements PreferredSizeWidget {
? _ChallengeGameTitle(challenge: challenge!)
: const SizedBox.shrink(),
actions: [
if (id != null)
AppBarIconButton(
onPressed: () => showAdaptiveBottomSheet<void>(
context: context,
isDismissible: true,
isScrollControlled: true,
showDragHandle: true,
builder: (_) => GameSettings(id: id!),
),
semanticsLabel: context.l10n.settingsSettings,
icon: const Icon(Icons.settings),
if (id != null) ...[
BookmarkButton(
id: id!.gameId,
),
_SettingButton(
id: id!,
),
],
],
);
}
Expand Down Expand Up @@ -106,19 +139,19 @@ class GameCupertinoNavBar extends ConsumerWidget
: challenge != null
? _ChallengeGameTitle(challenge: challenge!)
: const SizedBox.shrink(),
trailing: id != null
? AppBarIconButton(
onPressed: () => showAdaptiveBottomSheet<void>(
context: context,
isDismissible: true,
isScrollControlled: true,
showDragHandle: true,
builder: (_) => GameSettings(id: id!),
),
semanticsLabel: context.l10n.settingsSettings,
icon: const Icon(Icons.settings),
)
: null,
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (id != null) ...[
BookmarkButton(
id: id!.gameId,
),
_SettingButton(
id: id!,
),
],
],
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/game/game_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class _ContextMenu extends ConsumerWidget {
(client) => GameRepository(client).bookmark(game.id, v: 1),
);
},
icon: CupertinoIcons.star,
icon: Icons.star_border_rounded,
closeOnPressed: false,
child: const Text('Bookmark Game'),
),
Expand Down

0 comments on commit 8083469

Please sign in to comment.