patchthecode / JTAppleCalendar

The Unofficial Apple iOS Swift Calendar View. Swift calendar Library. iOS calendar Control. 100% Customizable
https://patchthecode.com
MIT License
7.55k stars 806 forks source link

Calendar displaying same value every day #1403

Open SosaFrancys opened 2 weeks ago

SosaFrancys commented 2 weeks ago

(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 commented 2 weeks ago

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

SosaFrancys commented 2 weeks ago

no I'm still on 7

patchthecode commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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