Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Frontend/src/components/TimeSince.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from "vue";
import moment from "moment";
import { Tippy } from "vue-tippy";

const emptyDate = "0001-01-01T00:00:00";

const props = withDefaults(defineProps<{ dateUtc?: string; defaultTextOnFailure?: string; titleValue?: string }>(), { dateUtc: emptyDate, defaultTextOnFailure: "n/a", titleValue: undefined });

let interval: number | undefined = undefined;

const title = ref(),
const title = ref<string[]>([]),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to make title an array so it renders correctly

text = ref();

function updateText() {
if (props.dateUtc != null && props.dateUtc !== emptyDate) {
const m = moment.utc(props.dateUtc);
text.value = m.fromNow();
title.value = props.titleValue ?? m.local().format("LLLL") + " (local)\n" + m.utc().format("LLLL") + " (UTC)";
title.value = props.titleValue ? [props.titleValue] : [`${m.local().format("LLLL")} (local)`, `${m.utc().format("LLLL")} (UTC)`];
} else {
text.value = props.defaultTextOnFailure;
title.value = props.titleValue ?? props.defaultTextOnFailure;
title.value = [props.titleValue ?? props.defaultTextOnFailure];
}
}

Expand All @@ -34,5 +35,10 @@ onUnmounted(() => window.clearInterval(interval));
</script>

<template>
<span :title="title">{{ text }}</span>
<Tippy>
<template #content>
<div v-for="row in title" :key="row">{{ row }}</div>
</template>
<span>{{ text }}</span>
</Tippy>
</template>
Loading