Skip to content

Commit

Permalink
add timeago
Browse files Browse the repository at this point in the history
  • Loading branch information
aliel committed Jun 3, 2024
1 parent 6e858c8 commit fde445e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,11 @@ input {
width: 0.8em;
height: 0.8em;
}

.bull-date {
color: $dark-text-color;
}
.bull-date::before {
content: "";
margin-left: 5px;
}
31 changes: 30 additions & 1 deletion src/pages/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<!-- Display the role of the user or the AI -->
<q-item-label class="text-semibold q-mb-md">
{{message.role}}
<span class="bull-date">{{formatDate(message.timestamp)}}</span>
</q-item-label>
<!-- Display any attachments -->
<q-item-label v-if="message.attachments && message.attachments.length > 0">
Expand Down Expand Up @@ -153,7 +154,7 @@

<script setup>
import 'highlight.js/styles/devibeans.css';
import { copyToClipboard, useQuasar } from 'quasar';
import { copyToClipboard, useQuasar, date } from 'quasar';
import { nextTick, onMounted, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
Expand Down Expand Up @@ -548,6 +549,34 @@ async function clearCookies() {
function openKnowledgeUploader() {
showKnowledgeUploaderRef.value = true;
}
function formatDate(d) {
if(!d) d = new Date();
const currentDate = new Date();
const timeDiff = currentDate.getTime()/1000 - d.getTime()/1000;
let unit = "hour";
let txtUnit = "h"
if(timeDiff < 60) {
unit = "second"
txtUnit = "s"
} else if(timeDiff < 3600) {
unit = "minute"
txtUnit = "m"
} else if(timeDiff < 86400) {
unit = "hour"
txtUnit = "h"
} else if(timeDiff < 2592000) {
unit = "day"
txtUnit = "d"
} else if(timeDiff > 2592000) {
unit = "month"
txtUnit = "month"
}
const diff = date.getDateDiff(currentDate, d, unit)
return diff + txtUnit;
}
</script>
<style>
/* Ensure message input expands to fill available space */
Expand Down

0 comments on commit fde445e

Please sign in to comment.