|
5 | 5 | * Created Date: 2025-09-08 15:39:55 |
6 | 6 | * Author: 3urobeat |
7 | 7 | * |
8 | | - * Last Modified: 2026-05-09 23:23:22 |
| 8 | + * Last Modified: 2026-05-10 19:12:09 |
9 | 9 | * Modified By: 3urobeat |
10 | 10 | * |
11 | 11 | * Copyright (c) 2025 - 2026 3urobeat <https://github.com/3urobeat> |
|
64 | 64 | > |
65 | 65 | <!-- Show image if available --> |
66 | 66 | <img |
67 | | - v-if="thisClothingImgBlob" |
| 67 | + v-if="cachedImage?.imgBlob" |
68 | 68 | class="rounded-2xl self-center h-fit max-h-full select-none" |
69 | 69 | :class="editModeEnabled ? 'opacity-50' : ''" |
70 | | - :src="'data:image/png;base64,' + thisClothingImgBlob" |
| 70 | + :src="'data:image/png;base64,' + cachedImage.imgBlob" |
71 | 71 | alt="" |
72 | 72 | > |
73 | 73 | <PhImageBroken v-else-if="!editModeEnabled" class="h-2/3 w-2/3 self-center text-text-secondary-light/50 dark:text-text-secondary-dark/50" /> |
|
160 | 160 | import { getNewLastLabelOrderIndex, sortLabelsList, type Label } from "~/model/label"; |
161 | 161 | import { getLabelsOfCategory, type Category } from "~/model/label-category"; |
162 | 162 | import { CategorySpecialityMap } from "~/model/label-category"; |
163 | | - import { getImageFromServer, setCategoriesAndLabelsToServer } from "~/composables/storage"; |
| 163 | + import { useImage, setCategoriesAndLabelsToServer } from "~/composables/storage"; |
164 | 164 | import { StorageKind, type ItemID } from "~/model/storage"; |
165 | 165 | import { SubscriptionEventAction, SubscriptionEventType, type ApiResponse, type StorageSubscriptionEvent, type SubscriptionEvent } from "~/model/api"; |
166 | 166 |
|
|
172 | 172 | const storedCategories = getAllLabelCategoriesFromCache(); |
173 | 173 |
|
174 | 174 | // Refs, init for new piece of clothing |
175 | | - let storedClothing: Ref<ApiResponse<Clothing>> = ref({ success: true, message: null, document: { id: "", title: "", description: "", imgPath: "", labelIDs: [], addedTimestamp: 0, modifiedTimestamp: 0 } }); |
176 | | - let localClothing: Ref<ApiResponse<Clothing>> = storedClothing; |
177 | | - const thisClothingImgBlob: Ref<string> = ref(""); |
| 175 | + let storedClothing: Ref<ApiResponse<Clothing>> = ref({ success: true, message: null, document: { id: "", title: "", description: "", imgPath: "", labelIDs: [], addedTimestamp: 0, modifiedTimestamp: 0 } }); |
| 176 | + let localClothing: Ref<ApiResponse<Clothing>> = storedClothing; |
| 177 | +
|
| 178 | + const currentImgPath = ref(""); |
| 179 | + const { cachedImage, load } = useImage(currentImgPath, 512); |
178 | 180 |
|
179 | 181 |
|
180 | 182 | // Check if edit mode is enabled based on if name of this route is outfits-view or outfits-edit |
|
200 | 202 | } |
201 | 203 |
|
202 | 204 | // I think it actually provides a better user experience fetching the image afterwards here |
203 | | - // thisClothingImgBlob.value = (await getSSRImageFromServer(thisClothing.value.imgPath, 512))?.value.document?.imgBlob || ""; |
204 | | - onMounted(async () => { |
205 | | - thisClothingImgBlob.value = (await getImageFromServer(localClothing.value.document!.imgPath, 512))?.imgBlob || ""; // TODO: Does ref break? |
206 | | - }); |
| 205 | + // cachedImage.value = (await getSSRImageFromServer(thisClothing.value.imgPath, 512))?.value.document?.imgBlob || ""; |
| 206 | + currentImgPath.value = localClothing.value.document!.imgPath; |
| 207 | + onMounted(() => { load(); }); |
207 | 208 | } |
208 | 209 |
|
209 | 210 |
|
|
225 | 226 | const diff = getDiff(storedClothing.value.document!, newClothingData); |
226 | 227 | localClothing.value.document = applyDiff(localClothing.value.document!, diff); |
227 | 228 | } |
| 229 | +
|
| 230 | + // Sync imgPath so useImage re-fetches new image |
| 231 | + if (newClothingData.imgPath !== currentImgPath.value) { |
| 232 | + currentImgPath.value = newClothingData.imgPath; |
| 233 | + } |
228 | 234 | } |
229 | 235 | } |
230 | 236 | } |
|
280 | 286 |
|
281 | 287 |
|
282 | 288 | // Triggered when new image was uploaded |
283 | | - async function updateImage(fileName: string) { |
| 289 | + function updateImage(fileName: string) { |
284 | 290 | if (!fileName) throw("Error: Image was uploaded without file name?"); |
285 | 291 |
|
286 | 292 | localClothing.value.document!.imgPath = fileName; |
287 | 293 | console.debug("DEBUG - updateImage: Setting imgPath of clothing to " + localClothing.value.document!.imgPath); |
288 | 294 |
|
289 | | - thisClothingImgBlob.value = (await getImageFromServer(fileName, 512))?.imgBlob || ""; |
| 295 | + currentImgPath.value = fileName; |
290 | 296 | } |
291 | 297 |
|
292 | 298 |
|
|
0 commit comments