From 1b36947982d99748eee5f16f124193349e74b647 Mon Sep 17 00:00:00 2001 From: Scott Clampet Date: Tue, 30 Apr 2019 09:53:10 -0600 Subject: [PATCH] fix(homepage, addusertojar): refactor add user to jar and make sure home page updates for each user re #105 --- fude_app/lib/pages/jars/jar_add.dart | 1 + fude_app/lib/pages/jars/jar_edit.dart | 137 +++++++++++++----------- fude_app/lib/scoped-models/jar.dart | 6 +- fude_app/lib/widgets/forms/add_jar.dart | 7 +- 4 files changed, 81 insertions(+), 70 deletions(-) diff --git a/fude_app/lib/pages/jars/jar_add.dart b/fude_app/lib/pages/jars/jar_add.dart index 34dbb0a..b3dfc17 100644 --- a/fude_app/lib/pages/jars/jar_add.dart +++ b/fude_app/lib/pages/jars/jar_add.dart @@ -106,6 +106,7 @@ class _JarPageState extends State { updateImage: updateImage, updateCategoryCount: updateCategoryCount, categoryCount: categoryCount, + categories: _formData['categories'], ), SizedBox(height: height * 0.035), Row( diff --git a/fude_app/lib/pages/jars/jar_edit.dart b/fude_app/lib/pages/jars/jar_edit.dart index b60a33e..619c6cf 100644 --- a/fude_app/lib/pages/jars/jar_edit.dart +++ b/fude_app/lib/pages/jars/jar_edit.dart @@ -49,6 +49,7 @@ class _JarPageState extends State { } else { formKey.currentState.save(); model.updateJar(_formData); + model.fetchAllUserJars(model.currUserEmail); Navigator.pop(context); } } @@ -171,76 +172,82 @@ class _JarPageState extends State { decoration: BoxDecoration( color: Theme.of(context).primaryColor, ), - child: !loadingJarData ? ListView( - shrinkWrap: true, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - SizedBox(height: height * 0.04), - EditJarForm( - formKey: formKey, - model: model, - jar: model.selectedJar, - addCategoryToRemoveList: addCategoryToRemoveList, - categories: currentCategories, - needsAtLeastOneCategory: needsAtLeastOneCategory, - updateCategory: updateCategory, - updateTitle: updateTitle, - updateImage: updateImage, - updateCategoryCount: updateCategoryCount, - categoryCount: categoryCount, - ), - AddUserToJarForm( - addUserFormKey: addUserFormKey, - addUserToJar: addUserToJar, - submitAddUser: submitAddUser, - userHasBeenAdded: userHasBeenAdded, - needToInviteThisUser: needToInviteThisUser, - model: model), - SizedBox(height: height * 0.04), - Container( - padding: - EdgeInsets.fromLTRB(width * 0.045, 0, width * 0.045, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + child: !loadingJarData + ? ListView( + shrinkWrap: true, + children: [ + Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ - RaisedButton( - child: Text( - 'UPDATE JAR', - style: TextStyle( - color: Theme.of(context).primaryColor, - fontWeight: FontWeight.bold, - fontSize: 15, - letterSpacing: 5, - ), - ), - elevation: 7, - highlightElevation: 1, - padding: EdgeInsets.all(15), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.0)), - color: Theme.of(context).secondaryHeaderColor, - splashColor: Colors.transparent, - highlightColor: Theme.of(context).primaryColor, - onPressed: () => updateJar(model), + SizedBox(height: height * 0.04), + EditJarForm( + formKey: formKey, + model: model, + jar: model.selectedJar, + addCategoryToRemoveList: addCategoryToRemoveList, + categories: currentCategories, + needsAtLeastOneCategory: needsAtLeastOneCategory, + updateCategory: updateCategory, + updateTitle: updateTitle, + updateImage: updateImage, + updateCategoryCount: updateCategoryCount, + categoryCount: categoryCount, ), - IconButton( - icon: Icon(Icons.delete), - iconSize: 36, - color: Colors.red, - onPressed: () { - model.deleteJar(); - Navigator.pop(context); - }) + AddUserToJarForm( + addUserFormKey: addUserFormKey, + addUserToJar: addUserToJar, + submitAddUser: submitAddUser, + userHasBeenAdded: userHasBeenAdded, + needToInviteThisUser: needToInviteThisUser, + model: model), + SizedBox(height: height * 0.04), + Container( + padding: EdgeInsets.fromLTRB( + width * 0.045, 0, width * 0.045, 0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + RaisedButton( + child: Text( + 'UPDATE JAR', + style: TextStyle( + color: Theme.of(context).primaryColor, + fontWeight: FontWeight.bold, + fontSize: 15, + letterSpacing: 5, + ), + ), + elevation: 7, + highlightElevation: 1, + padding: EdgeInsets.all(15), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10.0)), + color: Theme.of(context).secondaryHeaderColor, + splashColor: Colors.transparent, + highlightColor: Theme.of(context).primaryColor, + onPressed: () => updateJar(model), + ), + IconButton( + icon: Icon(Icons.delete), + iconSize: 36, + color: Colors.red, + onPressed: () { + model.deleteJar(); + model.fetchAllUserJars(model.currUserEmail); + + Navigator.pop(context); + }) + ], + ), + ) ], ), - ) - ], - ), - ], - ) : Center(child: CircularProgressIndicator(),), + ], + ) + : Center( + child: CircularProgressIndicator(), + ), ), ); }); diff --git a/fude_app/lib/scoped-models/jar.dart b/fude_app/lib/scoped-models/jar.dart index 494ba99..5e1aac4 100644 --- a/fude_app/lib/scoped-models/jar.dart +++ b/fude_app/lib/scoped-models/jar.dart @@ -256,10 +256,8 @@ mixin JarModel on Model { await _firestore .collection('jars') .document(_selJar.documentID) - .updateData({ - !_selJar.data['owners'].contains(email) - ? 'owners' - : FieldValue.arrayUnion([email]): FieldValue.arrayUnion([]) + .updateData({'owners' : + !_selJar.data['owners'].contains(email) ? FieldValue.arrayUnion([email]): FieldValue.arrayUnion([]) }); } catch (e) { print(e); diff --git a/fude_app/lib/widgets/forms/add_jar.dart b/fude_app/lib/widgets/forms/add_jar.dart index 54efc01..29e6017 100644 --- a/fude_app/lib/widgets/forms/add_jar.dart +++ b/fude_app/lib/widgets/forms/add_jar.dart @@ -13,6 +13,7 @@ class AddJarForm extends StatelessWidget { final Function updateImage; final Function updateCategoryCount; final DocumentSnapshot jar; + final List categories; AddJarForm( {this.formKey, @@ -21,7 +22,8 @@ class AddJarForm extends StatelessWidget { this.updateTitle, this.updateCategory, this.updateImage, - this.updateCategoryCount}); + this.updateCategoryCount, + this.categories}); Widget _buildFormTitles(String title, BuildContext context) { return Row( @@ -62,6 +64,8 @@ class AddJarForm extends StatelessWidget { hint: 'Add Category', updateCategory: updateCategory, enabled: true, + categories: categories, + ), ], ), @@ -99,6 +103,7 @@ class AddJarForm extends StatelessWidget { hint: 'Add Category', updateCategory: updateCategory, enabled: true, + categories: categories, ), categoryCount > 0 ? _addCategoryInputs(context) : Container(), SizedBox(height: height * 0.035),