Skip to content

Commit

Permalink
Show suggested book
Browse files Browse the repository at this point in the history
  • Loading branch information
lockieRichter committed Mar 14, 2024
1 parent 9bf1f47 commit dbb6fd7
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 16 deletions.
5 changes: 4 additions & 1 deletion assets/translations/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"recommendations": {
"add-to-wishlist": "Zur Wunschliste hinzufügen",
"empty": "Keine Vorschläge verfügbar.",
"enter_recommendation": "TODO",
"error": "Oh nein! Während des Ladens der Vorschläge trat ein Fehler auf. Versuche es später nochmals.\n\nFehler: {}",
"events": {
"move-to-wishlist": {
Expand All @@ -132,7 +133,9 @@
"content": "Willst du wirklich das Buch {} melden?\n\nDu wirst dieses Buch nicht mehr als Vorschlag sehen.",
"report": "Buch melden",
"title": "Vorschlag melden"
}
},
"success": "TODO",
"suggest": "TODO"
},
"reset": "Zurücksetzen",
"reset_password": "Password zurücksetzen",
Expand Down
5 changes: 4 additions & 1 deletion assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"recommendations": {
"add-to-wishlist": "Add to wishlist",
"empty": "No recommendations available.",
"enter_recommendation": "Enter your recommendation",
"error": "Oh no! An error occurred while trying to fetch your recommendations. Please try again later.\n\nReason: {}",
"events": {
"move-to-wishlist": {
Expand All @@ -131,7 +132,9 @@
"content": "Do you really want to report the book {}?\n\nYou will no longer see this book as a recommendation.",
"report": "Report",
"title": "Report recommendation"
}
},
"success": "Wonderful. Your recommendation will be shown to other users. Thank you!",
"suggest": "Suggest"
},
"reset": "Reset",
"reset_password": "Reset Password",
Expand Down
19 changes: 17 additions & 2 deletions lib/src/ui/book/desktop_book_action_menu.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:dantex/src/data/book/entity/book.dart';
import 'package:dantex/src/data/book/entity/book_state.dart';
import 'package:dantex/src/ui/book/book_action.dart';
import 'package:dantex/src/ui/book/recommend_book_bottom_sheet.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -81,7 +82,7 @@ class DesktopBookActionMenu extends StatelessWidget {
);
}

void _handleAction(BuildContext context, BookAction value) {
Future<void> _handleAction(BuildContext context, BookAction value) async {
switch (value) {
case BookAction.moveToReadLater:
onBookStateChanged(_book, BookState.readLater);
Expand All @@ -96,7 +97,21 @@ class DesktopBookActionMenu extends StatelessWidget {
// Do not provide Share action for desktop UI.
break;
case BookAction.recommend:
// _showSuggestBookDialog();
await showModalBottomSheet(
useSafeArea: true,
context: context,
showDragHandle: true,
isScrollControlled: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
barrierColor: Colors.black54,
builder: (context) =>
RecommendBookBottomSheet(book: _book, isWeb: true),
);
break;
case BookAction.edit:
// TODO: Handle this case.
Expand Down
26 changes: 14 additions & 12 deletions lib/src/ui/book/mobile_book_action_menu.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:dantex/src/data/book/entity/book.dart';
import 'package:dantex/src/data/book/entity/book_state.dart';
import 'package:dantex/src/ui/book/recommend_book_bottom_sheet.dart';
import 'package:dantex/src/ui/core/dante_components.dart';
import 'package:dantex/src/ui/core/platform_components.dart';
import 'package:dantex/src/util/share_helper.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -62,10 +62,19 @@ class MobileBookActionMenu extends StatelessWidget {
title: 'book-actions.suggest'.tr(),
icon: Icons.whatshot_outlined,
color: Theme.of(context).colorScheme.secondary,
onClick: () async => showDanteDialog(
context,
title: 'TODO',
content: _RecommendBookDialog(),
onClick: () async => showModalBottomSheet(
useSafeArea: true,
context: context,
showDragHandle: true,
isScrollControlled: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
barrierColor: Colors.black54,
builder: (context) => RecommendBookBottomSheet(book: _book),
),
),
_buildBookAction(
Expand Down Expand Up @@ -116,10 +125,3 @@ class MobileBookActionMenu extends StatelessWidget {
);
}
}

class _RecommendBookDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const Text('TODO');
}
}
104 changes: 104 additions & 0 deletions lib/src/ui/book/recommend_book_bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import 'package:dantex/src/data/book/entity/book.dart';
import 'package:dantex/src/providers/service.dart';
import 'package:dantex/src/ui/book/book_image.dart';
import 'package:dantex/src/ui/core/dante_components.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class RecommendBookBottomSheet extends ConsumerStatefulWidget {
final Book book;
final bool isWeb;

const RecommendBookBottomSheet({
required this.book,
super.key,
this.isWeb = false,
});

@override
createState() => _RecommendBookBottomSheetState();
}

class _RecommendBookBottomSheetState
extends ConsumerState<RecommendBookBottomSheet> {
late TextEditingController textController;

@override
void initState() {
super.initState();
textController = TextEditingController();
}

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

@override
Widget build(BuildContext context) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
BookImage(
widget.book.thumbnailAddress,
size: 96,
),
const SizedBox(height: 16),
Text(
widget.book.title,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 16),
DanteTextField(
controller: textController,
maxLines: 6,
hint: 'recommendations.enter_recommendation'.tr(),
// formatter: LengthLimitingTextInputFormatter(180),
maxLength: 180,
buildCounter: (
context, {
required currentLength,
required isFocused,
required maxLength,
}) {
return Container(
child: Text(
'$currentLength/$maxLength',
style: Theme.of(context).textTheme.bodySmall,
),
);
},
),
const SizedBox(height: 16),
DanteOutlinedButton(
child: Text('recommendations.suggest'.tr()),
onPressed: () async {
await ref
.read(recommendationsProvider)
.recommendBook(widget.book, textController.text);
if (context.mounted) {
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'recommendations.success'.tr(),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium,
),
),
);
}
},
),
if (widget.isWeb) const SizedBox(height: 16),
],
),
),
);
}
}
11 changes: 11 additions & 0 deletions lib/src/ui/core/dante_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class DanteTextField extends StatelessWidget {
final int maxLines;
final String? errorText;
final TextInputFormatter? formatter;
final Widget? Function(
BuildContext context, {
required int currentLength,
required bool isFocused,
required int? maxLength,
})? buildCounter;
final int? maxLength;

const DanteTextField({
required this.controller,
Expand All @@ -45,6 +52,8 @@ class DanteTextField extends StatelessWidget {
this.errorText,
this.formatter,
this.label,
this.buildCounter,
this.maxLength,
});

@override
Expand All @@ -61,8 +70,10 @@ class DanteTextField extends StatelessWidget {
keyboardType: textInputType,
textInputAction: textInputAction,
maxLines: maxLines,
maxLength: maxLength,
onChanged: onChanged,
inputFormatters: [if (formatter != null) formatter!],
buildCounter: buildCounter,
decoration: InputDecoration(
label: label,
errorText: errorText,
Expand Down

0 comments on commit dbb6fd7

Please sign in to comment.