From fd1332a3df191577e91c6d846a8b5db1747099fd Mon Sep 17 00:00:00 2001
From: Zach Berwaldt <zberwaldt@tutamail.com>
Date: Fri, 15 Mar 2024 22:00:10 -0400
Subject: cleanup

---
 fe/src/lib/PreferencesForm.svelte | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

(limited to 'fe/src/lib/PreferencesForm.svelte')

diff --git a/fe/src/lib/PreferencesForm.svelte b/fe/src/lib/PreferencesForm.svelte
index 875393c..74b8a63 100644
--- a/fe/src/lib/PreferencesForm.svelte
+++ b/fe/src/lib/PreferencesForm.svelte
@@ -2,6 +2,7 @@
   import { user, preferences, token } from "../stores/auth";
   import { createEventDispatcher, onDestroy, onMount } from "svelte";
   import type { User } from "../types";
+  import { apiURL } from "../utils";
 
   export let open: boolean;
 
@@ -13,9 +14,10 @@
 
   const unsubscribe = preferences.subscribe(
     (value: any) => {
-        console.log('update value: ', value);
-      color = value.color;
-      selectedSize = value.size_id;
+      if (value) {
+        color = value.color;
+        selectedSize = value.size_id;
+      }
     },
   );
 
@@ -24,7 +26,7 @@
   }
 
   async function updateUserPreferences() {
-    const res = await fetch("http://localhost:8080/api/v1/user/preferences", {
+    const res = await fetch(apiURL("user/preferences"), {
       method: "PATCH",
       headers: {
         Authorization: `Bearer ${$token}`,
@@ -34,8 +36,7 @@
   }
 
   async function getUserPreferences() {
-    const res = await fetch(
-      `http://localhost:8080/api/v1/user/${($user as User)!.id}/preferences`,
+    const res = await fetch(apiURL(`user/${($user as User)!.id}/preferences`),
       {
         method: "GET",
         headers: {
@@ -61,7 +62,7 @@
   }
 
   onMount(() => {
-    fetch("http://localhost:8080/api/v1/sizes", {
+    fetch(apiURL("sizes"), {
       method: "GET",
       headers: {
         Authorization: `Bearer ${$token}`,
-- 
cgit v1.1

