Skip to content

Commit 9027fa4

Browse files
committed
Add support for changing your atring main page
1 parent 77fe312 commit 9027fa4

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

src/lib/atproto/atweb-client.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class AtwebClient {
145145
await this.agent.put({
146146
collection: 'io.github.atweb.ringMembership',
147147
repo: this.user.did,
148-
rkey: rkey,
148+
rkey,
149149
record: {
150150
$type: 'io.github.atweb.ringMembership',
151151
createdAt: new Date().toISOString(),
@@ -154,4 +154,25 @@ export class AtwebClient {
154154
}
155155
});
156156
}
157+
158+
async setMainPage(rkey: string, mainPage: string) {
159+
const { value, cid } = await this.agent.get({
160+
collection: 'io.github.atweb.ringMembership',
161+
repo: this.user.did,
162+
rkey,
163+
});
164+
165+
await this.agent.put({
166+
collection: 'io.github.atweb.ringMembership',
167+
repo: this.user.did,
168+
rkey,
169+
record: {
170+
$type: 'io.github.atweb.ringMembership',
171+
ring: value.ring,
172+
createdAt: value.createdAt,
173+
mainPage: AtUri.make(this.user.did, 'io.github.atweb.page', filepathToRkey(mainPage)).toString(),
174+
},
175+
swapRecord: cid,
176+
});
177+
}
157178
}

src/lib/atproto/atweb-unauthed.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ export async function getRingsUserIsAMemberOf(didOrHandle: string) {
193193
repo: didOrHandle,
194194
});
195195

196-
const rings: Array<Awaited<ReturnType<typeof getRing>>> = [];
196+
const rings: Array<Awaited<ReturnType<typeof getRing>> & { mainPage: AtUri }> = [];
197197
for (const record of records) {
198198
const uri = new AtUri(record.value.ring);
199199

200200
const entry = await tryGetRing(uri.host, uri.rkey);
201201

202202
if (entry) {
203-
rings.push(entry);
203+
rings.push({...entry, mainPage: new AtUri(record.value.mainPage)});
204204
}
205205
}
206206

src/pages/rings.vue

+29-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import SignInGate from '@/components/SignInGate.vue';
33
import { getRing, getRingsUserIsAMemberOf } from '@/lib/atproto/atweb-unauthed';
44
import { resolveHandleAnonymously } from '@/lib/atproto/handles/resolve';
55
import { getDidAndPds } from '@/lib/atproto/pds-helpers';
6+
import { rkeyToFilepath } from '@/lib/atproto/rkey';
67
import { user, type User } from '@/lib/atproto/signed-in-user';
7-
import { watchImmediateAsync } from '@/lib/vue-utils';
8+
import { resolveRoute, watchImmediateAsync } from '@/lib/vue-utils';
89
import router from '@/router';
910
import type { IoGithubAtwebRing } from '@atcute/client/lexicons';
1011
import { now as tidNow } from '@atcute/tid';
@@ -17,9 +18,9 @@ import { useModal } from 'vuestic-ui';
1718
1819
type Ring = Awaited<ReturnType<typeof getRing>>;
1920
20-
const rings = ref<Ring[]>();
21+
const rings = ref<(Ring & { mainPage: AtUri })[]>();
2122
const route = useRoute('/rings');
22-
const selectedRing = ref<Ring>();
23+
const selectedRing = ref<(Ring & { mainPage: AtUri })>();
2324
2425
await watchImmediateAsync(
2526
[route, user],
@@ -190,6 +191,19 @@ function copyRingMdx(ring: Ring) {
190191
`<RingLink direction="next" ring-uri="${ring.uri.toString()}" self="${user.value!.did}">next</RingLink>`
191192
);
192193
}
194+
195+
const mainPageLink = ref('');
196+
watch(selectedRing, selectedRing => {
197+
if (!selectedRing) return;
198+
mainPageLink.value = rkeyToFilepath(selectedRing.mainPage.rkey);
199+
});
200+
201+
async function setMainPage(ring: (Ring & { mainPage: AtUri }), mainPageLink: string) {
202+
user.value!.client.setMainPage(
203+
ring.members.find(e => e.membership.host === user.value!.did)!.membership.rkey,
204+
mainPageLink
205+
);
206+
}
193207
</script>
194208

195209
<template>
@@ -266,7 +280,14 @@ function copyRingMdx(ring: Ring) {
266280
<p><b>{{ selectedRing.members?.length ?? 0 }}</b> member(s)</p>
267281
<p>Managed by <a class="va-link" :href="`https://bsky.app/profile/${selectedRing.uri.host}`">@{{ getMemberName(selectedRing.uri) }}</a></p>
268282

269-
<VaButton @click="copyRingMdx(selectedRing)">Copy ring MDX code</VaButton>
283+
<div class="va-gutter-2">
284+
<VaButton @click="copyRingMdx(selectedRing)">Copy ring MDX code</VaButton>
285+
</div>
286+
287+
<div class="va-gutter-2">
288+
<VaInput v-model="mainPageLink" label="My main page"></VaInput>
289+
<VaButton @click="setMainPage(selectedRing, mainPageLink)" class="set-my-main-page-button">Set my main page</VaButton>
290+
</div>
270291

271292
<div v-for="member in selectedRing.members" :key="member.membership.toString()" class="ring-member-card va-gutter-2">
272293
<div class="va-gutter-2">
@@ -318,6 +339,10 @@ function copyRingMdx(ring: Ring) {
318339
.ring-member-card:deep(.bluesky-embed) {
319340
margin: 0;
320341
}
342+
.set-my-main-page-button {
343+
margin-left: 0.1rem;
344+
vertical-align: text-top;
345+
}
321346
</style>
322347

323348
<style lang="scss">

0 commit comments

Comments
 (0)