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

Feature/improve notes #42

Merged
merged 3 commits into from
Nov 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AddExpenseDialogCubit extends Cubit<AddExpenseDialogState> {
final Category category;
final LastExpenseCubit lastExpenseCubit;
final noteController = TextEditingController();
final suggestionController = ScrollController();

AddExpenseDialogCubit(super.initialState,
{required this.category, required this.lastExpenseCubit}) {
Expand All @@ -33,6 +34,7 @@ class AddExpenseDialogCubit extends Cubit<AddExpenseDialogState> {
@override
close() async {
noteController.dispose();
suggestionController.dispose();
super.close();
}

Expand Down Expand Up @@ -223,6 +225,8 @@ class AddExpenseDialogCubit extends Cubit<AddExpenseDialogState> {

setNote(String note) {
emit(state.copyWith(expenseNote: note));
suggestionController.animateTo(0,
duration: animationDuration, curve: animationCurve);
}

enableCurrencyConversion(bool enable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class ExpenseActions extends StatelessWidget {
padding: const EdgeInsets.all(8.0),
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
controller: cubit.suggestionController,
scrollDirection: Axis.horizontal,
child: Row(
children: [
Expand Down
8 changes: 5 additions & 3 deletions src/main/app/lib/categories/state/categories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class CategoriesCubit extends Cubit<CategoriesState> {
}

getCategories() async {
emit(state.copyWith(loading: true));
final categories = await service.getCategories();
emit(state.copyWith(categories: categories));
emit(state.copyWith(categories: categories, loading: false));
}

void addCategory(String selected) async {
Expand All @@ -28,6 +29,7 @@ class CategoriesCubit extends Cubit<CategoriesState> {

@freezed
class CategoriesState with _$CategoriesState {
const factory CategoriesState({@Default([]) List<Category> categories}) =
_CategoriesState;
const factory CategoriesState(
{@Default(true) bool loading,
@Default([]) List<Category> categories}) = _CategoriesState;
}
33 changes: 26 additions & 7 deletions src/main/app/lib/categories/state/categories.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final _privateConstructorUsedError = UnsupportedError(

/// @nodoc
mixin _$CategoriesState {
bool get loading => throw _privateConstructorUsedError;
List<Category> get categories => throw _privateConstructorUsedError;

/// Create a copy of CategoriesState
Expand All @@ -31,7 +32,7 @@ abstract class $CategoriesStateCopyWith<$Res> {
CategoriesState value, $Res Function(CategoriesState) then) =
_$CategoriesStateCopyWithImpl<$Res, CategoriesState>;
@useResult
$Res call({List<Category> categories});
$Res call({bool loading, List<Category> categories});
}

/// @nodoc
Expand All @@ -49,9 +50,14 @@ class _$CategoriesStateCopyWithImpl<$Res, $Val extends CategoriesState>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? loading = null,
Object? categories = null,
}) {
return _then(_value.copyWith(
loading: null == loading
? _value.loading
: loading // ignore: cast_nullable_to_non_nullable
as bool,
categories: null == categories
? _value.categories
: categories // ignore: cast_nullable_to_non_nullable
Expand All @@ -68,7 +74,7 @@ abstract class _$$CategoriesStateImplCopyWith<$Res>
__$$CategoriesStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({List<Category> categories});
$Res call({bool loading, List<Category> categories});
}

/// @nodoc
Expand All @@ -84,9 +90,14 @@ class __$$CategoriesStateImplCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? loading = null,
Object? categories = null,
}) {
return _then(_$CategoriesStateImpl(
loading: null == loading
? _value.loading
: loading // ignore: cast_nullable_to_non_nullable
as bool,
categories: null == categories
? _value._categories
: categories // ignore: cast_nullable_to_non_nullable
Expand All @@ -98,9 +109,13 @@ class __$$CategoriesStateImplCopyWithImpl<$Res>
/// @nodoc

class _$CategoriesStateImpl implements _CategoriesState {
const _$CategoriesStateImpl({final List<Category> categories = const []})
const _$CategoriesStateImpl(
{this.loading = true, final List<Category> categories = const []})
: _categories = categories;

@override
@JsonKey()
final bool loading;
final List<Category> _categories;
@override
@JsonKey()
Expand All @@ -112,21 +127,22 @@ class _$CategoriesStateImpl implements _CategoriesState {

@override
String toString() {
return 'CategoriesState(categories: $categories)';
return 'CategoriesState(loading: $loading, categories: $categories)';
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CategoriesStateImpl &&
(identical(other.loading, loading) || other.loading == loading) &&
const DeepCollectionEquality()
.equals(other._categories, _categories));
}

@override
int get hashCode => Object.hash(
runtimeType, const DeepCollectionEquality().hash(_categories));
runtimeType, loading, const DeepCollectionEquality().hash(_categories));

/// Create a copy of CategoriesState
/// with the given fields replaced by the non-null parameter values.
Expand All @@ -139,9 +155,12 @@ class _$CategoriesStateImpl implements _CategoriesState {
}

abstract class _CategoriesState implements CategoriesState {
const factory _CategoriesState({final List<Category> categories}) =
_$CategoriesStateImpl;
const factory _CategoriesState(
{final bool loading,
final List<Category> categories}) = _$CategoriesStateImpl;

@override
bool get loading;
@override
List<Category> get categories;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CategoryListTab extends StatelessWidget {
builder: (context, state) {
return AnimatedSwitcher(
duration: panelTransition,
child: state.categories.isEmpty
child: state.loading
? const DummyGrid()
: CategoryGrid(state.categories));
});
Expand Down
2 changes: 2 additions & 0 deletions src/main/app/lib/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const MIN_BACKEND_VERSION = 67;
const BorderRadius defaultBorder = BorderRadius.all(Radius.circular(15));
const defaultPadding = 20.0;
const panelTransition = Duration(milliseconds: 350);
const animationDuration = Duration(milliseconds: 250);
const animationCurve = Curves.easeInOutQuad;

// broadcast message types
const BROADCAST_LOGGED_IN = 'loggedIn',
Expand Down
121 changes: 51 additions & 70 deletions src/main/app/lib/login/views/components/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ class Login extends StatelessWidget {
bool tablet = isTablet(mq);

double width = mq.size.width;
double height = mq.size.height;

if (tablet) {
width = 500;
height = 600;
}

return BlocProvider(
Expand All @@ -49,72 +47,12 @@ class Login extends StatelessWidget {
child: BlocBuilder<LoginCubit, LoginState>(builder: (context, state) {
final cubit = context.read<LoginCubit>();

return Stack(
children: [
Column(
children: [
Expanded(
child: Container(
alignment: Alignment.center,
child: AnimatedContainer(
width: width,
height: height,
duration: panelTransition,
curve: Curves.easeInOutQuart,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(tablet ? 20 : 0)),
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(bottom: bottom),
child: AnimatedSwitcher(
duration: panelTransition,
child: state.page == LoginPage.signUp
? SignUp(
key: ValueKey(state.page),
onBack: () => cubit.signUp(false),
server: cubit.urlController.text.trim())
: state.page == LoginPage.resetPassword
? ResetPassword(
onBack: () =>
cubit.resetPassword(false),
server:
cubit.urlController.text.trim(),
key: ValueKey(state.page))
: LoginForm(
error: state.loginError,
key: const ValueKey(false),
urlController: cubit.urlController,
config: state.config,
logIn: (username, password) async {
final loggedIn = await cubit.logIn(
username, password);
if (loggedIn && context.mounted) {
AutoRouter.of(context).replaceAll(
[const HomeRoute()]);
}
},
showSignUp: () => cubit.signUp(true),
showResetPassword: () =>
cubit.resetPassword(true)),
),
),
),
),
),
),
],
),
AnimatedPositioned(
top: state.config == null ||
(state.config?.announcement.trim().length ?? 0) == 0
? -200
: 0,
left: 0,
right: 0,
curve: Curves.easeInOutQuart,
duration: panelTransition,
child: Container(
return SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if ((state.config?.announcement.trim().length ?? 0) > 0)
Container(
color: colors.tertiaryContainer,
child: Padding(
padding: const EdgeInsets.all(20.0),
Expand All @@ -123,8 +61,51 @@ class Login extends StatelessWidget {
style: TextStyle(color: colors.onTertiaryContainer),
),
),
)),
],
),
Container(
alignment: Alignment.center,
child: AnimatedContainer(
width: width,
duration: panelTransition,
curve: Curves.easeInOutQuart,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(tablet ? 20 : 0)),
child: Padding(
padding: EdgeInsets.only(bottom: bottom),
child: AnimatedSwitcher(
duration: panelTransition,
child: state.page == LoginPage.signUp
? SignUp(
key: ValueKey(state.page),
onBack: () => cubit.signUp(false),
server: cubit.urlController.text.trim())
: state.page == LoginPage.resetPassword
? ResetPassword(
onBack: () => cubit.resetPassword(false),
server: cubit.urlController.text.trim(),
key: ValueKey(state.page))
: LoginForm(
error: state.loginError,
key: const ValueKey(false),
urlController: cubit.urlController,
config: state.config,
logIn: (username, password) async {
final loggedIn =
await cubit.logIn(username, password);
if (loggedIn && context.mounted) {
AutoRouter.of(context)
.replaceAll([const HomeRoute()]);
}
},
showSignUp: () => cubit.signUp(true),
showResetPassword: () =>
cubit.resetPassword(true)),
),
),
),
),
],
),
);
}),
),
Expand Down
2 changes: 1 addition & 1 deletion src/main/app/lib/login/views/components/loginForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class LoginFormState extends State<LoginForm> with AfterLayoutMixin<LoginForm> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(50.0),
padding: const EdgeInsets.symmetric(horizontal: 50.0),
child: Container(
decoration: const BoxDecoration(
borderRadius: defaultBorder,
Expand Down
14 changes: 14 additions & 0 deletions src/main/app/lib/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const EXPENSE_BY_MONTH = '$API_URL/Expense/ByDay?month={0}';
const EXPENSE_GET_MONTHS = '$API_URL/Expense/GetMonths';
const EXPENSE_DELETE = '$API_URL/Expense/{0}';
const EXPENSE_GET_NOTE_SUGGESTIONS = '$API_URL/Expense/suggest-notes';
const EXPENSE_GET_NOTE_AUTOCOMPLETE = '$API_URL/Expense/notes-autocomplete';
const EXPENSE_GET_LIMITS = '$API_URL/Expense/limits';
const HISTORY_OVERALL_MONTH = "$API_URL/History/CurrentMonth";
const HISTORY_OVERALL_YEAR = "$API_URL/History/CurrentYear";
Expand Down Expand Up @@ -241,6 +242,19 @@ class Service {
});
}

Future<Map<String, int>> getNoteAutoComplete(String seed) async {
final response = await http.post(
await formatUrl(EXPENSE_GET_NOTE_AUTOCOMPLETE),
body: jsonEncode(seed),
headers: headers);

processResponse(response);
Map<String, dynamic> result = jsonDecode(response.body);
return result.map((key, value) {
return MapEntry(key, value as int);
});
}

Future<List<Category>> getCategories() async {
final response =
await http.get(await formatUrl(CATEGORY_ALL), headers: headers);
Expand Down
2 changes: 1 addition & 1 deletion src/main/app/lib/utils/dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void showAlertDialog(BuildContext context, String title, String text) {

void showPromptDialog(BuildContext context, String title, String label,
TextEditingController controller, Function onOk,
{int? maxLines}) {
{int? maxLines, String Function(String seed)? getAutoComplete}) {
final colors = Theme.of(context).colorScheme;
showDialog(
context: context,
Expand Down
4 changes: 4 additions & 0 deletions src/main/app/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ pkgs.mkShell {

echo "creating useful aliases..."


flutter config --jdk-dir ${pkgs.corretto17}/lib/corretto

echo -e "\nAll done 🎉 \nAvailable aliases:"

''+
pkgs.lib.concatStrings (map (x: ''echo "${x.name}: ${x.description}";'') aliases);

Expand Down
Loading