Show salutation based on the time of day

This commit is contained in:
kolaente 2021-07-06 17:13:13 +02:00
parent f3715c7900
commit c7c9b5ee47
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 43 additions and 17 deletions

View file

@ -1,6 +1,9 @@
{ {
"home": { "home": {
"welcome": "Hi {username}", "welcomeNight": "Good Night {username}",
"welcomeMorning": "Good Morning {username}",
"welcomeDay": "Hi {username}",
"welcomeEvening": "Good Evening {username}",
"list": { "list": {
"newText": "You can create a new list for your new tasks:", "newText": "You can create a new list for your new tasks:",
"new": "Create a new list", "new": "Create a new list",

View file

@ -1,7 +1,7 @@
<template> <template>
<div class="content has-text-centered"> <div class="content has-text-centered">
<h2> <h2>
{{ $t('home.welcome', {username: userInfo.name !== '' ? userInfo.name : userInfo.username}) }}! {{ $t(`home.welcome${welcome}`, {username: userInfo.name !== '' ? userInfo.name : userInfo.username}) }}!
</h2> </h2>
<template v-if="!hasTasks"> <template v-if="!hasTasks">
<p>{{ $t('home.list.newText') }}</p> <p>{{ $t('home.list.newText') }}</p>
@ -43,7 +43,29 @@ export default {
tasks: [], tasks: [],
} }
}, },
computed: mapState({ computed: {
welcome() {
const now = new Date()
if (now.getHours() < 5) {
return 'Night'
}
if(now.getHours() < 11) {
return 'Morning'
}
if(now.getHours() < 18) {
return 'Day'
}
if(now.getHours() < 23) {
return 'Evening'
}
return 'Night'
},
...mapState({
migratorsEnabled: state => state.config.availableMigrators !== null && state.config.availableMigrators.length > 0, migratorsEnabled: state => state.config.availableMigrators !== null && state.config.availableMigrators.length > 0,
authenticated: state => state.auth.authenticated, authenticated: state => state.auth.authenticated,
userInfo: state => state.auth.info, userInfo: state => state.auth.info,
@ -63,5 +85,6 @@ export default {
return state.namespaces.namespaces[0].lists.length > 0 return state.namespaces.namespaces[0].lists.length > 0
}, },
}), }),
}
} }
</script> </script>