1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-19 12:59:36 +02:00

Toggle public profile from settings page.

This commit is contained in:
Sean Morley 2024-09-08 13:53:50 -04:00
parent c867494a17
commit 4d17484f86
4 changed files with 32 additions and 4 deletions

View file

@ -142,7 +142,7 @@ class UserDetailsSerializer(serializers.ModelSerializer):
return username return username
class Meta: class Meta:
extra_fields = ['profile_pic'] extra_fields = ['profile_pic', 'uuid', 'public_profile']
profile_pic = serializers.ImageField(required=False) profile_pic = serializers.ImageField(required=False)
# see https://github.com/iMerica/dj-rest-auth/issues/181 # see https://github.com/iMerica/dj-rest-auth/issues/181
# UserModel.XYZ causing attribute error while importing other # UserModel.XYZ causing attribute error while importing other
@ -160,10 +160,12 @@ class UserDetailsSerializer(serializers.ModelSerializer):
extra_fields.append('date_joined') extra_fields.append('date_joined')
if hasattr(UserModel, 'is_staff'): if hasattr(UserModel, 'is_staff'):
extra_fields.append('is_staff') extra_fields.append('is_staff')
if hasattr(UserModel, 'public_profile'):
extra_fields.append('public_profile')
class Meta(UserDetailsSerializer.Meta): class Meta(UserDetailsSerializer.Meta):
model = CustomUser model = CustomUser
fields = UserDetailsSerializer.Meta.fields + ('profile_pic',) fields = UserDetailsSerializer.Meta.fields + ('profile_pic', 'uuid', 'public_profile')
model = UserModel model = UserModel
fields = ('pk', *extra_fields) fields = ('pk', *extra_fields)

View file

@ -1,5 +1,4 @@
export let appVersion = 'Web v0.6.0'; 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 appTitle = 'AdventureLog';
export let copyrightYear = '2024'; export let copyrightYear = '2024';
// config for the frontend

View file

@ -45,6 +45,7 @@ export const actions: Actions = {
let first_name = formData.get('first_name') as string | null | undefined; let first_name = formData.get('first_name') as string | null | undefined;
let last_name = formData.get('last_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 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/`, { const resCurrent = await fetch(`${endpoint}/auth/user/`, {
headers: { headers: {
@ -56,6 +57,13 @@ export const actions: Actions = {
return fail(resCurrent.status, await resCurrent.json()); 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; let currentUser = (await resCurrent.json()) as User;
if (username === currentUser.username || !username) { if (username === currentUser.username || !username) {
@ -84,6 +92,7 @@ export const actions: Actions = {
if (profile_pic) { if (profile_pic) {
formDataToSend.append('profile_pic', profile_pic); formDataToSend.append('profile_pic', profile_pic);
} }
formDataToSend.append('public_profile', public_profile.toString());
let res = await fetch(`${endpoint}/auth/user/`, { let res = await fetch(`${endpoint}/auth/user/`, {
method: 'PATCH', method: 'PATCH',

View file

@ -111,6 +111,24 @@
id="profile_pic" id="profile_pic"
class="file-input file-input-bordered w-full max-w-xs mb-2" class="file-input file-input-bordered w-full max-w-xs mb-2"
/><br /> /><br />
<div class="form-control">
<div
class="tooltip tooltip-info"
data-tip="With a public profile, users can share collections with you and view your profile on the users page."
>
<label class="label cursor-pointer">
<span class="label-text">Public Profile</span>
<input
id="public_profile"
name="public_profile"
type="checkbox"
class="toggle"
checked={user.public_profile}
/>
</label>
</div>
</div>
<button class="py-2 mt-2 px-4 btn btn-primary">Update</button> <button class="py-2 mt-2 px-4 btn btn-primary">Update</button>
</form> </form>
</div> </div>