Merge pull request #24970 from nina-py/24938-dashboard-greetings-show-good-morning-after-noon

Fix dashboard greetings that show 'good morning' after noon
This commit is contained in:
Julien Veyssier 2021-01-05 18:58:21 +01:00 committed by GitHub
commit ef0732384f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 11 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -163,18 +163,43 @@ export default {
}, },
greeting() { greeting() {
const time = this.timer.getHours() const time = this.timer.getHours()
const shouldShowName = this.displayName && this.uid !== this.displayName
if (time > 18) { // Determine part of the day
return { text: shouldShowName ? t('dashboard', 'Good evening, {name}', { name: this.displayName }) : t('dashboard', 'Good evening') } let partOfDay
if (time >= 22 && time < 5) {
partOfDay = 'night'
} else if (time >= 18) {
partOfDay = 'evening'
} else if (time >= 12) {
partOfDay = 'afternoon'
} else {
partOfDay = 'morning'
} }
if (time > 12) {
return { text: shouldShowName ? t('dashboard', 'Good afternoon, {name}', { name: this.displayName }) : t('dashboard', 'Good afternoon') } // Define the greetings
const good = {
morning: {
generic: t('dashboard', 'Good morning'),
withName: t('dashboard', 'Good morning, {name}', { name: this.displayName }),
},
afternoon: {
generic: t('dashboard', 'Good afternoon'),
withName: t('dashboard', 'Good afternoon, {name}', { name: this.displayName }),
},
evening: {
generic: t('dashboard', 'Good evening'),
withName: t('dashboard', 'Good evening, {name}', { name: this.displayName }),
},
night: {
// Don't use "Good night" as it's not a greeting
generic: t('dashboard', 'Hello'),
withName: t('dashboard', 'Hello, {name}', { name: this.displayName }),
},
} }
if (time > 5) {
return { text: shouldShowName ? t('dashboard', 'Good morning, {name}', { name: this.displayName }) : t('dashboard', 'Good morning') } // Figure out which greeting to show
} const shouldShowName = this.displayName && this.uid !== this.displayName
return { text: shouldShowName ? t('dashboard', 'Good night, {name}', { name: this.displayName }) : t('dashboard', 'Good night') } return { text: shouldShowName ? good[partOfDay].withName : good[partOfDay].generic }
}, },
isActive() { isActive() {
return (panel) => this.layout.indexOf(panel.id) > -1 return (panel) => this.layout.indexOf(panel.id) > -1