1
0

feat: add getter support to useProjectBackground

This commit is contained in:
Dominik Pschenitschni 2024-06-26 12:19:00 +02:00 committed by konrad
parent 01a4ad99ab
commit 914fe092e5

View File

@ -1,19 +1,20 @@
import {ref, watch, type ShallowReactive} from 'vue' import {ref, toValue, watch, type MaybeRefOrGetter} from 'vue'
import ProjectService from '@/services/project' import ProjectService from '@/services/project'
import type {IProject} from '@/modelTypes/IProject' import type {IProject} from '@/modelTypes/IProject'
import {getBlobFromBlurHash} from '@/helpers/getBlobFromBlurHash' import {getBlobFromBlurHash} from '@/helpers/getBlobFromBlurHash'
export function useProjectBackground(project: ShallowReactive<IProject>) { export function useProjectBackground(project: MaybeRefOrGetter<IProject>) {
const background = ref<string | null>(null) const background = ref<string | null>(null)
const backgroundLoading = ref(false) const backgroundLoading = ref(false)
const blurHashUrl = ref('') const blurHashUrl = ref('')
watch( watch(
() => [project.id, project.backgroundBlurHash] as [IProject['id'], IProject['backgroundBlurHash']], () => [toValue(project).id, toValue(project)?.backgroundBlurHash] as [IProject['id'], IProject['backgroundBlurHash']],
async ([projectId, blurHash], oldValue) => { async ([projectId, blurHash], oldValue) => {
const projectValue = toValue(project)
if ( if (
project === null || projectValue === null ||
!project.backgroundInformation || !projectValue.backgroundInformation ||
backgroundLoading.value backgroundLoading.value
) { ) {
return return
@ -36,7 +37,7 @@ export function useProjectBackground(project: ShallowReactive<IProject>) {
}) })
const projectService = new ProjectService() const projectService = new ProjectService()
const backgroundPromise = projectService.background(project).then((result) => { const backgroundPromise = projectService.background(projectValue).then((result) => {
background.value = result background.value = result
}) })
await Promise.all([blurHashPromise, backgroundPromise]) await Promise.all([blurHashPromise, backgroundPromise])