StanfordSpezi / SpeziScheduler

Scheduler Module for the Stanford Spezi Ecosystem
https://swiftpackageindex.com/StanfordSpezi/SpeziScheduler/documentation/
MIT License
3 stars 3 forks source link

[Bug] Event's (e.g questionnaire's) completion status does not persist after cold app restart #2

Closed Lucas-ZX-W closed 1 year ago

Lucas-ZX-W commented 1 year ago

Description

The completion status of events (e.g questionnaires) are not stored persistently, allowing the user to cold-restart the app to break the Schedule of events.

Demo video (on Lucas's public Google Drive.)

Reproduction

  1. Set up the CardinalKit with a use profile fully onboarded.
  2. Complete a questionnaire, the questionnaire is marked as complete, and canto
  3. Exit the app (without force quitting) and reenter, the survey will
  4. Manually force quit the app or indirectly (e.g opening lots of other apps to push CardinalKitTemplateApp out of memory).
  5. Upon cold-opening the app, the questionnaire will be marked as available again.

Expected behavior

On step 5., the questionnaire that we just completed should remain "completed" and unavailable to be filled out again until its next Scheduled time as defined by its Schedule.

Additional context

Would CardinalKit/Sources/Scheduler/Event.swift adding persistent storage for Event objects be a viable approach for a fix?

    public func complete(_ newValue: Bool) async {
        await lock.enter {
            if newValue {
                completedAt = Date()
                eventContext?.completedEvents[_scheduledAt] = self
            } else {
                eventContext?.completedEvents[_scheduledAt] = nil
                completedAt = nil
            }
        }
    }

Code of Conduct

PSchmiedmayer commented 1 year ago

Hi @Lucas-ZX-W, thank you for informing us about the issue. This is indeed a problem that we have not fully implemented yet. We will take a closer look at this and will get back to you. The code that is related to this feature has moved into a separate repo and we will track the issue there: https://github.com/StanfordBDHG/CardinalKitScheduler.

PSchmiedmayer commented 1 year ago

@Lucas-ZX-W We resolved this issue with #7 🚀 Let us know if you can verify the new behaviour with the version 0.3.1 of the Spezi Scheduler module.