|
5 | 5 | * Created Date: 2025-09-10 17:37:07 |
6 | 6 | * Author: 3urobeat |
7 | 7 | * |
8 | | - * Last Modified: 2026-03-27 19:03:05 |
| 8 | + * Last Modified: 2026-03-29 18:50:04 |
9 | 9 | * Modified By: 3urobeat |
10 | 10 | * |
11 | 11 | * Copyright (c) 2025 - 2026 3urobeat <https://github.com/3urobeat> |
|
243 | 243 | import { defaultSortMode } from "~/model/sort-modes"; |
244 | 244 | import { responseIndicatorFailure, responseIndicatorSuccess } from "~/composables/responseIndicator"; |
245 | 245 | import threedModelViewer from "~/components/threedModelViewer.vue"; |
| 246 | + import { getAllClothesFromServer, getOutfitFromServer, rmOutfitToServer, setOutfitToServer } from "~/composables/storage"; |
246 | 247 |
|
247 | 248 |
|
248 | 249 | // Get from cache |
|
252 | 253 | // Refs |
253 | 254 | const thisOutfit: Ref<Outfit> = ref({ id: "", title: "", clothes: [], labelIDs: [], previewImgPath: "", addedTimestamp: 0, modifiedTimestamp: 0 }); |
254 | 255 | const bodyPartLabels: Ref<Label[]> = ref([]); |
255 | | - const storedClothes: Ref<Clothing[]> = ref([]); // Edit Mode only |
| 256 | + const storedClothes: Ref<Clothing[]> = ref([]); |
| 257 | + storedClothes.value = await getAllClothesFromServer(); |
256 | 258 |
|
257 | 259 |
|
258 | 260 | // Check if edit mode is enabled based on if name of this route is outfits-view or outfits-edit |
259 | 261 | const editModeEnabled = (useRoute().name == "outfits-edit"); |
260 | 262 |
|
261 | 263 | // Get ID of the outfit to view from query parameters |
262 | | - const outfitId = useRoute().query.id || "new"; |
| 264 | + const outfitId = (useRoute().query.id || "new").toString(); |
263 | 265 |
|
264 | 266 | // Redirect to edit page if view was opened with id new |
265 | 267 | if (!editModeEnabled && outfitId == "new") useRouter().push("/outfits/edit?id=new"); |
|
272 | 274 | } |
273 | 275 |
|
274 | 276 |
|
275 | | - // Get outfits and their data |
276 | | - let clothingRes = await useFetch("/api/get-all-clothes"); |
277 | | - storedClothes.value = clothingRes.data.value!; // TODO: Error handling |
278 | | -
|
279 | | -
|
280 | | -
|
281 | 277 | // Load images for clothes // TODO: Lazy load |
282 | 278 | onMounted(async () => { |
283 | 279 | // Get outfit data if not new |
284 | 280 | if (outfitId != "new") { |
285 | | - const outfitRes = await fetch("/api/get-outfit", { |
286 | | - method: "POST", |
287 | | - headers: { |
288 | | - "Content-Type": "application/json" |
289 | | - }, |
290 | | - body: JSON.stringify({ |
291 | | - id: outfitId |
292 | | - }) |
293 | | - }); |
294 | | -
|
295 | | - thisOutfit.value = await outfitRes.json(); // TODO: Error handling |
| 281 | + thisOutfit.value = await getOutfitFromServer(outfitId); |
296 | 282 | } |
297 | 283 | }); |
298 | 284 |
|
|
356 | 342 |
|
357 | 343 | // Send request to API if user confirmed |
358 | 344 | if (confirmed) { |
359 | | - const res = await fetch("/api/rm-outfit", { |
360 | | - method: "POST", |
361 | | - headers: { |
362 | | - "Content-Type": "application/json" |
363 | | - }, |
364 | | - body: JSON.stringify({ |
365 | | - id: thisOutfit.value.id |
366 | | - }) |
367 | | - }); |
368 | | -
|
369 | | - const resBody = await res.json(); |
| 345 | + const resBody = await rmOutfitToServer(thisOutfit.value.id); |
370 | 346 |
|
371 | 347 | // Indicate success/failure |
372 | 348 | if (resBody.success) { |
|
389 | 365 | async function saveChanges() { |
390 | 366 |
|
391 | 367 | // Send data to API |
392 | | - const res = await fetch("/api/set-outfit", { |
393 | | - method: "POST", |
394 | | - headers: { |
395 | | - "Content-Type": "application/json" |
396 | | - }, |
397 | | - body: JSON.stringify({ |
398 | | - outfit: thisOutfit.value |
399 | | - }) |
400 | | - }); |
401 | | -
|
402 | | - const resBody = await res.json(); |
| 368 | + const resBody = await setOutfitToServer(thisOutfit.value); |
403 | 369 |
|
404 | 370 | // Update local refs depending on success/failure and indicate result |
405 | 371 | if (resBody.success) { |
|
0 commit comments