-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIpfsImage.vue
42 lines (37 loc) · 991 Bytes
/
IpfsImage.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { getPhotoFromIPFS, isValidPhoto } from '@/backend/getPhoto';
import { toastError } from '@/plugins/toast';
const props = withDefaults(
defineProps<{
cid?: string | null;
imgClass?: string;
defaultImage?: string | null | ArrayBuffer;
}>(),
{
cid: null,
imgClass: ``,
defaultImage: null,
},
);
const imageSrc = ref<string | ArrayBuffer | null>(null);
onMounted(async () => {
if (props.defaultImage) {
imageSrc.value = props.defaultImage;
}
if (props.cid) {
const dataUrl = await getPhotoFromIPFS(props.cid);
if (!isValidPhoto(dataUrl)) {
toastError(`Invalid image with cid: ${props.cid}`);
return;
}
imageSrc.value = dataUrl;
}
});
</script>
<template>
<div v-if="imageSrc !== null" class="modal-animation">
<img v-lazy="imageSrc" :class="imgClass + ' object-cover'" />
</div>
<div v-else class="animate-pulse bg-gray1 dark:bg-gray7 h-72 w-full rounded-lg"></div>
</template>