Skip to content

Commit 84ad7eb

Browse files
committed
feat(webapp): use date-fns directly
No need for an extra wrapper as dependency.
1 parent f892231 commit 84ad7eb

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

www/webapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"@mdi/js": "~7.2.96",
1515
"axios": "^1.4.0",
1616
"core-js": "^3.27.1",
17+
"date-fns": "^2.30.0",
1718
"pinia": "^2.0.30",
1819
"vue": "~2.7.14",
1920
"vue-clipboard2": "^0.3.3",
2021
"vue-router": "~3.6.5",
21-
"vue-timeago": "^5.1.3",
2222
"vuelidate": "^0.7.7",
2323
"vuetify": "^2.6.13"
2424
},

www/webapp/src/components/Field/TimeAgo.vue

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
<template>
22
<div
3-
class="my-1 py-5"
4-
:title="value"
5-
><timeago v-if="value" :datetime="value"></timeago><span v-else>never</span></div>
3+
class="my-1 py-5"
4+
:title="value"
5+
>
6+
<span v-text="formattedValue"></span>
7+
</div>
68
</template>
79

810
<script>
11+
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
12+
913
export default {
1014
name: 'TimeAgo',
1115
props: {
1216
value: {
1317
default: '',
1418
type: String,
1519
},
20+
defaultText: {
21+
default: 'never',
22+
type: String,
23+
},
1624
},
25+
computed: {
26+
formattedValue() {
27+
const inputTime = this.value;
28+
if(!inputTime)
29+
return this.defaultText
30+
31+
const parsedTime = new Date(inputTime);
32+
return formatDistanceToNow(parsedTime, {addSuffix: true});
33+
}
34+
}
1735
};
1836
</script>
1937

www/webapp/src/main.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ import "@fontsource/roboto/400-italic.css" /* regular-italic */
1111
import "@fontsource/roboto/500.css" /* medium */
1212
import "@fontsource/roboto/700.css" /* bold */
1313
import '@mdi/font/css/materialdesignicons.css'
14-
import VueTimeago from 'vue-timeago'
1514
import {createPinia, PiniaVuePlugin} from "pinia";
1615

1716

1817
Vue.config.productionTip = false
1918
VueClipboard.config.autoSetContainer = true
2019
Vue.use(VueClipboard)
2120
Vue.use(Vuelidate)
22-
Vue.use(VueTimeago, {})
2321
// `Pinia` replaces `vuex` as store.
2422
Vue.use(PiniaVuePlugin)
2523
const pinia = createPinia()

0 commit comments

Comments
 (0)