Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Tutorial after sign up #543

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions kitchenowl/lib/cubits/auth_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,28 @@ class AuthCubit extends Cubit<AuthState> {
}
}

void onboard({
Future<void> onboard({
required String username,
required String name,
required String password,
Function()? wrongCredentialsCallback,
Function()? correctCredentialsCallback,
}) async {
emit(const Loading());
if (await ApiService.getInstance().isOnboarding()) {
final token =
await ApiService.getInstance().onboarding(username, name, password);
if (token != null && ApiService.getInstance().isAuthenticated()) {
await SecureStorage.getInstance().write(key: 'TOKEN', value: token);
await this.stream.any((s) => s is Authenticated);
if (correctCredentialsCallback != null) {
correctCredentialsCallback();
}
} else {
updateState();
await updateState();
if (wrongCredentialsCallback != null) {
wrongCredentialsCallback();
}
}
}
}
Expand All @@ -164,6 +173,7 @@ class AuthCubit extends Cubit<AuthState> {
required String password,
required String email,
Function(String?)? wrongCredentialsCallback,
Function()? correctCredentialsCallback,
}) async {
emit(const Loading());
final (token, msg) = await ApiService.getInstance().signup(
Expand All @@ -174,6 +184,10 @@ class AuthCubit extends Cubit<AuthState> {
);
if (token != null && ApiService.getInstance().isAuthenticated()) {
await SecureStorage.getInstance().write(key: 'TOKEN', value: token);
await this.stream.any((s) => s is Authenticated);
if (correctCredentialsCallback != null) {
correctCredentialsCallback();
}
} else {
await updateState();
if (ApiService.getInstance().connectionStatus == Connection.connected &&
Expand Down
20 changes: 20 additions & 0 deletions kitchenowl/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
"@go": {},
"@grid": {},
"@helpTranslate": {},
"@hi": {
"placeholders": {
"name": {}
}
},
"@household": {},
"@householdDelete": {},
"@householdDeleteConfirmation": {
Expand Down Expand Up @@ -316,6 +321,7 @@
}
},
"@signup": {},
"@skip": {},
"@smaller": {},
"@sortingAlgorithmic": {},
"@sortingAlphabetical": {},
Expand All @@ -339,6 +345,14 @@
"@themeSystem": {},
"@total": {},
"@totalTime": {},
"@tutorialItemDescription1": {},
"@tutorialItemDescription2": {},
"@tutorialRecipeDescription": {},
"@tutorialRecipeMore": {
"placeholders": {
"url": {}
}
},
"@uncategorized": {},
"@underConstruction": {},
"@undo": {},
Expand Down Expand Up @@ -459,6 +473,7 @@
"go": "Go",
"grid": "Grid",
"helpTranslate": "Help translate",
"hi": "Hi {name}!",
"household": "Household",
"householdDelete": "Delete household",
"householdDeleteConfirmation": "Are you sure you want to delete {household}? This will delete any items, recipes, and expenses associated with that household.",
Expand Down Expand Up @@ -593,6 +608,7 @@
"shoppingLists": "Shopping lists",
"signInWith": "Sign in with {provider}",
"signup": "Sign up",
"skip": "Skip",
"smaller": "Smaller",
"sortingAlgorithmic": "Algorithmic",
"sortingAlphabetical": "Alphabetical",
Expand All @@ -612,6 +628,10 @@
"themeSystem": "System",
"total": "Total",
"totalTime": "Total time",
"tutorialItemDescription1": "When searching for items you can add an amount at the start of your query and it will be added as a description.",
"tutorialItemDescription2": "Or, if amounts are not enough, use a comma to seperate the item name and description.",
"tutorialRecipeDescription": "Inside of recipes you can use Markdown. Basic features are headlines specified with hash signs, numbered lists for instruction steps, and references to ingredients using an at sign and the ingredient name.",
"tutorialRecipeMore": "For more information visit the [documentation]({url}).",
"uncategorized": "Uncategorized",
"underConstruction": "Under construction",
"undo": "Undo",
Expand Down
28 changes: 1 addition & 27 deletions kitchenowl/lib/pages/expense_page.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:intl/intl.dart';
import 'package:kitchenowl/app.dart';
import 'package:kitchenowl/cubits/expense_cubit.dart';
import 'package:kitchenowl/enums/update_enum.dart';
import 'package:kitchenowl/helpers/url_launcher.dart';
import 'package:kitchenowl/models/expense.dart';
import 'package:kitchenowl/models/household.dart';
import 'package:kitchenowl/pages/expense_add_update_page.dart';
Expand Down Expand Up @@ -113,31 +110,8 @@ class _ExpensePageState extends State<ExpensePage> {
margin: const EdgeInsets.fromLTRB(16, 24, 16, 4),
child: Padding(
padding: const EdgeInsets.all(16),
child: MarkdownBody(
child: KitchenOwlMarkdownBody(
data: state.expense.description!,
shrinkWrap: true,
styleSheet: MarkdownStyleSheet.fromTheme(
Theme.of(context),
).copyWith(
blockquoteDecoration: BoxDecoration(
color: Theme.of(context).cardTheme.color ??
Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(2.0),
),
),
imageBuilder: (uri, title, alt) =>
CachedNetworkImage(
imageUrl: uri.toString(),
placeholder: (context, url) =>
const CircularProgressIndicator(),
errorWidget: (context, url, error) =>
const Icon(Icons.error),
),
onTapLink: (text, href, title) {
if (href != null && isValidUrl(href)) {
openUrl(context, href);
}
},
),
),
),
Expand Down
8 changes: 5 additions & 3 deletions kitchenowl/lib/pages/onboarding_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:kitchenowl/cubits/auth_cubit.dart';
import 'package:kitchenowl/kitchenowl.dart';
import 'package:kitchenowl/router.dart';
import 'package:kitchenowl/widgets/create_user_form_fields.dart';

class OnboardingPage extends StatefulWidget {
Expand Down Expand Up @@ -44,7 +45,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
),
Padding(
padding: const EdgeInsets.only(top: 16, bottom: 8),
child: ElevatedButton(
child: LoadingElevatedButton(
onPressed: () => _submit(context),
child: Text(AppLocalizations.of(context)!.start),
),
Expand All @@ -67,12 +68,13 @@ class _OnboardingPageState extends State<OnboardingPage> {
);
}

void _submit(BuildContext context) {
Future<void> _submit(BuildContext context) async {
if (_formKey.currentState!.validate()) {
BlocProvider.of<AuthCubit>(context).onboard(
await BlocProvider.of<AuthCubit>(context).onboard(
username: usernameController.text,
name: nameController.text,
password: passwordController.text,
correctCredentialsCallback: () => router.push("/tutorial"),
);
}
}
Expand Down
46 changes: 3 additions & 43 deletions kitchenowl/lib/pages/recipe_page.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
import 'package:kitchenowl/app.dart';
import 'package:kitchenowl/cubits/recipe_cubit.dart';
import 'package:kitchenowl/enums/update_enum.dart';
import 'package:kitchenowl/helpers/recipe_item_markdown_extension.dart';
import 'package:kitchenowl/helpers/share.dart';
import 'package:kitchenowl/helpers/url_launcher.dart';
import 'package:kitchenowl/models/household.dart';
import 'package:kitchenowl/models/item.dart';
import 'package:kitchenowl/models/recipe.dart';
import 'package:kitchenowl/models/shoppinglist.dart';
import 'package:kitchenowl/pages/recipe_add_update_page.dart';
import 'package:kitchenowl/kitchenowl.dart';
import 'package:kitchenowl/widgets/recipe_markdown_body.dart';
import 'package:kitchenowl/widgets/recipe_source_chip.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:kitchenowl/widgets/sliver_with_pinned_footer.dart';
import 'package:markdown/markdown.dart' as md;
import 'package:responsive_builder/responsive_builder.dart';
import 'package:sliver_tools/sliver_tools.dart';
import 'package:tuple/tuple.dart';
Expand Down Expand Up @@ -129,44 +125,8 @@ class _RecipePageState extends State<RecipePage> {
),
if (state.recipe.prepTime + state.recipe.cookTime > 0)
const SizedBox(height: 16),
MarkdownBody(
data: state.recipe.description,
shrinkWrap: true,
styleSheet: MarkdownStyleSheet.fromTheme(
Theme.of(context),
).copyWith(
blockquoteDecoration: BoxDecoration(
color: Theme.of(context).cardTheme.color ??
Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(2.0),
),
),
imageBuilder: (uri, title, alt) => CachedNetworkImage(
imageUrl: uri.toString(),
placeholder: (context, url) =>
const CircularProgressIndicator(),
errorWidget: (context, url, error) =>
const Icon(Icons.error),
),
onTapLink: (text, href, title) {
if (href != null && isValidUrl(href)) {
openUrl(context, href);
}
},
builders: <String, MarkdownElementBuilder>{
'recipeItem': RecipeItemMarkdownBuilder(
cubit: cubit,
),
},
extensionSet: md.ExtensionSet(
md.ExtensionSet.gitHubWeb.blockSyntaxes,
md.ExtensionSet.gitHubWeb.inlineSyntaxes +
[
RecipeItemMarkdownSyntax(
state.recipe,
),
],
),
RecipeMarkdownBody(
recipe: state.recipe,
),
],
),
Expand Down
14 changes: 4 additions & 10 deletions kitchenowl/lib/pages/signup_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,12 @@ class _SignupPageState extends State<SignupPage> {
isValidUrl(privacyPolicyUrl))
Padding(
padding: const EdgeInsets.only(top: 16),
child: MarkdownBody(
child: KitchenOwlMarkdownBody(
data: AppLocalizations.of(context)!
.privacyPolicyAgree(
"[${AppLocalizations.of(context)!.privacyPolicy}]($privacyPolicyUrl)",
),
shrinkWrap: true,
styleSheet: MarkdownStyleSheet.fromTheme(
Theme.of(context),
).copyWith(
styleSheet: MarkdownStyleSheet(
p: Theme.of(context)
.textTheme
.labelSmall
Expand All @@ -148,11 +145,6 @@ class _SignupPageState extends State<SignupPage> {
Theme.of(context).colorScheme.primary,
),
),
onTapLink: (text, href, title) {
if (href != null && isValidUrl(href)) {
openUrl(context, href);
}
},
),
),
Padding(
Expand Down Expand Up @@ -198,6 +190,8 @@ class _SignupPageState extends State<SignupPage> {
Future.delayed(
Duration(milliseconds: 1), () => router.go("/register"));
},
correctCredentialsCallback: () => Future.delayed(
Duration(milliseconds: 1), () => router.push("/tutorial")),
);
}
}
Expand Down
Loading
Loading