Skip to content

A self-hosted media server and file management system

fix: history shows as -1s ago

aminnausin2a68a56d91d6
diff --git a/resources/js/components/cards/RecordCard.vue b/resources/js/components/cards/RecordCard.vue
index 9e6b5c89..1ef223e2 100755
--- a/resources/js/components/cards/RecordCard.vue
+++ b/resources/js/components/cards/RecordCard.vue
@@ -2,7 +2,7 @@
import { type RecordResource } from '@/types/resources';
import { toFormattedDate, toTimeSpan } from '@/service/util';
-import { computed } from 'vue';
+import { computed, ref, watch } from 'vue';
import ButtonCorner from '@/components/inputs/ButtonCorner.vue';
@@ -11,11 +11,11 @@ import CircumPlay1 from '~icons/circum/play-1';
const props = defineProps<{
record: RecordResource;
+ index: number;
}>();
const rawDate = new Date((props.record.attributes.created_at ?? '').replace(' ', 'T'));
-const timeSpan = toTimeSpan(rawDate);
-
+const timeSpan = ref(toTimeSpan(rawDate));
const videoLink = computed(() => {
if (
!(props.record.relationships.video_id ?? props.record.relationships.metadata?.video_id) ||
@@ -25,6 +25,13 @@ const videoLink = computed(() => {
return false;
return `/${encodeURIComponent(props.record.relationships?.category?.name ?? '')}/${encodeURIComponent(props.record.relationships.folder?.name ?? '')}?video=${props.record.relationships.video_id ?? props.record.relationships.metadata?.video_id}`;
});
+
+watch(
+ () => props.index,
+ () => {
+ timeSpan.value = toTimeSpan(rawDate);
+ },
+);
</script>
<template>
diff --git a/resources/js/components/panels/VideoSidebar.vue b/resources/js/components/panels/VideoSidebar.vue
index fcee5bf7..6e916fb2 100755
--- a/resources/js/components/panels/VideoSidebar.vue
+++ b/resources/js/components/panels/VideoSidebar.vue
@@ -1,11 +1,11 @@
<script setup lang="ts">
import type { FolderResource, SeriesResource } from '@/types/resources';
+import { ref, watch, type Ref } from 'vue';
import { useContentStore } from '@/stores/ContentStore';
import { useAppStore } from '@/stores/AppStore';
import { storeToRefs } from 'pinia';
import { RouterLink } from 'vue-router';
-import { ref, watch, type Ref } from 'vue';
import ButtonClipboard from '@/components/pinesUI/ButtonClipboard.vue';
import FolderCard from '@/components/cards/FolderCard.vue';
@@ -77,7 +77,7 @@ watch(
/>
</section>
<section v-if="selectedSideBar === 'history'" id="list-content-history" class="flex gap-2 flex-wrap">
- <RecordCard v-for="record in stateRecords.slice(0, 10)" :key="record.id" :record="record" @clickAction="handleShare" />
+ <RecordCard v-for="(record, index) in stateRecords.slice(0, 10)" :key="record.id" :record="record" :index="index" @clickAction="handleShare" />
<RouterLink v-if="stateRecords.length != 0" to="/history" class="text-center text-sm dark:text-neutral-400 mx-auto p-3 hover:underline">View More</RouterLink>
<h2 v-else class="text-gray-500 dark:text-gray-400 tracking-wider w-full py-2">Nothing Yet...</h2>
</section>
diff --git a/resources/js/service/util.ts b/resources/js/service/util.ts
index 46416ed4..c2099407 100644
--- a/resources/js/service/util.ts
+++ b/resources/js/service/util.ts
@@ -30,7 +30,7 @@ export function toTimeSpan(rawDate: Date | string, timeZoneName = ' EST') {
? `${hours} hour${toPlural(hours)} ago`
: minutes > 0
? `${minutes}m ago`
- : `${seconds}s ago`;
+ : `${Math.max(1, seconds)}s ago`;
return timeSpan;
}