ListPost: regularly update creation date

This commit is contained in:
styppo 2023-01-15 02:20:09 +00:00
parent d3e5d30038
commit 6b3ebe5d46
No known key found for this signature in database
GPG Key ID: 3AAA685C50724C28

View File

@ -18,7 +18,7 @@
<p class="author-line">
<UserName :pubkey="note.author" clickable show-verified @click.stop />
<span>&#183;</span>
<span class="created-at">{{ formatPostDate(note.createdAt) }}</span>
<span class="created-at">{{ createdAt }}</span>
</p>
<p v-if="note.hasAncestor()" class="in-reply-to">
Replying to
@ -97,6 +97,12 @@ export default {
stat: useStatStore(),
}
},
data() {
return {
refreshCounter: 0,
refreshTimer: null,
}
},
computed: {
ancestor() {
return this.note.hasAncestor()
@ -109,6 +115,11 @@ export default {
showActions() {
return this.actions && this.note.canReply()
},
createdAt() {
// Mention refreshCounter to make this property react to changes to it
this.refreshCounter
return this.formatPostDate(this.note.createdAt)
}
},
methods: {
formatPostDate(timestamp) {
@ -116,6 +127,15 @@ export default {
return DateUtils.formatFromNow(timestamp, format)
},
},
mounted() {
const updateInterval = Date.now() / 1000 - this.note.createdAt >= 3600 // 1h
? 3600 // 1h
: 60 // 1m
this.refreshTimer = setInterval(() => this.refreshCounter++, updateInterval * 1000)
},
unmounted() {
clearInterval(this.refreshTimer)
}
}
</script>