This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): display run date instead of random title
- Loading branch information
Showing
11 changed files
with
117 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<script lang="ts" setup> | ||
import { computed, onUnmounted, PropType, ref, watchEffect } from 'vue' | ||
const props = defineProps({ | ||
date: { | ||
type: [Object, String, Number] as PropType<Date | string | number>, | ||
required: true, | ||
}, | ||
}) | ||
const parsedDate = computed(() => new Date(props.date)) | ||
const display = ref('') | ||
const interval = ref(1) | ||
const rtf = new Intl.RelativeTimeFormat(undefined, { | ||
style: 'narrow', | ||
numeric: 'auto', | ||
}) | ||
const units: ([number, Intl.RelativeTimeFormatUnit])[] = [[60, 'minute'], [60, 'hour']] | ||
function update () { | ||
let diff = (parsedDate.value.getTime() - Date.now()) / 1000 | ||
let unit: Intl.RelativeTimeFormatUnit = 'second' | ||
let newInterval = 1000 | ||
for (let index = 0; index < units.length - 1; index++) { | ||
const newDiff = diff / units[index][0] | ||
if (Math.abs(newDiff) < 1) { | ||
index-- | ||
break | ||
} | ||
diff = newDiff | ||
unit = units[index][1] | ||
newInterval *= units[index][0] | ||
} | ||
display.value = rtf.format(Math.round(diff), unit) | ||
interval.value = newInterval | ||
} | ||
update() | ||
let timer: ReturnType<typeof setInterval> | ||
watchEffect(() => { | ||
clearInterval(timer) | ||
timer = setInterval(() => { | ||
update() | ||
}, interval.value) | ||
}) | ||
onUnmounted(() => { | ||
clearInterval(timer) | ||
}) | ||
</script> | ||
|
||
<template> | ||
{{ display }} | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './server.js' | ||
export * from './generated/nexus-typegen.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.