|
|
@@ -2,7 +2,7 @@
|
|
|
<main>
|
|
|
<div class="image-wrapper" :style="{width: width + 'px'}">
|
|
|
<v-img
|
|
|
- :src="imgSrcReload ? imgSrcReload : image"
|
|
|
+ :src="imageSrc"
|
|
|
:lazy-src="defaultImagePath"
|
|
|
:height="height"
|
|
|
:width="width"
|
|
|
@@ -18,8 +18,7 @@
|
|
|
<v-progress-circular
|
|
|
:indeterminate="true"
|
|
|
color="grey lighten-1"
|
|
|
- >
|
|
|
- </v-progress-circular>
|
|
|
+ />
|
|
|
</v-row>
|
|
|
</template>
|
|
|
</v-img>
|
|
|
@@ -48,11 +47,13 @@ import {useContext} from "unctx";
|
|
|
import {useNuxtApp} from "#app";
|
|
|
import {useImageFetch} from "~/composables/data/useImageFetch";
|
|
|
import {onUnmounted, watch, WatchStopHandle} from "@vue/runtime-core";
|
|
|
+import {useImageManager} from "~/composables/data/useImageManager";
|
|
|
|
|
|
const props = defineProps({
|
|
|
id: {
|
|
|
type: Number,
|
|
|
- required: false
|
|
|
+ required: true,
|
|
|
+ default: null
|
|
|
},
|
|
|
field: {
|
|
|
type: String,
|
|
|
@@ -60,8 +61,7 @@ const props = defineProps({
|
|
|
},
|
|
|
defaultImage: {
|
|
|
type: String,
|
|
|
- required: false,
|
|
|
- default: 'picture.jpeg'
|
|
|
+ required: false
|
|
|
},
|
|
|
height: {
|
|
|
type: Number,
|
|
|
@@ -82,25 +82,34 @@ const props = defineProps({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-// fetchOnServer: false, // TODO: je ne sais pas encore par quoi remplacer ça...
|
|
|
+const { imageManager } = useImageManager()
|
|
|
+const { fetch } = useImageFetch()
|
|
|
|
|
|
-const defaultImagePath = `/images/default/${props.defaultImage}`
|
|
|
+const defaultImagePath = props.defaultImage ?? imageManager.defaultImage
|
|
|
|
|
|
const openUpload: Ref<Boolean> = ref(false)
|
|
|
-const imgSrcReload: Ref<any> = ref(null)
|
|
|
-const { $config } = useNuxtApp()
|
|
|
|
|
|
-const { fetch } = useImageFetch()
|
|
|
-const fetchImage = () => fetch(props.id ?? null, props.defaultImage, props.height, props.width)
|
|
|
+const imageSrc: Ref<string | null> = ref(null)
|
|
|
+let pending = ref(true)
|
|
|
+
|
|
|
+const fetchImage = async () => {
|
|
|
+ pending.value = true
|
|
|
+ imageSrc.value = await imageManager.get(props.id ?? null, defaultImagePath, props.height, props.width)
|
|
|
+ pending.value = false
|
|
|
+}
|
|
|
|
|
|
-const {data: image, pending} = fetchImage()
|
|
|
+onMounted(
|
|
|
+ () => {
|
|
|
+ fetchImage()
|
|
|
+ }
|
|
|
+)
|
|
|
|
|
|
const unwatch: WatchStopHandle = watch(() => props.id, async (newValue, oldValue) => {
|
|
|
- imgSrcReload.value = await fetch(newValue as number, props.defaultImage, props.height, props.width)
|
|
|
+ await fetchImage()
|
|
|
})
|
|
|
|
|
|
-const onReload = () => {
|
|
|
- fetchImage()
|
|
|
+const onReload = async () => {
|
|
|
+ await fetchImage()
|
|
|
openUpload.value = false
|
|
|
}
|
|
|
|
|
|
@@ -108,8 +117,7 @@ const onReload = () => {
|
|
|
* Quand on souhaite faire un reset de l'image
|
|
|
*/
|
|
|
const reset = () => {
|
|
|
- imgSrcReload.value = null
|
|
|
- image.value = require(defaultImagePath)
|
|
|
+ imageSrc.value = defaultImagePath
|
|
|
openUpload.value = false
|
|
|
}
|
|
|
|