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

Updated UI and singleton services #45

Closed
wants to merge 7 commits into from
Closed

Conversation

tbeidlershenk
Copy link
Collaborator

Changes

  1. Updated AuthService by making it singleton and to correctly update Firestore with user documents
  2. Added a new data model AppUser to match a user document in Firestore
  3. Created a singletonFirebaseService where we should put all related Firestore calls
  4. Created a singleton DataService that stores the current lost and found items so we can access from anywhere in the app
  5. Updated the UI to use the google_nav_bar package in a new HomePage class that manages all routes in the app, both existing and to be implemented (chat, profile page) and moved the StreamBuilder listening to this page from MapPage
  6. Updated route.dart and other files as needed
  7. Slightly changed the project folder structure to be more meaningful

Notes

Too many changes bruh please pull and test this Jeff!!!
One note I wasn't able to get it to auto update the map when submitting a post which is weird because I think the StreamBuilder should pick up on this but idrk. It does refresh if you physically refresh the page by navigating away then back.

@tbeidlershenk tbeidlershenk added enhancement Improvements that are not entirely "new features" structural Issues relating to improving project structure and scalability ui labels Dec 26, 2023
@tbeidlershenk tbeidlershenk added this to the MVP App milestone Dec 26, 2023
@jeffzheng13
Copy link
Collaborator

Pull request not being accepted at the moment. There seems to be some functionality issues at the moment. (Testing on dev db)

My observations:

  • Marker design denoting lost and found items not displaying. Displaying a default red map marker icon.
  • Unable to add items after clicking submit even after refreshing
  • Found items not showing on map
  • Logging in does seem to work and create a user.

My suggestion now is, are we able to take one push at time and test? That way we can pinpoint single issues. Right now there's too many things causing errors that I would like to take it one adjustment at a time.

jeffzheng13

This comment was marked as outdated.

@jeffzheng13 jeffzheng13 self-requested a review December 27, 2023 22:46
@jeffzheng13 jeffzheng13 dismissed their stale review December 27, 2023 22:46

Hold up do not merge.

Item item = Item(id: "", userId: AuthService.instance.user!.uid, timeCreated: Timestamp.now(), description: description, itemName: category, location: GeoPoint(lat, long),phone: phone, picture: _imgName);
DocumentReference ref = await FirebaseFirestore.instance.collection('lost').add(item.toFirestore());
item.id = ref.id;
DataService.instance.lostItems.add(item);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a better way to manage lost and found items. We stream from FirebaseFirestore for a reason, it allows us to sync with changes in the backend. There should not be a need to add via locally. We can instead stream the collection and update any info needed to be displayed accordingly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the methods to not add locally. Doesn't update automatically but it does if you refresh

return StreamBuilder<MyUser?>(
stream: authService.user,
builder: (_, AsyncSnapshot<MyUser?> snapshot) {
return StreamBuilder<User?>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got rid of the provider here. Just wondering why, I had provider here so we can access user info anywhere in app.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I have it we still can access it anywhere. We can go back to using the Provider, but it works the same using the singleton instance pattern:
<ServiceClassName>.instance.<whatever you need to access> should work from any file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ followup to this is there an advantage of using Provider class instead? I haven't looked into it at all

/**
* Singleton service for making Firebase calls
*/
class FirebaseService {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong for some reason. Firebase itself is already a class and has methods in it, feels wrong to package it up again? Feel free to correct me if I'm wrong. Also what was with it being in the auth.dart file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly just for the convenience of calling one method to do something. Take createUser as an example. It takes the AppUser datamodel and then performs the database call that creates the firebase mapping. I'm not opposed to moving these method(s) though to the AuthService class instead, that might make more sense - because i just realized that we have a service class calling a service class which is honestly probably not good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your call on what to do about this, let me know, I can refactor it

@tbeidlershenk tbeidlershenk self-assigned this Dec 28, 2023
lastName: lastName,
location: defaultGeopoint);
this.user = user;
await FirebaseService.instance.createUser(user);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is going on with line 41-43?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 42 creates a new user document in Firestore. line 41 appears to be a mistake since this is in the register method not the sign in method. But there's a similar line to 41 in signInWithEmailAndPassword that keeps the AppUser instance of AuthService consistent with the sign in state held in FirebaseAuth. Is there a way we can just get this to automatically update by listening to the FirebaseAuth stream? This would be a better way

Stream<User?> get authUser => FirebaseAuth.instance.authStateChanges();
^ this one in AuthService

@jeffzheng13
Copy link
Collaborator

Appreciate all the work you're putting in @tbeidlershenk👏.

Observations:

  • Clicking on map to create a listing, but then exiting leads to nav bar disappearing
  • Clicking submit twice while on listing, results in there being two entries in db
  • Unable to sign in via a google account (i registered with google and it takes me to log in page but unable to get to map page).
  • Logging out should take you out of app completely, but clicking on back arrow takes you back to the map.

@tbeidlershenk tbeidlershenk linked an issue Dec 28, 2023 that may be closed by this pull request
@jeffzheng13 jeffzheng13 mentioned this pull request Jan 1, 2024
@tbeidlershenk
Copy link
Collaborator Author

Closing as we won't be merging this but will still be referencing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements that are not entirely "new features" structural Issues relating to improving project structure and scalability ui
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Move database calls and StreamBuilders
2 participants