Daniel Bohry пре 9 месеци
родитељ
комит
26005cff32
3 измењених фајлова са 69 додато и 22 уклоњено
  1. 8 4
      src/routes/insights/+page.svelte
  2. 9 15
      src/routes/portfolio/+page.svelte
  3. 52 3
      src/routes/profile/+page.svelte

+ 8 - 4
src/routes/insights/+page.svelte

@@ -9,7 +9,7 @@
 	let authToken;
 	let data = {};
 	let isLoading = true;
-	let currency = 'USD';
+	let currency;
 	let total = 0;
 
 	onMount(() => {
@@ -21,13 +21,17 @@
 			if (!auth || !auth.token) {
 				await goto('/logout');
 			} else {
+
+				const defaultCurrency = localStorage.getItem('defaultCurrency');
+				currency = defaultCurrency || 'USD';
+
 				authToken = auth.token;
-				await fetchPortfolio();
+				await fetchPortfolio(currency);
 			}
 		});
 	});
 
-	async function fetchPortfolio() {
+	async function fetchPortfolio(currency) {
 		try {
 			const response = await getRequest(
 				`${import.meta.env.VITE_STOCKS_HOST}/api/portfolios?currency=${currency}`,
@@ -64,7 +68,7 @@
 	function updateCurrency(event) {
 		currency = event.target.value;
 		isLoading = true;
-		fetchPortfolio();
+		fetchPortfolio(currency);
 	}
 </script>
 

+ 9 - 15
src/routes/portfolio/+page.svelte

@@ -16,7 +16,7 @@
 	let showModal = false;
 	let searchStockResult = [];
 	let orderBy = 'total';
-	let currency = 'USD';
+	let currency;
 	let hasChanges = false;
 	let showDeleteConfirm = false;
 	let stockToDelete = null;
@@ -44,6 +44,10 @@
 			if (!auth || !auth.token) {
 				await goto('/logout');
 			} else {
+
+				const defaultCurrency = localStorage.getItem('defaultCurrency');
+				currency = defaultCurrency || 'USD';
+
 				authToken = auth.token;
 				await fetchPortfolio();
 			}
@@ -299,10 +303,10 @@
 			Add
 		</button>
 
-		<select class="form-control order-select" on:change={updateCurrency}>
-			<option value="brl">BRL</option>
-			<option value="eur">EURO</option>
-			<option value="usd" selected>USD</option>
+		<select class="form-control order-select" on:change={updateCurrency} value={currency}>
+			<option value="BRL">BRL</option>
+			<option value="EUR">EURO</option>
+			<option value="USD" selected>USD</option>
 		</select>
 
 		<select class="form-control order-select" on:change={updateOrderBy}>
@@ -607,16 +611,6 @@
         animation: fadeIn 0.2s ease;
     }
 
-    .modal-confirm h2 {
-        margin-bottom: 0.5rem;
-        font-size: 1.25rem;
-    }
-
-    .modal-confirm p {
-        margin-bottom: 1.5rem;
-        color: #555;
-    }
-
     .modal-actions {
         display: flex;
         justify-content: center;

+ 52 - 3
src/routes/profile/+page.svelte

@@ -7,6 +7,7 @@
 	let isAuthenticated = false;
 	let isLoading = true;
 	let user = null;
+	let currency = 'USD';
 
 	$: authentication.subscribe((value) => {
 		isAuthenticated = !!value;
@@ -21,7 +22,14 @@
 			if (storedAuth) {
 				authentication.set(JSON.parse(storedAuth));
 			} else {
-				goto('/login');
+				goto('/logout');
+			}
+
+			const defaultCurrency = localStorage.getItem('defaultCurrency');
+			if (defaultCurrency) {
+				currency = defaultCurrency;
+			} else {
+				localStorage.setItem('defaultCurrency', 'USD');
 			}
 		} catch (error) {
 			console.error('Error parsing stored auth:', error);
@@ -33,6 +41,12 @@
 	function logout() {
 		window.location.href = '/logout';
 	}
+
+	function updateCurrency(event) {
+		currency = event.target.value;
+		localStorage.setItem('defaultCurrency', currency);
+	}
+
 </script>
 
 <svelte:head>
@@ -45,13 +59,48 @@
 		<p>Loading...</p>
 	{:else if isAuthenticated}
 		<p>You are logged in as <strong>{user.username}</strong>!</p>
+
+		<div class="button-container">
+			<select class="form-control order-select" on:change={updateCurrency} value={currency}>
+				<option value="BRL">BRL</option>
+				<option value="EUR">EUR</option>
+				<option value="USD" selected>USD</option>
+			</select>
+		</div>
+
+		<div class="button-container">
+			<select class="form-control order-select">
+				<option value="light">Light</option>
+				<!--				<option value="dark">Dark</option>-->
+			</select>
+		</div>
+
 		<button class="logout-button" on:click={logout}>Logout</button>
 	{/if}
 </div>
 
 <style>
-    input::placeholder {
-        opacity: 0.5;
+    .button-container {
+        display: flex;
+        gap: 10px;
+        margin-bottom: 1rem;
+        align-items: center;
+        justify-content: flex-end;
+    }
+
+    .order-select {
+        width: 200px;
+        padding: 0.5rem;
+        border-radius: 8px;
+        border: 1px solid #ddd;
+        font-size: 1rem;
+        background-color: #f9f9f9;
+        transition: border-color 0.3s ease;
+    }
+
+    .order-select:focus {
+        border-color: #2980b9;
+        outline: none;
     }
 
     .logout-button {