2018-09-12 17:14:45 +00:00
|
|
|
<template>
|
2019-07-17 09:33:59 +00:00
|
|
|
<div :aria-label="localeDate" class="date-marker-container tooltipped tooltipped-s">
|
2018-09-12 17:14:45 +00:00
|
|
|
<div class="date-marker">
|
2019-11-20 22:16:58 +00:00
|
|
|
<span :aria-label="friendlyDate()" class="date-marker-text" />
|
2018-09-12 17:14:45 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
2019-11-14 15:30:42 +00:00
|
|
|
import dayjs from "dayjs";
|
|
|
|
import calendar from "dayjs/plugin/calendar";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {computed, defineComponent, onBeforeUnmount, onMounted, PropType} from "vue";
|
2020-03-16 17:58:40 +00:00
|
|
|
import eventbus from "../js/eventbus";
|
2022-06-19 00:25:21 +00:00
|
|
|
import type {ClientMessage} from "../js/types";
|
2019-11-14 15:30:42 +00:00
|
|
|
|
|
|
|
dayjs.extend(calendar);
|
2018-09-12 17:14:45 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default defineComponent({
|
2018-09-12 17:14:45 +00:00
|
|
|
name: "DateMarker",
|
|
|
|
props: {
|
2022-06-19 00:25:21 +00:00
|
|
|
message: {
|
|
|
|
type: Object as PropType<ClientMessage>,
|
|
|
|
required: true,
|
2018-09-12 18:09:43 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
focused: Boolean,
|
2018-09-12 18:09:43 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
setup(props) {
|
|
|
|
const localeDate = computed(() => dayjs(props.message.time).format("D MMMM YYYY"));
|
|
|
|
|
|
|
|
const hoursPassed = () => {
|
|
|
|
return (Date.now() - Date.parse(props.message.time.toString())) / 3600000;
|
|
|
|
};
|
2018-09-12 18:00:03 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const dayChange = () => {
|
|
|
|
if (hoursPassed() >= 48) {
|
|
|
|
eventbus.off("daychange", dayChange);
|
2018-09-12 18:00:03 +00:00
|
|
|
}
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const friendlyDate = () => {
|
2018-09-12 18:00:03 +00:00
|
|
|
// See http://momentjs.com/docs/#/displaying/calendar-time/
|
2022-06-19 00:25:21 +00:00
|
|
|
return dayjs(props.message.time).calendar(null, {
|
2018-09-12 18:00:03 +00:00
|
|
|
sameDay: "[Today]",
|
|
|
|
lastDay: "[Yesterday]",
|
|
|
|
lastWeek: "D MMMM YYYY",
|
|
|
|
sameElse: "D MMMM YYYY",
|
|
|
|
});
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
if (hoursPassed() < 48) {
|
|
|
|
eventbus.on("daychange", dayChange);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
eventbus.off("daychange", dayChange);
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
localeDate,
|
|
|
|
friendlyDate,
|
|
|
|
};
|
2018-09-12 17:14:45 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2018-09-12 17:14:45 +00:00
|
|
|
</script>
|