-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+
<RelativeTime>
that extracted from <PostBadgeTimeView>
to only …
…invoking expensive `DateTime.toRelative()` moment/luxon#959 for components in viewport * now will return the ref `timer[unit]` being bound * replace the null forgive operator for unmatched units with fallbacking to year unit * remove param `options` * renamed from `registerRelative()` @ `registerTimerDep()` @ `store/relativeTime.ts` - scoped style for `span` that being unused since 4d82a0a @ `<PostBadgeTimeView>` @ fe
- Loading branch information
Showing
3 changed files
with
46 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<template> | ||
<span :ref="el => relativeEl = (el as HTMLElement)"> | ||
<template v-if="hydrationStore.isHydratingOrSSR || !relativeElIsVisible"> | ||
{{ dateTimeInChina.toLocaleString({ | ||
year: 'numeric', | ||
...keysWithSameValue(['month', 'day', 'hour', 'minute', 'second'], '2-digit') | ||
}) }} | ||
</template> | ||
<template v-else> | ||
{{ current.toRelative({ base: relativeTo, round: false }) }} | ||
</template> | ||
</span> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { DateTime } from 'luxon'; | ||
const props = defineProps<{ | ||
dateTime: DateTime<true>, | ||
relativeTo?: DateTime<true> | ||
}>(); | ||
const hydrationStore = useHydrationStore(); | ||
const relativeEl = ref<HTMLElement>(); | ||
const relativeElIsVisible = ref(false); | ||
const dateTimeInChina = computed(() => setDateTimeZoneAndLocale()(props.dateTime)); | ||
const { pause, resume } = useIntersectionObserver( | ||
relativeEl, | ||
([{ isIntersecting }]) => { | ||
relativeElIsVisible.value = isIntersecting; | ||
} | ||
); | ||
watchEffect(() => { | ||
if (props.relativeTo === undefined) | ||
pause(); | ||
else | ||
resume(); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters