* Update the session with new data from the server * @param {Object} updatedSession - The updated session data from the API * @returns {Object|null} The next card to study
(updatedSession)
| 100 | * @returns {Object|null} The next card to study |
| 101 | */ |
| 102 | updateSession(updatedSession) { |
| 103 | this.session = updatedSession; |
| 104 | this.cardIndex = 0; |
| 105 | |
| 106 | if (this.hasCards()) { |
| 107 | this.currentCard = this.session.cards[0]; |
| 108 | } else { |
| 109 | this.currentCard = null; |
| 110 | } |
| 111 | |
| 112 | if (this.updateCallback) { |
| 113 | this.updateCallback({ |
| 114 | currentCard: this.currentCard, |
| 115 | cardIndex: this.cardIndex, |
| 116 | sessionUpdated: true |
| 117 | }); |
| 118 | } |
| 119 | |
| 120 | return this.currentCard; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Process a card rating and update its state according to SM-2 |