Fix modified tooltip (exact timestamp) flickering on/off because of timestamp updates every second. Made the tooltip follow mouse cursor.

This commit is contained in:
2026-01-22 00:39:26 +00:00
parent f354fc5c71
commit b6c21152e7
3 changed files with 74 additions and 12 deletions
+2 -2
View File
@@ -17,7 +17,7 @@
<td class="name">
<FileRenameInput :doc="editing" :rename="mkdir" :exit="() => {editing = null}" />
</td>
<FileModified :doc=editing :key=nowkey />
<FileModified :doc=editing :now=nowkey />
<FileSize :doc=editing />
<td class="menu"></td>
</tr>
@@ -55,7 +55,7 @@
<button tabindex=-1 v-if="store.cursor == doc.key" class="rename-button" @click="() => (editing = doc)">🖊</button>
</template>
</td>
<FileModified :doc=doc :key=nowkey />
<FileModified :doc=doc :now=nowkey />
<FileSize :doc=doc />
<td class="menu">
<button tabindex=-1 @click.stop="contextMenu($event, doc)"></button>
+71 -7
View File
@@ -1,22 +1,86 @@
<template>
<td class="modified right">
<time :data-tooltip=tooltip :datetime=datetime>{{ doc.modified }}</time>
<time
:datetime=datetime
@mouseenter="startHover"
@mousemove="updatePosition"
@mouseleave="endHover"
>{{ modified }}</time>
<Teleport to="body">
<div v-if="showTooltip" class="cursor-tooltip" :style="tooltipStyle">
{{ tooltipText }}
</div>
</Teleport>
</td>
</template>
<script setup lang="ts">
import { Doc } from '@/repositories/Document'
import { computed } from 'vue'
import { formatUnixDate } from '@/utils'
import { computed, ref } from 'vue'
const props = defineProps<{
doc: Doc
now: number
}>()
// Reference props.now to trigger reactivity when time updates
const modified = computed(() => {
props.now // trigger reactivity
return formatUnixDate(props.doc.mtime)
})
const datetime = computed(() =>
new Date(1000 * props.doc.mtime).toISOString().replace('.000Z', 'Z')
)
const tooltip = computed(() =>
datetime.value.replace('T', '\n').replace('Z', ' UTC')
const tooltipText = computed(() =>
datetime.value.replace('T', ' ').replace('Z', ' UTC')
)
const props = defineProps<{
doc: Doc
}>()
const showTooltip = ref(false)
const mouseX = ref(0)
const mouseY = ref(0)
let hoverTimer: ReturnType<typeof setTimeout> | null = null
const tooltipStyle = computed(() => ({
left: `${mouseX.value + 12}px`,
top: `${mouseY.value + 12}px`,
}))
const startHover = (e: MouseEvent) => {
mouseX.value = e.clientX
mouseY.value = e.clientY
hoverTimer = setTimeout(() => {
showTooltip.value = true
}, 500)
}
const updatePosition = (e: MouseEvent) => {
mouseX.value = e.clientX
mouseY.value = e.clientY
}
const endHover = () => {
if (hoverTimer) {
clearTimeout(hoverTimer)
hoverTimer = null
}
showTooltip.value = false
}
</script>
<style scoped>
.cursor-tooltip {
position: fixed;
z-index: 10000;
padding: .5rem 1rem;
border-radius: 3rem 0 3rem 0;
box-shadow: 0 0 1rem var(--accent-color);
background-color: var(--accent-color);
color: var(--primary-color);
white-space: pre;
pointer-events: none;
font-size: 1rem;
}
</style>