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

Make last saved counter less agressive #1752

Merged
merged 2 commits into from
May 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions evap/student/templates/student_vote.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,18 @@ <h3 class="mb-3">{{ evaluation.full_name }} ({{ evaluation.course.semester.name
const lastSavedLabel = $('#last-saved');
if (localStorage.getItem(lastSavedStorageKey) !== null) {
const lastSavedDate = new Date(localStorage.getItem(lastSavedStorageKey));
const delta = Math.round((timeNow - lastSavedDate) / 1000)
const languageCode = "{{ LANGUAGE_CODE }}"
const relativeTimeFormat = new Intl.RelativeTimeFormat(languageCode)
let timeStamp = "{% trans 'unknown' %}"
const delta = Math.round((timeNow - lastSavedDate) / 1000);
const languageCode = "{{ LANGUAGE_CODE }}";
const relativeTimeFormat = new Intl.RelativeTimeFormat(languageCode);
let timeStamp;
if (delta < 3) {
timeStamp = "{% trans 'just now' %}";
} else if (delta < 10) {
timeStamp = "{% trans 'less than 10 seconds ago' %}";
} else if (delta < 30) {
timeStamp = "{% trans 'less than 30 seconds ago' %}";
} else if (delta < 60) {
timeStamp = relativeTimeFormat.format(-delta, 'seconds');
timeStamp = "{% trans 'less than 1 minute ago' %}";
} else if (delta < 60 * 30) {
timeStamp = relativeTimeFormat.format(-Math.round(delta / 60), 'minutes');
} else if (delta < 60 * 60 * 12) {
Expand All @@ -242,7 +246,7 @@ <h3 class="mb-3">{{ evaluation.full_name }} ({{ evaluation.course.semester.name
sisyphus.saveAllData();

// Initialize lastSavedLabel and update it every second
updateLastSavedLabel()
updateLastSavedLabel();
setInterval(updateLastSavedLabel, 1000);

initTextAnswerWarnings(document.querySelectorAll("#student-vote-form textarea"), JSON.parse($("#text-answer-warnings").text()));
Expand Down