Daniel Bohry 9 hónapja
szülő
commit
740e9087d9
1 módosított fájl, 9 hozzáadás és 1 törlés
  1. 9 1
      src/routes/portfolio/+page.svelte

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

@@ -11,6 +11,7 @@
     let isLoading = true;
     let showModal = false;
     let searchStockResult = [];
+    let orderBy = "total";
 
     onMount(() => {
         const unsubscribe = authentication.subscribe(value => {
@@ -53,7 +54,14 @@
     async function update(response) {
         const portfolio = await response;
         if (portfolio?.length > 0) {
-            result = portfolio[0].stocks.sort((a, b) => a.code.localeCompare(b.code));
+            if (orderBy === "code") {
+                result = portfolio[0].stocks.sort((a, b) => a.code.localeCompare(b.code));
+            }
+
+            if (orderBy === "total") {
+                result = portfolio[0].stocks.sort((a, b) => a.total - b.total);
+            }
+
             totalValue = portfolio[0].totalValue;
             totalAssets = portfolio[0].totalAssets;
             portfolioId = portfolio[0].id;