From a39e22b0a88125c133e20589d7f1830b9b933183 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Tue, 3 Dec 2024 14:00:48 -0500 Subject: [PATCH] Add new dashboard --- .../src/lib/components/AdventureModal.svelte | 1 - frontend/src/locales/de.json | 3 +- frontend/src/locales/en.json | 3 +- frontend/src/locales/es.json | 3 +- frontend/src/locales/fr.json | 3 +- frontend/src/locales/it.json | 3 +- frontend/src/locales/nl.json | 3 +- frontend/src/locales/pl.json | 3 +- frontend/src/locales/sv.json | 3 +- frontend/src/locales/zh.json | 3 +- frontend/src/routes/dashboard/+page.server.ts | 53 +++++++++ frontend/src/routes/dashboard/+page.svelte | 107 ++++++++++++++++++ frontend/src/routes/settings/+page.svelte | 4 +- 13 files changed, 181 insertions(+), 11 deletions(-) create mode 100644 frontend/src/routes/dashboard/+page.server.ts create mode 100644 frontend/src/routes/dashboard/+page.svelte diff --git a/frontend/src/lib/components/AdventureModal.svelte b/frontend/src/lib/components/AdventureModal.svelte index 3d64599..c0dc277 100644 --- a/frontend/src/lib/components/AdventureModal.svelte +++ b/frontend/src/lib/components/AdventureModal.svelte @@ -444,7 +444,6 @@ headers: { 'Content-Type': 'application/json' }, - credentials: 'include', body: JSON.stringify(adventure) }); let data = await res.json(); diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 4e2d111..415cf84 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -294,7 +294,8 @@ "join_discord_desc": "um Ihre eigenen Fotos zu teilen. \nVeröffentlichen Sie sie im", "photo_by": "Foto von", "change_password_error": "Passwort kann nicht geändert werden. \nUngültiges aktuelles Passwort oder ungültiges neues Passwort.", - "current_password": "Aktuelles Passwort" + "current_password": "Aktuelles Passwort", + "password_change_lopout_warning": "Nach der Passwortänderung werden Sie abgemeldet." }, "checklist": { "add_item": "Artikel hinzufügen", diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index ad7f36d..3394e55 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -294,7 +294,8 @@ "join_discord": "Join the Discord", "join_discord_desc": "to share your own photos. Post them in the #travel-share channel.", "current_password": "Current Password", - "change_password_error": "Unable to change password. Invalid current password or invalid new password." + "change_password_error": "Unable to change password. Invalid current password or invalid new password.", + "password_change_lopout_warning": "You will be logged out after changing your password." }, "collection": { "collection_created": "Collection created successfully!", diff --git a/frontend/src/locales/es.json b/frontend/src/locales/es.json index 9d600c9..4061d5a 100644 --- a/frontend/src/locales/es.json +++ b/frontend/src/locales/es.json @@ -294,7 +294,8 @@ "join_discord_desc": "para compartir tus propias fotos. \nPublicarlos en el", "photo_by": "Foto por", "change_password_error": "No se puede cambiar la contraseña. \nContraseña actual no válida o contraseña nueva no válida.", - "current_password": "Contraseña actual" + "current_password": "Contraseña actual", + "password_change_lopout_warning": "Se cerrará su sesión después de cambiar su contraseña." }, "checklist": { "add_item": "Agregar artículo", diff --git a/frontend/src/locales/fr.json b/frontend/src/locales/fr.json index d530c31..f2a8061 100644 --- a/frontend/src/locales/fr.json +++ b/frontend/src/locales/fr.json @@ -294,7 +294,8 @@ "join_discord_desc": "pour partager vos propres photos. \nPostez-les dans le", "photo_by": "Photo par", "change_password_error": "Impossible de changer le mot de passe. \nMot de passe actuel invalide ou nouveau mot de passe invalide.", - "current_password": "Mot de passe actuel" + "current_password": "Mot de passe actuel", + "password_change_lopout_warning": "Vous serez déconnecté après avoir modifié votre mot de passe." }, "checklist": { "add_item": "Ajouter un article", diff --git a/frontend/src/locales/it.json b/frontend/src/locales/it.json index 124a12f..7246be6 100644 --- a/frontend/src/locales/it.json +++ b/frontend/src/locales/it.json @@ -294,7 +294,8 @@ "join_discord_desc": "per condividere le tue foto. \nPubblicateli in", "photo_by": "Foto di", "change_password_error": "Impossibile modificare la password. \nPassword attuale non valida o nuova password non valida.", - "current_password": "password attuale" + "current_password": "password attuale", + "password_change_lopout_warning": "Verrai disconnesso dopo aver modificato la password." }, "checklist": { "add_item": "Aggiungi articolo", diff --git a/frontend/src/locales/nl.json b/frontend/src/locales/nl.json index 534cfc6..e48ff1a 100644 --- a/frontend/src/locales/nl.json +++ b/frontend/src/locales/nl.json @@ -294,7 +294,8 @@ "join_discord_desc": "om uw eigen foto's te delen. \nPlaats ze in de", "photo_by": "Foto door", "change_password_error": "Kan wachtwoord niet wijzigen. \nOngeldig huidig ​​wachtwoord of ongeldig nieuw wachtwoord.", - "current_password": "Huidig ​​wachtwoord" + "current_password": "Huidig ​​wachtwoord", + "password_change_lopout_warning": "Na het wijzigen van uw wachtwoord wordt u uitgelogd." }, "checklist": { "add_item": "Artikel toevoegen", diff --git a/frontend/src/locales/pl.json b/frontend/src/locales/pl.json index 4eabed3..bea7a2c 100644 --- a/frontend/src/locales/pl.json +++ b/frontend/src/locales/pl.json @@ -294,7 +294,8 @@ "join_discord": "Dołącz do Discorda", "join_discord_desc": "aby podzielić się swoimi zdjęciami. Zamieść je w kanale #travel-share.", "change_password_error": "Nie można zmienić hasła. \nNieprawidłowe bieżące hasło lub nieprawidłowe nowe hasło.", - "current_password": "Aktualne hasło" + "current_password": "Aktualne hasło", + "password_change_lopout_warning": "Po zmianie hasła nastąpi wylogowanie." }, "collection": { "collection_created": "Kolekcja została pomyślnie utworzona!", diff --git a/frontend/src/locales/sv.json b/frontend/src/locales/sv.json index 9828d2b..035fef4 100644 --- a/frontend/src/locales/sv.json +++ b/frontend/src/locales/sv.json @@ -294,7 +294,8 @@ "join_discord_desc": "för att dela dina egna foton. \nLägg upp dem i", "photo_by": "Foto av", "change_password_error": "Det går inte att ändra lösenord. \nOgiltigt nuvarande lösenord eller ogiltigt nytt lösenord.", - "current_password": "Aktuellt lösenord" + "current_password": "Aktuellt lösenord", + "password_change_lopout_warning": "Du kommer att loggas ut efter att du har ändrat ditt lösenord." }, "checklist": { "add_item": "Lägg till objekt", diff --git a/frontend/src/locales/zh.json b/frontend/src/locales/zh.json index 70e6299..fdaf746 100644 --- a/frontend/src/locales/zh.json +++ b/frontend/src/locales/zh.json @@ -294,7 +294,8 @@ "join_discord_desc": "分享您自己的照片。\n将它们张贴在", "photo_by": "摄影:", "change_password_error": "无法更改密码。\n当前密码无效或新密码无效。", - "current_password": "当前密码" + "current_password": "当前密码", + "password_change_lopout_warning": "更改密码后您将退出。" }, "checklist": { "add_item": "添加项目", diff --git a/frontend/src/routes/dashboard/+page.server.ts b/frontend/src/routes/dashboard/+page.server.ts new file mode 100644 index 0000000..5db5aef --- /dev/null +++ b/frontend/src/routes/dashboard/+page.server.ts @@ -0,0 +1,53 @@ +import { redirect } from '@sveltejs/kit'; +import type { PageServerLoad } from './$types'; +const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL']; +import type { Adventure } from '$lib/types'; + +const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000'; + +export const load = (async (event) => { + if (!event.locals.user) { + return redirect(302, '/login'); + } else { + let adventures: Adventure[] = []; + + let initialFetch = await event.fetch(`${serverEndpoint}/api/adventures/`, { + headers: { + Cookie: `sessionid=${event.cookies.get('sessionid')}` + }, + credentials: 'include' + }); + + let stats = null; + + let res = await event.fetch(`${serverEndpoint}/api/stats/counts/`, { + headers: { + Cookie: `sessionid=${event.cookies.get('sessionid')}` + } + }); + if (!res.ok) { + console.error('Failed to fetch user stats'); + } else { + stats = await res.json(); + } + + if (!initialFetch.ok) { + let error_message = await initialFetch.json(); + console.error(error_message); + console.error('Failed to fetch visited adventures'); + return redirect(302, '/login'); + } else { + let res = await initialFetch.json(); + let visited = res.results as Adventure[]; + // only get the first 3 adventures or less if there are less than 3 + adventures = visited.slice(0, 3); + } + + return { + props: { + adventures, + stats + } + }; + } +}) satisfies PageServerLoad; diff --git a/frontend/src/routes/dashboard/+page.svelte b/frontend/src/routes/dashboard/+page.svelte new file mode 100644 index 0000000..fcf9d51 --- /dev/null +++ b/frontend/src/routes/dashboard/+page.svelte @@ -0,0 +1,107 @@ + + +
+ +
+

Welcome back, {user?.first_name}!

+
+ + +
+
+
+ +
+
Countries Visited
+
{stats.country_count}
+
+
+
+ +
+
Total Adventures
+
{stats.adventure_count}
+
+
+
+ +
+
Total Visited Regions
+
{stats.visited_region_count}
+
+
+ + +

Recent Adventures

+
+ {#each recentAdventures as adventure} + + {/each} +
+ + +
+
+ Inspiration +
+
+

Get Inspired

+

"{inspirationQuote}"

+
+ +
+
+
+
+ + + Dashboard | AdventureLog + + diff --git a/frontend/src/routes/settings/+page.svelte b/frontend/src/routes/settings/+page.svelte index 90e3195..d15d26b 100644 --- a/frontend/src/routes/settings/+page.svelte +++ b/frontend/src/routes/settings/+page.svelte @@ -151,7 +151,9 @@ placeholder={$t('settings.confirm_new_password')} class="block mb-2 input input-bordered w-full max-w-xs" /> - +
+ +