+49
-18
apps/amethyst/app/onboarding/index.tsx
+49
-18
apps/amethyst/app/onboarding/index.tsx
···
38
const handleImageSelectionComplete = (avatar: string, banner: string) => {
39
setAvatarUri(avatar);
40
setBannerUri(banner);
41
-
onComplete({ displayName, description }, avatarUri, bannerUri);
42
};
43
44
const handleDisplayNameComplete = (name: string) => {
···
61
console.log('Saving profile:', updatedProfile, newAvatarUri, newBannerUri);
62
63
setSubmissionStep(1);
64
65
// upload blobs if necessary
66
-
let newAvatarBlob;
67
-
let newBannerBlob;
68
if (newAvatarUri) {
69
// if it is http/s url then do nothing
70
if (!newAvatarUri.startsWith('http')) {
71
setSubmissionStep(2);
···
75
const fileType = newAvatarUri.split(';')[0].split(':')[1];
76
console.log(fileType);
77
const blob = new Blob([data], { type: fileType });
78
-
newAvatarBlob = await agent.uploadBlob(blob);
79
}
80
}
81
if (newBannerUri) {
···
86
const fileType = newBannerUri.split(';')[0].split(':')[1];
87
console.log(fileType);
88
const blob = new Blob([data], { type: fileType });
89
-
newBannerBlob = await agent.uploadBlob(blob);
90
}
91
}
92
···
97
let record: ProfileRecord = {
98
displayName: updatedProfile.displayName,
99
description: updatedProfile.description,
100
-
avatar: newAvatarBlob?.data.blob,
101
-
banner: newBannerBlob?.data.blob,
102
};
103
104
-
// submit the profile to our PDS
105
-
let post = await agent.call(
106
-
'com.atproto.repo.createRecord',
107
-
{},
108
-
{
109
-
repo: agent.did,
110
-
collection: 'fm.teal.alpha.actor.profile',
111
-
rkey: 'self',
112
-
record,
113
-
},
114
-
);
115
116
console.log(post);
117
setSubmissionStep(5);
···
38
const handleImageSelectionComplete = (avatar: string, banner: string) => {
39
setAvatarUri(avatar);
40
setBannerUri(banner);
41
+
onComplete({ displayName, description }, avatar, banner);
42
};
43
44
const handleDisplayNameComplete = (name: string) => {
···
61
console.log('Saving profile:', updatedProfile, newAvatarUri, newBannerUri);
62
63
setSubmissionStep(1);
64
+
65
+
// get the current user's profile (getRecord)
66
+
let currentUser: ProfileRecord | undefined;
67
+
let cid: string | undefined;
68
+
try {
69
+
const res = await agent.call('com.atproto.repo.getRecord', {
70
+
repo: agent.did,
71
+
collection: 'fm.teal.alpha.actor.profile',
72
+
rkey: 'self',
73
+
});
74
+
currentUser = res.data.value;
75
+
cid = res.data.cid;
76
+
} catch (error) {
77
+
console.error('Error fetching user profile:', error);
78
+
}
79
80
// upload blobs if necessary
81
+
let newAvatarBlob = currentUser?.avatar ?? undefined;
82
+
let newBannerBlob = currentUser?.banner ?? undefined;
83
if (newAvatarUri) {
84
+
console.log(newAvatarUri);
85
// if it is http/s url then do nothing
86
if (!newAvatarUri.startsWith('http')) {
87
setSubmissionStep(2);
···
91
const fileType = newAvatarUri.split(';')[0].split(':')[1];
92
console.log(fileType);
93
const blob = new Blob([data], { type: fileType });
94
+
newAvatarBlob = (await agent.uploadBlob(blob)).data.blob;
95
}
96
}
97
if (newBannerUri) {
···
102
const fileType = newBannerUri.split(';')[0].split(':')[1];
103
console.log(fileType);
104
const blob = new Blob([data], { type: fileType });
105
+
newBannerBlob = (await agent.uploadBlob(blob)).data.blob;
106
}
107
}
108
···
113
let record: ProfileRecord = {
114
displayName: updatedProfile.displayName,
115
description: updatedProfile.description,
116
+
avatar: newAvatarBlob,
117
+
banner: newBannerBlob,
118
};
119
120
+
let post;
121
+
122
+
if (cid) {
123
+
post = await agent.call(
124
+
'com.atproto.repo.putRecord',
125
+
{},
126
+
{
127
+
repo: agent.did,
128
+
collection: 'fm.teal.alpha.actor.profile',
129
+
rkey: 'self',
130
+
record,
131
+
swapRecord: cid,
132
+
},
133
+
);
134
+
} else {
135
+
post = await agent.call(
136
+
'com.atproto.repo.createRecord',
137
+
{},
138
+
{
139
+
repo: agent.did,
140
+
collection: 'fm.teal.alpha.actor.profile',
141
+
rkey: 'self',
142
+
record,
143
+
},
144
+
);
145
+
}
146
147
console.log(post);
148
setSubmissionStep(5);
+47
-32
apps/amethyst/components/actor/actorView.tsx
+47
-32
apps/amethyst/components/actor/actorView.tsx
···
61
};
62
}, [pdsAgent, actorDid, tealDid]);
63
64
-
const isSelf = actorDid === (pdsAgent?.did || "");
65
66
const handleSave = async (
67
updatedProfile: { displayName: any; description: any },
···
83
banner: newBannerUri,
84
}));
85
86
// upload blobs if necessary
87
-
let newAvatarBlob;
88
-
let newBannerBlob;
89
if (newAvatarUri) {
90
// if it is http/s url then do nothing
91
if (!newAvatarUri.startsWith('http')) {
···
95
const fileType = newAvatarUri.split(';')[0].split(':')[1];
96
console.log(fileType);
97
const blob = new Blob([data], { type: fileType });
98
-
newAvatarBlob = await pdsAgent.uploadBlob(blob);
99
}
100
}
101
if (newBannerUri) {
···
105
const fileType = newBannerUri.split(';')[0].split(':')[1];
106
console.log(fileType);
107
const blob = new Blob([data], { type: fileType });
108
-
newBannerBlob = await pdsAgent.uploadBlob(blob);
109
}
110
}
111
···
114
let record: ProfileRecord = {
115
displayName: updatedProfile.displayName,
116
description: updatedProfile.description,
117
-
avatar: newAvatarBlob?.data.blob,
118
-
banner: newBannerBlob?.data.blob,
119
};
120
121
-
console.log(record);
122
123
-
// delete existing record
124
-
await pdsAgent.call(
125
-
'com.atproto.repo.deleteRecord',
126
-
{},
127
-
{
128
-
repo: pdsAgent.did,
129
-
collection: 'fm.teal.alpha.actor.profile',
130
-
rkey: 'self',
131
-
},
132
-
);
133
-
134
-
// submit the profile to our PDS
135
-
let post = await pdsAgent.call(
136
-
'com.atproto.repo.createRecord',
137
-
{},
138
-
{
139
-
repo: pdsAgent.did,
140
-
collection: 'fm.teal.alpha.actor.profile',
141
-
rkey: 'self',
142
-
record,
143
-
},
144
-
);
145
-
146
-
console.log(post);
147
148
setIsEditing(false); // Close the modal after saving
149
};
···
61
};
62
}, [pdsAgent, actorDid, tealDid]);
63
64
+
const isSelf = actorDid === (pdsAgent?.did || '');
65
66
const handleSave = async (
67
updatedProfile: { displayName: any; description: any },
···
83
banner: newBannerUri,
84
}));
85
86
+
// get the current user's profile (getRecord)
87
+
let currentUser: ProfileRecord | undefined;
88
+
let cid: string | undefined;
89
+
try {
90
+
const res = await pdsAgent.call('com.atproto.repo.getRecord', {
91
+
repo: pdsAgent.did,
92
+
collection: 'fm.teal.alpha.actor.profile',
93
+
rkey: 'self',
94
+
});
95
+
currentUser = res.data.value;
96
+
cid = res.data.cid;
97
+
} catch (error) {
98
+
console.error('Error fetching user profile:', error);
99
+
}
100
+
101
// upload blobs if necessary
102
+
let newAvatarBlob = currentUser?.avatar ?? undefined;
103
+
let newBannerBlob = currentUser?.banner ?? undefined;
104
if (newAvatarUri) {
105
// if it is http/s url then do nothing
106
if (!newAvatarUri.startsWith('http')) {
···
110
const fileType = newAvatarUri.split(';')[0].split(':')[1];
111
console.log(fileType);
112
const blob = new Blob([data], { type: fileType });
113
+
newAvatarBlob = (await pdsAgent.uploadBlob(blob)).data.blob;
114
}
115
}
116
if (newBannerUri) {
···
120
const fileType = newBannerUri.split(';')[0].split(':')[1];
121
console.log(fileType);
122
const blob = new Blob([data], { type: fileType });
123
+
newBannerBlob = (await pdsAgent.uploadBlob(blob)).data.blob;
124
}
125
}
126
···
129
let record: ProfileRecord = {
130
displayName: updatedProfile.displayName,
131
description: updatedProfile.description,
132
+
avatar: newAvatarBlob,
133
+
banner: newBannerBlob,
134
};
135
136
+
let post;
137
138
+
if (cid) {
139
+
post = await pdsAgent.call(
140
+
'com.atproto.repo.putRecord',
141
+
{},
142
+
{
143
+
repo: pdsAgent.did,
144
+
collection: 'fm.teal.alpha.actor.profile',
145
+
rkey: 'self',
146
+
record,
147
+
swapRecord: cid,
148
+
},
149
+
);
150
+
} else {
151
+
post = await pdsAgent.call(
152
+
'com.atproto.repo.createRecord',
153
+
{},
154
+
{
155
+
repo: pdsAgent.did,
156
+
collection: 'fm.teal.alpha.actor.profile',
157
+
rkey: 'self',
158
+
record,
159
+
},
160
+
);
161
+
}
162
163
setIsEditing(false); // Close the modal after saving
164
};