From 4d17484f86e7a2e475ee698152066bd22fb8c499 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Sun, 8 Sep 2024 13:53:50 -0400 Subject: [PATCH] Toggle public profile from settings page. --- backend/server/users/serializers.py | 6 ++++-- frontend/src/lib/config.ts | 3 +-- frontend/src/routes/settings/+page.server.ts | 9 +++++++++ frontend/src/routes/settings/+page.svelte | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/backend/server/users/serializers.py b/backend/server/users/serializers.py index 5d3e3b4..a6e6577 100644 --- a/backend/server/users/serializers.py +++ b/backend/server/users/serializers.py @@ -142,7 +142,7 @@ class UserDetailsSerializer(serializers.ModelSerializer): return username class Meta: - extra_fields = ['profile_pic'] + extra_fields = ['profile_pic', 'uuid', 'public_profile'] profile_pic = serializers.ImageField(required=False) # see https://github.com/iMerica/dj-rest-auth/issues/181 # UserModel.XYZ causing attribute error while importing other @@ -160,10 +160,12 @@ class UserDetailsSerializer(serializers.ModelSerializer): extra_fields.append('date_joined') if hasattr(UserModel, 'is_staff'): extra_fields.append('is_staff') + if hasattr(UserModel, 'public_profile'): + extra_fields.append('public_profile') class Meta(UserDetailsSerializer.Meta): model = CustomUser - fields = UserDetailsSerializer.Meta.fields + ('profile_pic',) + fields = UserDetailsSerializer.Meta.fields + ('profile_pic', 'uuid', 'public_profile') model = UserModel fields = ('pk', *extra_fields) diff --git a/frontend/src/lib/config.ts b/frontend/src/lib/config.ts index f063a68..59d6f4a 100644 --- a/frontend/src/lib/config.ts +++ b/frontend/src/lib/config.ts @@ -1,5 +1,4 @@ export let appVersion = 'Web v0.6.0'; -export let versionChangelog = 'https://github.com/seanmorley15/AdventureLog/releases/tag/v0.5.2'; +export let versionChangelog = 'https://github.com/seanmorley15/AdventureLog/releases/tag/v0.6.0'; export let appTitle = 'AdventureLog'; export let copyrightYear = '2024'; -// config for the frontend diff --git a/frontend/src/routes/settings/+page.server.ts b/frontend/src/routes/settings/+page.server.ts index efd758a..9b97697 100644 --- a/frontend/src/routes/settings/+page.server.ts +++ b/frontend/src/routes/settings/+page.server.ts @@ -45,6 +45,7 @@ export const actions: Actions = { let first_name = formData.get('first_name') as string | null | undefined; let last_name = formData.get('last_name') as string | null | undefined; let profile_pic = formData.get('profile_pic') as File | null | undefined; + let public_profile = formData.get('public_profile') as string | null | undefined | boolean; const resCurrent = await fetch(`${endpoint}/auth/user/`, { headers: { @@ -56,6 +57,13 @@ export const actions: Actions = { return fail(resCurrent.status, await resCurrent.json()); } + if (public_profile === 'on') { + public_profile = true; + } else { + public_profile = false; + } + console.log(public_profile); + let currentUser = (await resCurrent.json()) as User; if (username === currentUser.username || !username) { @@ -84,6 +92,7 @@ export const actions: Actions = { if (profile_pic) { formDataToSend.append('profile_pic', profile_pic); } + formDataToSend.append('public_profile', public_profile.toString()); let res = await fetch(`${endpoint}/auth/user/`, { method: 'PATCH', diff --git a/frontend/src/routes/settings/+page.svelte b/frontend/src/routes/settings/+page.svelte index cb7bd28..61e2d57 100644 --- a/frontend/src/routes/settings/+page.svelte +++ b/frontend/src/routes/settings/+page.svelte @@ -111,6 +111,24 @@ id="profile_pic" class="file-input file-input-bordered w-full max-w-xs mb-2" />
+
+
+ +
+