Skip to content

Commit

Permalink
refactor: make the score result message account for the selected quer…
Browse files Browse the repository at this point in the history
…y period
  • Loading branch information
crimsonskylark committed Oct 27, 2024
1 parent 291da6f commit 47420d2
Showing 1 changed file with 40 additions and 1 deletion.
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>

0 comments on commit 47420d2

Please sign in to comment.