From 57d9ff8ed0f79f206fb7f2eb234eb9f334bc18fd Mon Sep 17 00:00:00 2001 From: DariusTFox24 Date: Tue, 4 Jan 2022 01:22:27 +0200 Subject: [PATCH] Finished frontend implementation with api --- client/package-lock.json | 13 ++++++ client/package.json | 1 + client/src/AccountCard.svelte | 12 +----- client/src/App.svelte | 26 ++++++++++-- client/src/CheckNotifications.svelte | 59 ++++++++++++++++------------ client/src/CreateAccount.svelte | 4 ++ client/src/InputField.svelte | 2 +- client/src/Login.svelte | 17 +++++++- client/src/MainPage.svelte | 19 ++++++--- client/src/SendMoney.svelte | 4 ++ client/src/api.js | 50 +++++++++++++++++++++-- 11 files changed, 157 insertions(+), 50 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index 407d5b5..ed105e1 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -23,6 +23,7 @@ "rollup-plugin-svelte": "^7.0.0", "rollup-plugin-terser": "^7.0.0", "svelte": "^3.0.0", + "svelte-keydown": "^0.4.0", "svelte-preprocess": "^4.9.8" } }, @@ -1947,6 +1948,12 @@ "node": ">= 8" } }, + "node_modules/svelte-keydown": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/svelte-keydown/-/svelte-keydown-0.4.0.tgz", + "integrity": "sha512-a0S5m+u78FE1jgpuSCZPtgh/KhwNAO9t8kkcBkK1sK9ZiVC+Iu5XOCqIu1F+PEyenRTIxGaA4yr6KAsYFB6kkQ==", + "dev": true + }, "node_modules/svelte-preprocess": { "version": "4.9.8", "resolved": "https://registry.npmjs.org/svelte-preprocess/-/svelte-preprocess-4.9.8.tgz", @@ -3700,6 +3707,12 @@ "integrity": "sha512-4DrCEJoBvdR689efHNSxIQn2pnFwB7E7j2yLEJtHE/P8hxwZWIphCtJ8are7bjl/iVMlcEf5uh5pJ68IwR09vQ==", "dev": true }, + "svelte-keydown": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/svelte-keydown/-/svelte-keydown-0.4.0.tgz", + "integrity": "sha512-a0S5m+u78FE1jgpuSCZPtgh/KhwNAO9t8kkcBkK1sK9ZiVC+Iu5XOCqIu1F+PEyenRTIxGaA4yr6KAsYFB6kkQ==", + "dev": true + }, "svelte-preprocess": { "version": "4.9.8", "resolved": "https://registry.npmjs.org/svelte-preprocess/-/svelte-preprocess-4.9.8.tgz", diff --git a/client/package.json b/client/package.json index 677abca..b9a74f2 100644 --- a/client/package.json +++ b/client/package.json @@ -17,6 +17,7 @@ "rollup-plugin-svelte": "^7.0.0", "rollup-plugin-terser": "^7.0.0", "svelte": "^3.0.0", + "svelte-keydown": "^0.4.0", "svelte-preprocess": "^4.9.8" }, "dependencies": { diff --git a/client/src/AccountCard.svelte b/client/src/AccountCard.svelte index 7220394..1a1bde6 100644 --- a/client/src/AccountCard.svelte +++ b/client/src/AccountCard.svelte @@ -21,7 +21,7 @@ export let balance="5425"; export let iban="RONFOX62188921"; export let isExpanded=false; - let transactions=[]; + export let transactions=[]; export let accountId; let copied = false; @@ -55,14 +55,6 @@ }); } - onMount( () => { - gettransactions($token, accountId).then( result => { - if(result.status == "success") { - transactions = result.transactions; - transactions.sort((e1, e2) => new Date(e2.datetime) - new Date(e1.datetime)); - } - }); - }) @@ -82,7 +74,7 @@
-

Balance: {balance}{currency}

+

Balance: {amountToString(balance)}{currency}

diff --git a/client/src/App.svelte b/client/src/App.svelte index ed8e7f4..4e8c1e6 100644 --- a/client/src/App.svelte +++ b/client/src/App.svelte @@ -42,21 +42,39 @@ }) setContext("user", user); + const refreshAccounts = writable(null); + setContext("refreshAccounts", refreshAccounts); const accounts = readable(null, set => { - const unsubscribe = userToken.subscribe(token => { - if(token == null) { + function getAccounts(token){ + if(token==null){ set(null); }else{ - getaccountlist(token) - .then(result =>{ + getaccountlist(token) + .then(result => { set(result); }) } + } + + let token = null; + + refreshAccounts.set( () => { + getAccounts(token); + }); + + const unsubscribe = userToken.subscribe(newToken => { + token = newToken; + getAccounts(token); }) + const intervalId = setInterval(() => { + getAccounts(token); + }, 10000); + return () => { unsubscribe(); + clearInterval(intervalId); } }) diff --git a/client/src/CheckNotifications.svelte b/client/src/CheckNotifications.svelte index 3ee4458..50ed2a8 100644 --- a/client/src/CheckNotifications.svelte +++ b/client/src/CheckNotifications.svelte @@ -39,35 +39,44 @@
- {#each notifications as notification,i (i)} -
onNotificationClick(notification.id)} in:slide={{delay:100*i}} out:slide={{delay:50*(notifications.length-i)}}> - - -
- {notification.body} -
+ {#if notifications.length > 0} + {#each notifications as notification,i (i)} +
onNotificationClick(notification.id)} in:slide={{delay:100*i}} out:slide={{delay:50*(notifications.length-i)}}> + + +
+ {notification.body} +
-
-
- at {new Date(notification.datetime).toLocaleString()} +
+
+ at {new Date(notification.datetime).toLocaleString()} +
-
-
- {#if !notification.read} - - - - {:else} - - - - {/if} +
+ {#if !notification.read} + + + + {:else} + + + + {/if} +
+ + +
+ {/each} + {:else} + +
+ No notifications.
- -
-
- {/each} +
+ {/if} +
diff --git a/client/src/CreateAccount.svelte b/client/src/CreateAccount.svelte index acbc6ba..a9e4776 100644 --- a/client/src/CreateAccount.svelte +++ b/client/src/CreateAccount.svelte @@ -12,6 +12,7 @@ import { getContext } from "svelte"; const token = getContext("token"); + const refreshAccounts = getContext("refreshAccounts"); const dispatch = createEventDispatcher(); @@ -32,6 +33,9 @@ const result = await createaccount($token, name, currency, type); if(result.status == "success") { dispatch("createPopup",{type:"create_acc_success"}); + if($refreshAccounts){ + $refreshAccounts(); + } }else{ dispatch("createPopup",{type:"create_acc_failed", reason:"Failed to create account. Error:"+result.status}); } diff --git a/client/src/InputField.svelte b/client/src/InputField.svelte index de1978d..41c0366 100644 --- a/client/src/InputField.svelte +++ b/client/src/InputField.svelte @@ -9,7 +9,7 @@
- +