Your music, beautifully tracked. All yours. (coming soon) teal.fm
teal-fm atproto

hydrate profile data and double check before editing/committing

Changed files
+96 -50
apps
amethyst
app
onboarding
components
+49 -18
apps/amethyst/app/onboarding/index.tsx
··· 38 38 const handleImageSelectionComplete = (avatar: string, banner: string) => { 39 39 setAvatarUri(avatar); 40 40 setBannerUri(banner); 41 - onComplete({ displayName, description }, avatarUri, bannerUri); 41 + onComplete({ displayName, description }, avatar, banner); 42 42 }; 43 43 44 44 const handleDisplayNameComplete = (name: string) => { ··· 61 61 console.log('Saving profile:', updatedProfile, newAvatarUri, newBannerUri); 62 62 63 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 + } 64 79 65 80 // upload blobs if necessary 66 - let newAvatarBlob; 67 - let newBannerBlob; 81 + let newAvatarBlob = currentUser?.avatar ?? undefined; 82 + let newBannerBlob = currentUser?.banner ?? undefined; 68 83 if (newAvatarUri) { 84 + console.log(newAvatarUri); 69 85 // if it is http/s url then do nothing 70 86 if (!newAvatarUri.startsWith('http')) { 71 87 setSubmissionStep(2); ··· 75 91 const fileType = newAvatarUri.split(';')[0].split(':')[1]; 76 92 console.log(fileType); 77 93 const blob = new Blob([data], { type: fileType }); 78 - newAvatarBlob = await agent.uploadBlob(blob); 94 + newAvatarBlob = (await agent.uploadBlob(blob)).data.blob; 79 95 } 80 96 } 81 97 if (newBannerUri) { ··· 86 102 const fileType = newBannerUri.split(';')[0].split(':')[1]; 87 103 console.log(fileType); 88 104 const blob = new Blob([data], { type: fileType }); 89 - newBannerBlob = await agent.uploadBlob(blob); 105 + newBannerBlob = (await agent.uploadBlob(blob)).data.blob; 90 106 } 91 107 } 92 108 ··· 97 113 let record: ProfileRecord = { 98 114 displayName: updatedProfile.displayName, 99 115 description: updatedProfile.description, 100 - avatar: newAvatarBlob?.data.blob, 101 - banner: newBannerBlob?.data.blob, 116 + avatar: newAvatarBlob, 117 + banner: newBannerBlob, 102 118 }; 103 119 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 - ); 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 + } 115 146 116 147 console.log(post); 117 148 setSubmissionStep(5);
+47 -32
apps/amethyst/components/actor/actorView.tsx
··· 61 61 }; 62 62 }, [pdsAgent, actorDid, tealDid]); 63 63 64 - const isSelf = actorDid === (pdsAgent?.did || ""); 64 + const isSelf = actorDid === (pdsAgent?.did || ''); 65 65 66 66 const handleSave = async ( 67 67 updatedProfile: { displayName: any; description: any }, ··· 83 83 banner: newBannerUri, 84 84 })); 85 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 + 86 101 // upload blobs if necessary 87 - let newAvatarBlob; 88 - let newBannerBlob; 102 + let newAvatarBlob = currentUser?.avatar ?? undefined; 103 + let newBannerBlob = currentUser?.banner ?? undefined; 89 104 if (newAvatarUri) { 90 105 // if it is http/s url then do nothing 91 106 if (!newAvatarUri.startsWith('http')) { ··· 95 110 const fileType = newAvatarUri.split(';')[0].split(':')[1]; 96 111 console.log(fileType); 97 112 const blob = new Blob([data], { type: fileType }); 98 - newAvatarBlob = await pdsAgent.uploadBlob(blob); 113 + newAvatarBlob = (await pdsAgent.uploadBlob(blob)).data.blob; 99 114 } 100 115 } 101 116 if (newBannerUri) { ··· 105 120 const fileType = newBannerUri.split(';')[0].split(':')[1]; 106 121 console.log(fileType); 107 122 const blob = new Blob([data], { type: fileType }); 108 - newBannerBlob = await pdsAgent.uploadBlob(blob); 123 + newBannerBlob = (await pdsAgent.uploadBlob(blob)).data.blob; 109 124 } 110 125 } 111 126 ··· 114 129 let record: ProfileRecord = { 115 130 displayName: updatedProfile.displayName, 116 131 description: updatedProfile.description, 117 - avatar: newAvatarBlob?.data.blob, 118 - banner: newBannerBlob?.data.blob, 132 + avatar: newAvatarBlob, 133 + banner: newBannerBlob, 119 134 }; 120 135 121 - console.log(record); 136 + let post; 122 137 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); 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 + } 147 162 148 163 setIsEditing(false); // Close the modal after saving 149 164 };