5b7f28925c
* FE validation before model creation * minor fix * testing UI change in cardview * a bunch of fixes * table improvements * undid test thing
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import type { MaybeRef } from '@vueuse/core'
|
|
import type { MaybeNullOrUndefined } from '@speckle/shared'
|
|
import type { CSSProperties } from 'vue'
|
|
import type { UploadFileItem, UploadableFileItem } from '@speckle/ui-components'
|
|
|
|
export type { UploadFileItem, UploadableFileItem }
|
|
|
|
export function useFileUploadProgressCore(params: {
|
|
item: MaybeRef<MaybeNullOrUndefined<UploadFileItem>>
|
|
}) {
|
|
const errorMessage = computed(() => {
|
|
const item = unref(params.item)
|
|
if (!item) return null
|
|
|
|
const itemError = item.error
|
|
if (itemError) return itemError.message
|
|
|
|
const uploadError = item.result?.uploadError
|
|
if (uploadError) return uploadError
|
|
|
|
return null
|
|
})
|
|
|
|
const progressBarColorClass = computed(() => {
|
|
const item = unref(params.item)
|
|
if (errorMessage.value) return 'bg-danger'
|
|
if (item && item.progress >= 100) return 'bg-success'
|
|
return 'bg-primary'
|
|
})
|
|
|
|
const progressBarClasses = computed(() => {
|
|
return ['h-1', progressBarColorClass.value].join(' ')
|
|
})
|
|
|
|
const progressBarStyle = computed((): CSSProperties => {
|
|
const item = unref(params.item)
|
|
return {
|
|
width: `${Math.max(item ? item.progress : 0, 1)}%`
|
|
}
|
|
})
|
|
|
|
return { errorMessage, progressBarClasses, progressBarStyle }
|
|
}
|