Skip to content

Commit

Permalink
Merge pull request #96 from pvdthings/dev
Browse files Browse the repository at this point in the history
Release: Librarian Improvements
  • Loading branch information
dillonfagan authored Nov 23, 2024
2 parents 6f47033 + 70a31d3 commit 27d9484
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 200 deletions.
4 changes: 2 additions & 2 deletions apps/librarian/lib/dashboard/pages/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:librarian_app/dashboard/providers/create_loan_controller.dart';
import 'package:librarian_app/dashboard/providers/invalidate_module.dart';
import 'package:librarian_app/dashboard/providers/workspace.dart';
import 'package:librarian_app/dashboard/widgets/end_drawer.dart';
import 'package:librarian_app/modules/authentication/providers/auth_service_provider.dart';
import 'package:librarian_app/modules/authentication/providers/user_tray.dart';
import 'package:librarian_app/modules/members/details/needs_attention_page.dart';
import 'package:librarian_app/dashboard/layouts/members_desktop_layout.dart';
import 'package:librarian_app/modules/members/list/searchable_members_list.dart';
import 'package:librarian_app/dashboard/providers/end_drawer_provider.dart';
import 'package:librarian_app/dashboard/widgets/create_menu_item.dart';
import 'package:librarian_app/dashboard/layouts/inventory_desktop_layout.dart';
import 'package:librarian_app/modules/things/maintenance/view.dart';
Expand Down Expand Up @@ -232,7 +232,7 @@ class _DashboardPageState extends ConsumerState<DashboardPage> {
],
)
: null,
endDrawer: ref.watch(endDrawerProvider).drawer,
endDrawer: const EndDrawer(),
floatingActionButton: mobile ? menuAnchor : null,
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ class EndDrawerController {
EndDrawerController(this.ref);

final Ref ref;
Widget? drawer;
Widget child = const SizedBox.expand();

openEndDrawer(BuildContext context, Widget drawer) {
this.drawer = drawer;
openEndDrawer(BuildContext context, Widget child) {
this.child = child;
ref.notifyListeners();
Future.delayed(const Duration(milliseconds: 500), () {
Future.delayed(const Duration(milliseconds: 750), () {
Scaffold.of(context).openEndDrawer();
});
}
Expand Down
16 changes: 16 additions & 0 deletions apps/librarian/lib/dashboard/widgets/end_drawer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../providers/end_drawer_provider.dart';

class EndDrawer extends ConsumerWidget {
const EndDrawer({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
return Drawer(
width: 500,
child: ref.watch(endDrawerProvider).child,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,88 +26,72 @@ class ConnectedThingSearchField extends StatelessWidget {

@override
Widget build(BuildContext context) {
return TextField(
controller: _textController,
onSubmitted: (_) => _submit(),
decoration: InputDecoration(
hintText: 'Enter Item Number',
prefixIcon: const Icon(Icons.numbers),
suffixIcon: IconButton(
tooltip: 'Add Item',
onPressed: () => _submit(),
icon: const Icon(Icons.add_rounded),
),
),
inputFormatters: [
FilteringTextInputFormatter.digitsOnly,
],
);
return ListenableBuilder(
listenable: controller,
builder: (context, child) {
return TextField(
controller: _textController,
onSubmitted: (_) => _submit(),
decoration: InputDecoration(
errorText: controller.errorText,
hintText: 'Enter Item Number',
prefixIcon: const Icon(Icons.numbers),
suffixIcon: IconButton(
tooltip: 'Add Item',
onPressed: () => _submit(),
icon: const Icon(Icons.add_rounded),
),
),
inputFormatters: [
FilteringTextInputFormatter.digitsOnly,
],
);
});
}
}

class ThingSearchController {
class ThingSearchController extends ChangeNotifier {
final BuildContext context;
final List<ItemModel> items;
final InventoryRepository repository;
final void Function(ItemModel) onMatchFound;

bool isLoading = false;

String? errorText;

ThingSearchController({
required this.context,
required this.items,
required this.repository,
required this.onMatchFound,
});

Future<void> search(String value) async {
final itemNumber = int.parse(value);

if (items.any((t) => t.number == itemNumber)) {
errorText = '#$value is already added to this loan.';
notifyListeners();
return;
}

isLoading = true;
final match = await repository.getItem(number: int.parse(value));
final match = await repository.getItem(number: itemNumber);
isLoading = false;

if (match != null) {
if (!match.available) {
_showThingCheckedOutDialog(match);
} else {
onMatchFound(match);
}
} else {
_showUnknownThingDialog(value);
if (match == null) {
errorText = '#$value could not be found.';
notifyListeners();
return;
}
}

void _showThingCheckedOutDialog(ItemModel thing) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text("Item Unavailable"),
content: Text(
"Item #${thing.number} is checked out or not available for lending."),
actions: [
TextButton(
child: const Text("OK"),
onPressed: () => Navigator.pop(context),
)
],
);
},
);
}
if (!match.available) {
errorText = '#$value is unavailable.';
notifyListeners();
return;
}

void _showUnknownThingDialog(String searchValue) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("Item #$searchValue does not exist."),
content: const Text("Try another number."),
actions: [
TextButton(
child: const Text("OK"),
onPressed: () => Navigator.pop(context),
)
],
);
},
);
onMatchFound(match);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:librarian_app/modules/things/providers/things_repository_provide
import 'package:librarian_app/widgets/item_card.dart';

import 'connected_thing_search_field.dart';
import 'existing_item_dialog.dart';
import 'eye_protection_dialog.dart';
import 'suggested_things_dialog.dart';

Expand All @@ -27,33 +26,24 @@ Step buildItemsStep({
ConnectedThingSearchField(
controller: ThingSearchController(
context: context,
onMatchFound: (thing) {
if (items.any((t) => t.id == thing.id)) {
showDialog(
context: context,
builder: (context) {
return ExistingItemDialog(number: thing.number);
},
);
return;
}

onAddItem(thing);
items: items,
onMatchFound: (item) {
onAddItem(item);

if (thing.eyeProtection && !didPromptForEyeProtection) {
if (item.eyeProtection && !didPromptForEyeProtection) {
showDialog(
context: context,
builder: (_) => const EyeProtectionDialog(),
);
onPromptForEyeProtection();
}

if (thing.linkedThingIds.isNotEmpty) {
if (item.linkedThingIds.isNotEmpty) {
showDialog(
context: context,
builder: (_) => SuggestedThingsDialog(
thingName: thing.name,
thingIds: thing.linkedThingIds,
thingName: item.name,
thingIds: item.linkedThingIds,
),
);
}
Expand Down
Loading

0 comments on commit 27d9484

Please sign in to comment.