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

refactor: make the score result message account for the selected query period #617

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
41 changes: 40 additions & 1 deletion src/visualizations/Score.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang="pug">
div
div(style="text-align: center")
| Your total score today is:
| Your total score {{selected_timeperiod}} is:
div(:style="'font-size: 2em; color: ' + (score >= 0 ? '#0A0' : '#F00')")
| {{score >= 0 ? '+' : ''}}{{ (Math.round(score * 10) / 10).toFixed(1) }}
div.small.text-muted
Expand Down Expand Up @@ -76,6 +76,45 @@ export default {
c => c.data.$total_score
);
},
selected_timeperiod: function () {
const [duration, span] = useActivityStore().query_options.timeperiod.length;
let relative_period = "";

// Default case, keep the existing behaviour
if (span.startsWith("day")) {
if (duration > 1) {
relative_period = `${duration} days`;
} else {
return "today";
}
}

if (span.startsWith("week")) {
if (duration > 1) {
relative_period = `${duration} weeks`;
} else {
return "this week";
}
}

if (span.startsWith("month")) {
if (duration > 1) {
relative_period = `${duration} months`;
} else {
return "this month";
}
}

if (span.startsWith("year")) {
if (duration > 1) {
relative_period = `${duration} years`;
} else {
return "this year";
}
}

return `in the past ${relative_period}`
},
},
};
</script>