Added docs for the task bloc
This commit is contained in:
parent
12ea8fec33
commit
cd214e888e
2 changed files with 34 additions and 4 deletions
|
|
@ -26,7 +26,7 @@ class NewImageBloc {
|
|||
/// A subject of the current user model.
|
||||
final _user = BehaviorSubject<UserModel>();
|
||||
|
||||
/// A subject of the current task event name.
|
||||
/// A subject of the current media event name.
|
||||
final _eventName = BehaviorSubject<String>();
|
||||
|
||||
NewImageBloc() {
|
||||
|
|
@ -40,10 +40,10 @@ class NewImageBloc {
|
|||
/// An observable of the user model.
|
||||
Observable<UserModel> get userModelStream => _user.stream;
|
||||
|
||||
/// An observable of the task event name.
|
||||
/// An observable of the media event name.
|
||||
Observable<String> get eventName => _eventName.stream;
|
||||
|
||||
/// An observable of the ready to submit flag.
|
||||
/// An observable of the submit enabled flag.
|
||||
Observable<bool> get submitEnabled =>
|
||||
Observable.combineLatest2(_picture, _eventName, (a, b) => true);
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ class NewImageBloc {
|
|||
/// Changes the current picture file.
|
||||
Function(File) get changePicture => _picture.sink.add;
|
||||
|
||||
/// Changes the current task event name.
|
||||
/// Changes the current media event name.
|
||||
Function(String) get changeEventName => _eventName.sink.add;
|
||||
|
||||
/// Fetches and updates the current user.
|
||||
|
|
|
|||
|
|
@ -9,39 +9,66 @@ import '../resources/firestore_provider.dart';
|
|||
import '../services/auth_service.dart';
|
||||
import '../services/current_task_service.dart';
|
||||
|
||||
/// Business logic component that manages the state for the task screen.
|
||||
class TaskBloc extends Object with Validators {
|
||||
/// An instance of the auth service.
|
||||
final AuthService _auth = authService;
|
||||
|
||||
/// An instance of the firebase repository.
|
||||
final FirestoreProvider _firestore = firestoreProvider;
|
||||
|
||||
/// An instance of the current task service.
|
||||
final CurrentTaskService _taskService = currentTaskService;
|
||||
|
||||
/// A subject of user model.
|
||||
final _user = BehaviorSubject<UserModel>();
|
||||
|
||||
/// A subject of task event name.
|
||||
final _eventName = BehaviorSubject<String>();
|
||||
|
||||
/// A subject of task text.
|
||||
final _taskText = BehaviorSubject<String>();
|
||||
|
||||
/// The priority of the current task.
|
||||
TaskPriority priority = TaskPriority.high;
|
||||
|
||||
/// The text of the current global task.
|
||||
String get textInitialValue => _taskService.task.text;
|
||||
|
||||
//Stream getters.
|
||||
/// An observable of the current user model.
|
||||
Observable<UserModel> get userModelStream => _user.stream;
|
||||
|
||||
/// An observable of the current task event name.
|
||||
Observable<String> get eventName => _eventName.stream;
|
||||
|
||||
/// An observable of the current task text.
|
||||
Observable<String> get taskText =>
|
||||
_taskText.stream.transform(validateStringNotEmpty);
|
||||
|
||||
/// An observable of the submit enabled flag.
|
||||
Observable<bool> get submitEnabled =>
|
||||
Observable.combineLatest2(eventName, taskText, (a, b) => true);
|
||||
|
||||
//Sinks getters.
|
||||
/// Changes the current task event name.
|
||||
Function(String) get changeEventName => _eventName.sink.add;
|
||||
|
||||
///Changes the current task text.
|
||||
Function(String) get changeTaskText => _taskText.sink.add;
|
||||
|
||||
TaskBloc() {
|
||||
setCurrentUser();
|
||||
}
|
||||
|
||||
/// Changes the current task priority.
|
||||
void setPriority(TaskPriority newPriority) {
|
||||
priority = newPriority;
|
||||
}
|
||||
|
||||
//TODO: Figure out how to update the event and user properties if needed.
|
||||
|
||||
/// Saves or updates the current task in the database.
|
||||
Future<void> submit(isEdit) {
|
||||
if (isEdit) {
|
||||
return _firestore.updateTask(
|
||||
|
|
@ -60,12 +87,15 @@ class TaskBloc extends Object with Validators {
|
|||
return _firestore.addTask(newTask);
|
||||
}
|
||||
|
||||
/// Fetches and updates the current user.
|
||||
Future<void> setCurrentUser() async {
|
||||
final user = await _auth.currentUser;
|
||||
final userModel = await _firestore.getUser(username: user.email);
|
||||
_user.add(userModel);
|
||||
}
|
||||
|
||||
/// Grabs the data from the current global task and pipes it to the local
|
||||
/// streams.
|
||||
void populateWithCurrentTask() {
|
||||
TaskModel currentTask = _taskService.task;
|
||||
if (currentTask != null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue