feat: move the calculation of the current salutation to a different function #1249
No reviewers
Labels
No Label
area/internal-code
changes requested
confirmed
dependencies
duplicate
good first issue
help wanted
hosting
invalid
kind/bug
kind/feature
question
wontfix
No Milestone
No project
No Assignees
3 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: vikunja/frontend#1249
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "feature/move-salutation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I hope to make the tests less flaky with that (it's almost always the home page test that fails).
Hi konrad!
Thank you for creating a PR!
I've deployed the changes of this PR on a preview environment under this URL: https://1249-featuremove-salutation--vikunja-frontend-preview.netlify.app
You can use this url to view the changes live and test them out.
You will need to manually connect this to an api running somehwere. The easiest to use is https://try.vikunja.io/.
Have a nice day!
@ -0,0 +1,21 @@
export function hourToSalutation(now: Date = new Date()): String {
Maybe we can return a translation id here instead of the final string. This way we can add support for translation
Done!
@ -90,3 +71,1 @@
return 'Night'
})
const welcome = computed(hourToSalutation)
This computed will currently never change. My idea with the
useNow
was that when you keep the page open the title changes dynamically.That makes sense.
I've reimplemented it with
useNow
andDate
, that way we can put a controlled date in the function for the tests.Not quite sure if this is the right way?
@ -0,0 +3,4 @@
const TRANSLATION_KEY_PREFIX = 'home.welcome'
export function hourToSalutation(now: Date | Ref<Date> = useNow()): String {
I'm quite unsure about this pattern now:
Normally our helpers are side effect free.
But this helper can contain a ref which has to be cleaned up.
It is almost a composable. Maybe we should go the full way and tranform it in one. Or would that make problems with testing?
OR
We keep the function (but remove the ref compatability) and add a composable.
Somehow like this (untested):
EDIT: We could probably remove the parameter of useDateTimeSalutation because we don't need it (?).
sidenote: vueuse has a cool type for this: MayBeRef
Probably we can even remove the extra function. I thought it makes sense to keep it separated to make the function testable by itself.
But we can also just test the composable e.g. like vueuse does
I changed it to this comment now to keep it simple.
We can still change the composable tests to something similar than vueuse does later.
@ -0,0 +4,4 @@
const TRANSLATION_KEY_PREFIX = 'home.welcome'
export function hourToSalutation(now: Date | Ref<Date> = useNow()): String {
const hours = now instanceof Date ? new Date(now).getHours() : new Date(now.value).getHours()
use unref
Not necessary anymore since I removed composable functions from the helper.
ccb764ff1f
to6fbf329abb
6fbf329abb
to096395e530
096395e530
to323e7d299d
323e7d299d
to74313499b0