-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from pvdthings/minimize-checkout
Feature: Minimize Checkout
- Loading branch information
Showing
38 changed files
with
471 additions
and
235 deletions.
There are no files selected for viewing
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../lib/modules/loans/models/loan_model.dart → ...arian/lib/core/api/models/loan_model.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
apps/librarian/lib/dashboard/providers/create_loan_controller.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:librarian_app/dashboard/providers/workspace.dart'; | ||
import 'package:librarian_app/dashboard/widgets/workspace_window.dart'; | ||
import 'package:librarian_app/modules/loans/checkout/checkout_page.dart'; | ||
import 'package:librarian_app/modules/loans/checkout/checkout_stepper.dart'; | ||
import 'package:librarian_app/utils/media_query.dart'; | ||
|
||
class CreateLoanController { | ||
CreateLoanController(this.ref); | ||
|
||
final Ref ref; | ||
|
||
void createLoan(BuildContext context) { | ||
if (isMobile(context)) { | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => const CheckoutPage(), | ||
), | ||
); | ||
return; | ||
} | ||
|
||
final ws = ref.read(workspace); | ||
final window = WorkspaceWindow( | ||
title: 'Create Loan', | ||
content: CheckoutStepper( | ||
onFinish: () => ws.closeWindow(), | ||
), | ||
); | ||
|
||
ws.open(window); | ||
} | ||
} | ||
|
||
final createLoan = Provider((ref) => CreateLoanController(ref)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:librarian_app/dashboard/widgets/workspace_window.dart'; | ||
|
||
class WorkspaceController { | ||
WorkspaceController(this.ref); | ||
|
||
final Ref ref; | ||
final List<WorkspaceItem> _items = []; | ||
final Map<String, WorkspaceItem> _minimized = {}; | ||
|
||
bool get hasItem => _items.isNotEmpty; | ||
|
||
ActiveWorkspaceItem? get activeItem { | ||
if (_items.isEmpty) { | ||
return null; | ||
} | ||
|
||
final item = _items.last; | ||
|
||
return ActiveWorkspaceItem( | ||
isMinimized: isMinimized(item.id), | ||
widget: item.widget, | ||
); | ||
} | ||
|
||
List<MapEntry<String, WorkspaceItem>> get minimizedItems { | ||
return _minimized.entries.toList(); | ||
} | ||
|
||
void open(WorkspaceWindow window) { | ||
_items.add(WorkspaceItem( | ||
id: window.id, | ||
title: window.title, | ||
widget: window, | ||
)); | ||
|
||
ref.notifyListeners(); | ||
} | ||
|
||
void closeWindow() { | ||
_items.removeLast(); | ||
ref.notifyListeners(); | ||
} | ||
|
||
void close(String id) { | ||
_items.removeWhere((i) => i.id == id); | ||
_minimized.remove(id); | ||
|
||
ref.notifyListeners(); | ||
} | ||
|
||
void maximize(String id) { | ||
// minimize current active item | ||
final activeItem = _items.last; | ||
_minimized[activeItem.id] = activeItem; | ||
|
||
// make active | ||
final item = _items.firstWhere((i) => i.id == id); | ||
_items.remove(item); | ||
_items.add(item); | ||
|
||
// maximize | ||
_minimized.remove(id); | ||
|
||
ref.notifyListeners(); | ||
} | ||
|
||
void minimize( | ||
String id, { | ||
String? title, | ||
}) { | ||
_minimized[id] = _items.last; | ||
ref.notifyListeners(); | ||
} | ||
|
||
bool isMinimized(String id) { | ||
return _minimized.containsKey(id); | ||
} | ||
} | ||
|
||
class WorkspaceItem { | ||
WorkspaceItem({ | ||
required this.id, | ||
required this.widget, | ||
this.title, | ||
}); | ||
|
||
final String id; | ||
final String? title; | ||
final Widget widget; | ||
} | ||
|
||
class ActiveWorkspaceItem { | ||
const ActiveWorkspaceItem({ | ||
required this.isMinimized, | ||
required this.widget, | ||
}); | ||
|
||
final bool isMinimized; | ||
final Widget widget; | ||
} | ||
|
||
final workspace = Provider((ref) => WorkspaceController(ref)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.