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

Calendar displaying same value every day #1403

Open
SosaFrancys opened this issue Sep 1, 2024 · 5 comments
Open

Calendar displaying same value every day #1403

SosaFrancys opened this issue Sep 1, 2024 · 5 comments

Comments

@SosaFrancys
Copy link

(Required) Version Number:
7.1

Description

I'm trying to update my calendar to get the data needed from Firestore instead of CoreData which is working fine but when I try to display the data from Firestore the whole calendar gets the same value

Steps To Reproduce

Function in my User Struct
` static func getUserHoursFromFirestore(date: Date, from snapshot: DocumentSnapshot, forField field: String, completion: @escaping (Double?) -> Void) {

    let dayFormatter = DateFormatter()
    dayFormatter.dateFormat = "MM-dd-yyyy hh:mm a"
    let documentID = dayFormatter.string(from: date)
    
    let db = Firestore.firestore()
    let user = Auth.auth().currentUser
    guard let userEmail = user?.email else {
        print("++ User is not logged in")
        completion(nil)
        return
    }
    
    let userCollection = db.collection("users").document(userEmail)
    let hourCollection = userCollection.collection("hours").document("Nov 25 2024 05:00 PM")
    
    hourCollection.getDocument { document, error in
        if let error = error {
            print("++ Error fetching document: \(error.localizedDescription)")
            completion(nil)
            return
        }
        guard let document = document, document.exists else {
            print("++ Document does not exist")
            completion(nil)
            return
        }
        
        if let hours = document.get(field) as? Double {
            print("++ Retrieved hours: \(hours)")
            completion(hours)
        } else {
            print("++ Field does not exist or is not a Double")
            completion(nil)
        }
    }
}       `

my handleFirestoreHours on cellForItemAt

`func handleFirestoreHours(cell: CalendarCell, cellState: CellState) {
let db = Firestore.firestore()
let user = Auth.auth().currentUser
let userCollection = db.collection("users").document((user?.email)!)
let hourCollection = userCollection.collection("hours").document("Nov 25 2024 05:00 PM")

    hourCollection.getDocument { snapshot, error in
        
        if let error = error {
            print(error.localizedDescription)
        }else if let snapshot = snapshot {

            User.getUserHoursFromFirestore(date: cellState.date, from: snapshot, forField: "totalHours") { hours in

                print("** THE Number OF hours in handle is : \(String(describing: hours!))")
                if hours == 0.0 {
                cell.hoursLabel.isHidden  = true
            }else{
                cell.hoursLabel.text = "\(hours!)Hrs."
                cell.hoursLabel.isHidden = false
            }
        }
        
    }
    }   
    } `

Expected Behavior

the calendar should be displaying only the hours for Nov 25, 2024, for testing purposes then the documentID will be used

Additional Context

Since the app is working fine using core data at version 7.1 I haven't tried updating to version 8.0.5
I'm fairly new to swift and I hope you can help me solve this issue, thanks in advance.

@patchthecode
Copy link
Owner

wait.. just to be clear, you're updating from version 7 to 8?

@SosaFrancys
Copy link
Author

no I'm still on 7

@patchthecode
Copy link
Owner

Have you tried migrating to version 8? since it was introduced 6 years ago 😬 ...
in any case, please provide a minimal calendar zip file which reproduces this issue.

im sure its a tiny mistake youre making somewhere

@SosaFrancys
Copy link
Author

yeah, I need to do that lol
Calendar.zip
, I like your calendar that's the reason I started this project and it's been good so far. I just thought of adding Firebase to it as a back end instead of core data, in the zip you'll see that I used a predicate to get the hours from core data for that day and maybe that's the case for firestore but I've done that with no luck, the firestore is structure as follow main "users" collection, with user emails as the documents id then a collection of "hours" with document id as the "time out" time stamp converted to string, hope you can help me or guide me in the right direction, thanks in advance..

@SosaFrancys
Copy link
Author

all set, I figured out thanks, I'll try and migrate to version 8 later on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants