Skip to content

Commit 7502eb0

Browse files
feat: request avg reading time when submitting a book summary
1 parent 950e9b2 commit 7502eb0

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/main/resources/static/dashboard.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,20 +539,37 @@ <h5 class="card-title">${escapeHtml(book.title)}</h5>
539539
const lastPage = $('#finishLastPage').val();
540540
const summaryText = $('#finishSummary').val();
541541
if (!lastPage || !summaryText) { notifyWarning('Please fill last page and summary.'); return; }
542+
542543
const lines = summaryText.split(/\r?\n/).length;
543544
let exp = Math.min(lines * 2, 30);
545+
// Calculate reading time in minutes (readingSeconds is global)
546+
const readingMinutes = Math.ceil(readingSeconds / 60);
547+
544548
try {
549+
// 1. Submit summary
545550
await apiCall('POST', '/api/summaries', { text: summaryText, bookId: parseInt(bookId), studentId: userId });
551+
552+
// 2. Update current book and last page
546553
await apiCall('POST', '/api/stats/set-current-book', { userId, bookId: parseInt(bookId), page: parseInt(lastPage) });
554+
555+
// 3. Add experience points
547556
await apiCall('POST', `/api/stats/${userId}/add-exp`, { exp });
548-
notifySuccess(`Session finished! You earned ${exp} XP.`);
557+
558+
// 4. Update average reading time (statsId = userId)
559+
await apiCall('POST', `/api/stats/${userId}/average-reading-time`, { readingTimeInMins: readingMinutes });
560+
561+
notifySuccess(`Session finished! You earned ${exp} XP. Average reading time updated.`);
562+
563+
// Clean up timer and UI
549564
if (readingTimerInterval) clearInterval(readingTimerInterval);
550565
readingActive = false;
551566
readingSeconds = 0;
552567
currentReadingBookId = null;
553568
$('#finishReadingModal').modal('hide');
554569
$('#bookDetailModal').modal('hide');
555-
} catch(e) { notifyError('Error finishing session: ' + e.message); }
570+
} catch(e) {
571+
notifyError('Error finishing session: ' + e.message);
572+
}
556573
}
557574

558575
// Groups tab - with add book button per group

0 commit comments

Comments
 (0)