settings: set avatar
This commit is contained in:
@ -347,4 +347,37 @@ const flash = ({ type, msg }) => {
|
||||
toggleFavEvent();
|
||||
});
|
||||
}
|
||||
|
||||
if(document.location.pathname === '/settings') {
|
||||
const saveAvatar = async e => {
|
||||
e.preventDefault();
|
||||
|
||||
const avatar = +document.querySelector('input[name="i_avatar"]').value;
|
||||
let res = await fetch('/api/v2/settings/setAvatar', {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({ avatar })
|
||||
});
|
||||
const code = res.status;
|
||||
res = await res.json();
|
||||
|
||||
switch(code) {
|
||||
case 200:
|
||||
document.querySelector('#img_avatar').src = `/t/${avatar}.webp`;
|
||||
document.querySelector('img.avatar').src = `/t/${avatar}.webp`;
|
||||
break;
|
||||
default:
|
||||
console.log(res);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
document.querySelector('input#s_avatar').addEventListener('click', saveAvatar);
|
||||
document.querySelector('input[name="i_avatar"]').addEventListener('keyup', async e => {
|
||||
if(e.key === 'Enter')
|
||||
await saveAvatar(e);
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
Reference in New Issue
Block a user