diff --git a/pkg/web/src/routes/login/+page.svelte b/pkg/web/src/routes/login/+page.svelte index fdee728d..3e8ed9f5 100644 --- a/pkg/web/src/routes/login/+page.svelte +++ b/pkg/web/src/routes/login/+page.svelte @@ -6,6 +6,7 @@ var username = ''; var password = ''; var qpUserLoggedIn = false; + var ratings = []; onMount(async () => { qpUserLoggedIn = checkQPUserLoggedIn(); @@ -34,6 +35,39 @@ qpUserLoggedIn = checkQPUserLoggedIn(); } + $: if (qpUserLoggedIn) { + updateRatings(); + } + + async function updateRatings() { + ratings = []; + const res = await fetch(`${PUBLIC_BACKEND_ENDPOINT}api/ratings`, { + method: 'GET', + credentials: 'same-origin' + }); + if (!res.ok) { + ratings = ['Something went wrong retrieving your ratings.']; + return; + } + const json = await res.json(); + + var newRatings = []; + json.ratings.forEach((rating) => { + newRatings.push( + `Rating ID: ${rating.id} (stars=${rating.stars}, pizza_id=${rating.pizza_id})` + ); + }); + ratings = newRatings; + } + + async function deleteRatings() { + await fetch(`${PUBLIC_BACKEND_ENDPOINT}api/ratings`, { + method: 'DELETE', + credentials: 'same-origin' + }); + location.reload(); + } + async function handleLogout() { document.cookie = 'qp_user_token=; Expires=Thu, 01 Jan 1970 00:00:01 GMT'; qpUserLoggedIn = false; @@ -41,16 +75,30 @@ {#if qpUserLoggedIn} - - - Hello there! You are currently logged in. - - + + + Your Pizza Ratings: + + + {#if ratings.length === 0} + No ratings yet + {:else} + {#each ratings as rating} + {rating} + {/each} + {/if} + + + Clear Ratings Logout