@ -263,6 +263,47 @@
< / r o u t e r - l i n k >
< / div >
<!-- User Profile -- >
< div
class = "bg-slate-100 rounded-md overflow-hidden px-4 py-4 mt-8 mb-8"
>
< div v-if ="loadingProfile" class="text-center mb-2" >
< fa icon = "spinner" class = "fa-spin text-slate-400" > < / fa > Loading
profile ...
< / div >
< div v -else class = "flex items-center mb-2" >
< span class = "font-bold" > Public Profile < / span >
< fa
icon = "circle-info"
class = "text-slate-400 fa-fw ml-2 cursor-pointer"
@ click = "showProfileInfo"
/ >
< / div >
< textarea
v - model = "userProfile"
class = "w-full h-32 p-2 border border-slate-300 rounded-md"
placeholder = "Write something about yourself for the public..."
: readonly = "loadingProfile || savingProfile"
: class = "{ 'bg-slate-100': loadingProfile || savingProfile }"
> < / textarea >
< button
@ click = "saveProfile"
class = "mt-2 px-4 py-2 bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white rounded-md"
: disabled = "loadingProfile || savingProfile"
: class = " {
'opacity-50 cursor-not-allowed' : loadingProfile || savingProfile ,
} "
>
{ {
loadingProfile
? "Loading..."
: savingProfile
? "Saving..."
: "Save Profile"
} }
< / button >
< / div >
< div
v - if = "activeDid"
id = "sectionUsageLimits"
@ -819,6 +860,7 @@ import {
} from "@/constants/app" ;
import {
db ,
logConsoleAndDb ,
retrieveSettingsForActiveAccount ,
updateAccountSettings ,
} from "@/db/index" ;
@ -830,8 +872,9 @@ import {
} from "@/db/tables/settings" ;
import {
clearPasskeyToken ,
ErrorResponse ,
EndorserRateLimits ,
ErrorResponse ,
errorStringForLog ,
fetchEndorserRateLimits ,
fetchImageRateLimits ,
getHeaders ,
@ -877,6 +920,7 @@ export default class AccountViewView extends Vue {
isRegistered = false ;
limitsMessage = "" ;
loadingLimits = false ;
loadingProfile = true ;
notifyingNewActivity = false ;
notifyingNewActivityTime = "" ;
notifyingReminder = false ;
@ -890,6 +934,7 @@ export default class AccountViewView extends Vue {
profileImageUrl ? : string ;
publicHex = "" ;
publicBase64 = "" ;
savingProfile = false ;
showAdvanced = false ;
showB64Copy = false ;
showContactGives = false ;
@ -905,6 +950,7 @@ export default class AccountViewView extends Vue {
warnIfTestServer = false ;
webPushServer = "" ;
webPushServerInput = "" ;
userProfile = "" ;
/ * *
* Async function executed when the component is mounted .
@ -918,6 +964,38 @@ export default class AccountViewView extends Vue {
/ / I n i t i a l i z e c o m p o n e n t s t a t e w i t h v a l u e s f r o m t h e d a t a b a s e o r d e f a u l t s
await this . initializeState ( ) ;
await this . processIdentity ( ) ;
/ / L o a d t h e u s e r p r o f i l e
try {
const headers = await getHeaders ( this . activeDid ) ;
const response = await this . axios . get (
this . apiServer + "/api/partner/user-profile/" + this . activeDid ,
{ headers } ,
) ;
if ( response . status === 200 ) {
this . userProfile = response . data . description || "" ;
} else {
/ / w o n ' t g e t h e r e b e c a u s e a x i o s t h r o w s a n e r r o r i n s t e a d
throw Error ( "Unable to load profile." ) ;
}
} catch ( error ) {
if ( error . status === 404 ) {
/ / t h i s i s o k : t h e p r o f i l e i s n o t y e t c r e a t e d
} else {
logConsoleAndDb ( "Error loading profile: " + errorStringForLog ( error ) ) ;
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error Loading Profile" ,
text : "Your server profile is not available." ,
} ,
5000 ,
) ;
}
} finally {
this . loadingProfile = false ;
}
} catch ( error ) {
/ / t h i s c a n h a p p e n w h e n r u n n i n g a u t o m a t e d t e s t s i n d e v m o d e b e c a u s e n o t i f i c a t i o n s d o n ' t w o r k
console . error (
@ -1498,13 +1576,22 @@ export default class AccountViewView extends Vue {
* /
private handleRateLimitsError ( error : unknown ) {
if ( error instanceof AxiosError ) {
if ( error . status == 400 || error . status == 404 ) {
/ / n o w o r r i e s : t h e y p r o b a b l y j u s t a r e n ' t r e g i s t e r e d a n d d o n ' t h a v e a n y l i m i t s
console . log (
"Got 400 or 404 response retrieving limits which probably means they're not registered:" ,
error ,
) ;
this . limitsMessage = "No limits found, so no actions are allowed." ;
} else {
const data = error . response ? . data as ErrorResponse ;
this . limitsMessage =
( data ? . error ? . message as string ) || "Bad server response." ;
console . error (
"Got bad response retrieving limits, which usually means user isn't registered." ,
console . log (
"Got bad response retrieving limits: " ,
error ,
) ;
}
} else {
this . limitsMessage = "Got an error retrieving limits." ;
console . error ( "Got some error retrieving limits:" , error ) ;
@ -1635,5 +1722,63 @@ export default class AccountViewView extends Vue {
}
}
}
showProfileInfo ( ) {
this . $notify (
{
group : "alert" ,
type : "info" ,
title : "Public Profile Information" ,
text : "This data will be published for all to see, so be careful what your write. Your ID will only be shared with people who you allow to see your activity." ,
} ,
7000 ,
) ;
}
async saveProfile ( ) {
this . savingProfile = true ;
try {
const headers = await getHeaders ( this . activeDid ) ;
const response = await this . axios . post (
this . apiServer + "/api/partner/user-profile" ,
{
description : this . userProfile ,
} ,
{ headers } ,
) ;
if ( response . status === 201 ) {
this . $notify (
{
group : "alert" ,
type : "success" ,
title : "Profile Saved" ,
text : "Your profile has been updated successfully." ,
} ,
3000 ,
) ;
} else {
/ / w o n ' t g e t h e r e b e c a u s e a x i o s t h r o w s a n e r r o r o n n o n - s u c c e s s
throw Error ( "Profile not saved" ) ;
}
} catch ( error ) {
logConsoleAndDb ( "Error saving profile: " + errorStringForLog ( error ) ) ;
const errorMessage : string =
error . response ? . data ? . error ? . message ||
error . response ? . data ? . error ||
error . message ||
"There was an error saving your profile." ;
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error Saving Profile" ,
text : errorMessage ,
} ,
3000 ,
) ;
} finally {
this . savingProfile = false ;
}
}
}
< / script >