feat: finish up the my account section for now
This commit is contained in:
parent
8a3bb89f8a
commit
acc4fa14b7
4 changed files with 72 additions and 69 deletions
|
@ -10,7 +10,7 @@
|
||||||
{{ props.user.username || "username" }} - {{ props.user.pronouns || "un/defined" }}
|
{{ props.user.username || "username" }} - {{ props.user.pronouns || "un/defined" }}
|
||||||
</p>
|
</p>
|
||||||
<div id="about-me">
|
<div id="about-me">
|
||||||
<span>About me</span>
|
{{ props.user.about || "about me" }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -74,8 +74,11 @@ const props = defineProps<{
|
||||||
}
|
}
|
||||||
|
|
||||||
#about-me {
|
#about-me {
|
||||||
margin-top: 4px;
|
background-color: #34200f;
|
||||||
padding: 4px;
|
border-radius: 12px;
|
||||||
|
|
||||||
|
margin-top: 32px;
|
||||||
|
padding: 16px;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
|
@ -7,16 +7,19 @@
|
||||||
<div class="user-data-fields">
|
<div class="user-data-fields">
|
||||||
<h3 class="subtitle">AVATAR</h3>
|
<h3 class="subtitle">AVATAR</h3>
|
||||||
<Button text="Change Avatar" :callback="changeAvatar"></Button>
|
<Button text="Change Avatar" :callback="changeAvatar"></Button>
|
||||||
<Button text="Remove Avatar" :callback="removeAvatar" style="margin-left: 10px; background-color: grey;"></Button>
|
<Button text="Remove Avatar" :callback="removeAvatar"
|
||||||
|
style="margin-left: 10px; background-color: grey;"></Button>
|
||||||
<h3 class="subtitle">DISPLAY NAME</h3>
|
<h3 class="subtitle">DISPLAY NAME</h3>
|
||||||
<input type="text" v-model="user.display_name" placeholder="Enter display name" />
|
<input class="profile-data-input" type="text" v-model="user.display_name" placeholder="Enter display name" />
|
||||||
<h3 class="subtitle">USERNAME</h3>
|
<h3 class="subtitle">USERNAME</h3>
|
||||||
<input type="text" v-model="user.username" placeholder="Enter username" />
|
<input class="profile-data-input" type="text" v-model="user.username" placeholder="Enter username" />
|
||||||
<h3 class="subtitle">PRONOUNS</h3>
|
<h3 class="subtitle">PRONOUNS</h3>
|
||||||
<input type="text" v-model="user.pronouns" placeholder="Enter pronouns" />
|
<input class="profile-data-input" type="text" v-model="user.pronouns" placeholder="Enter pronouns" />
|
||||||
<h3 class="subtitle">ABOUT ME</h3>
|
<h3 class="subtitle">ABOUT ME</h3>
|
||||||
<p>{{ user?.about_me || "TBD" }}</p>
|
<input class="profile-data-input" type="text" v-model="user.about" placeholder="About You" />
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
<Button text="Save Changes" :callback="saveChanges"></Button>
|
<Button text="Save Changes" :callback="saveChanges"></Button>
|
||||||
</div>
|
</div>
|
||||||
<Userpopup :user=user_me class="profile"></Userpopup>
|
<Userpopup :user=user_me class="profile"></Userpopup>
|
||||||
|
@ -50,34 +53,31 @@ const user = user_me!
|
||||||
let new_pfp_file: any = null
|
let new_pfp_file: any = null
|
||||||
|
|
||||||
const saveChanges = async () => {
|
const saveChanges = async () => {
|
||||||
try {
|
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
|
|
||||||
const upload_field: HTMLInputElement = document.getElementById("hidden-pfp-uploader")
|
if (new_pfp_file !== null) {
|
||||||
if (upload_field.files?.length && upload_field.files.length > 0) {
|
formData.append("avatar", new_pfp_file)
|
||||||
console.log(upload_field.files[0])
|
|
||||||
formData.append("avatar", upload_field.files[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bytes = new TextEncoder().encode(JSON.stringify({
|
const bytes = new TextEncoder().encode(JSON.stringify({
|
||||||
display_name: user.display_name,
|
display_name: user.display_name,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
pronouns: user.pronouns,
|
pronouns: user.pronouns,
|
||||||
|
about: user.about,
|
||||||
}));
|
}));
|
||||||
formData.append("json", new Blob([bytes], { type: "application/json" }));
|
formData.append('json', new Blob([bytes], { type: 'application/json' }));
|
||||||
|
|
||||||
await fetchWithApi("/me", {
|
try {
|
||||||
method: "PATCH",
|
await fetchWithApi('/me', {
|
||||||
|
method: 'PATCH',
|
||||||
body: formData
|
body: formData
|
||||||
})
|
})
|
||||||
|
|
||||||
user_reference = Object.assign({}, user_me)
|
user_reference = Object.assign({}, await fetchUser())
|
||||||
alert("success!!")
|
alert('success!!')
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error?.response?.status !== 200) {
|
if (error?.response?.status !== 200) {
|
||||||
const errorData = await error?.response?.json()
|
alert(`error ${error?.response?.status} met whilst trying to update profile info`)
|
||||||
|
|
||||||
alert(`error ${error?.response?.status} met whilst trying to update profile info\n${errorData}`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -89,23 +89,28 @@ const removeAvatar = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const changeAvatar = async () => {
|
const changeAvatar = async () => {
|
||||||
const upload_field: HTMLInputElement = document.getElementById("hidden-pfp-uploader")
|
let input = document.createElement('input');
|
||||||
|
input.type = 'file';
|
||||||
|
input.accept = 'image/*';
|
||||||
|
|
||||||
// upload_field.onchange = async(e) => {
|
input.onchange = async (e) => {
|
||||||
// console.log(upload_field.files)
|
if (input.files?.length && input.files.length > 0) {
|
||||||
// if (upload_field.files?.length && upload_field.files.length > 0) {
|
const file = input.files[0];
|
||||||
// const file = upload_field.files[0];
|
if (!file) return;
|
||||||
// if (!file) return;
|
|
||||||
|
|
||||||
// const reader = new FileReader();
|
new_pfp_file = file
|
||||||
// reader.onload = (e) => {
|
|
||||||
// user.avatar = e?.target?.result;
|
|
||||||
// };
|
|
||||||
// reader.readAsDataURL(file);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
upload_field?.click()
|
const reader = new FileReader();
|
||||||
|
reader.onload = (e) => {
|
||||||
|
if (e.target?.result && typeof e.target.result === 'string') {
|
||||||
|
user.avatar = e.target.result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
input.click()
|
||||||
}
|
}
|
||||||
|
|
||||||
const resetPassword = async () => {
|
const resetPassword = async () => {
|
||||||
|
@ -130,7 +135,8 @@ const deleteAccount = async () => {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.profile-container, .user-data-fields {
|
.profile-container,
|
||||||
|
.user-data-fields {
|
||||||
min-width: 350px;
|
min-width: 350px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,4 +145,16 @@ const deleteAccount = async () => {
|
||||||
font-weight: 800;
|
font-weight: 800;
|
||||||
margin: 12px 0;
|
margin: 12px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.profile-data-input {
|
||||||
|
min-width: 300px;
|
||||||
|
margin: 2px;
|
||||||
|
padding: 2px 10px;
|
||||||
|
height: 40px;
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
background-color: #54361b;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
|
@ -69,24 +69,6 @@ const settingsCategories = {
|
||||||
{ display_name: "Language", page_data: Language },
|
{ display_name: "Language", page_data: Language },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
app_settings2: {
|
|
||||||
display_name: "App Settings",
|
|
||||||
pages: [
|
|
||||||
{ display_name: "Appearance", page_data: Appearance },
|
|
||||||
{ display_name: "Notifications", page_data: Notifications },
|
|
||||||
{ display_name: "Keybinds", page_data: Keybinds },
|
|
||||||
{ display_name: "Language", page_data: Language },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
app_settings3: {
|
|
||||||
display_name: "App Settings",
|
|
||||||
pages: [
|
|
||||||
{ display_name: "Appearance", page_data: Appearance },
|
|
||||||
{ display_name: "Notifications", page_data: Notifications },
|
|
||||||
{ display_name: "Keybinds", page_data: Keybinds },
|
|
||||||
{ display_name: "Language", page_data: Language },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const categories = Object.values(settingsCategories);
|
const categories = Object.values(settingsCategories);
|
||||||
|
|
|
@ -59,7 +59,7 @@ export interface UserResponse {
|
||||||
display_name: string | null,
|
display_name: string | null,
|
||||||
avatar: string | null,
|
avatar: string | null,
|
||||||
pronouns: string | null,
|
pronouns: string | null,
|
||||||
about_me: string | null,
|
about: string | null,
|
||||||
email?: string,
|
email?: string,
|
||||||
email_verified?: boolean
|
email_verified?: boolean
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue