@atmo-dev/kit 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
<script lang="ts">
|
|
9
9
|
import type { Snippet } from 'svelte';
|
|
10
|
+
import { SvelteMap } from 'svelte/reactivity';
|
|
10
11
|
import type { AttendeeInfo, AttendeeListLoader } from './contrail.js';
|
|
11
12
|
import { Avatar } from '../index.js';
|
|
12
13
|
import { scale } from 'svelte/transition';
|
|
@@ -64,20 +65,32 @@
|
|
|
64
65
|
);
|
|
65
66
|
let loadingAll = $state(false);
|
|
66
67
|
let loadedAll = $state(false);
|
|
68
|
+
const localUpdates = new SvelteMap<string, AttendeeInfo | null>();
|
|
67
69
|
|
|
68
70
|
async function loadEveryone() {
|
|
69
71
|
if (!loadAll || loadedAll || loadingAll || !hasMore) return;
|
|
70
72
|
loadingAll = true;
|
|
71
73
|
try {
|
|
72
74
|
const full = await loadAll();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
full.
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
// The index may still contain a just-cancelled RSVP (or omit a new
|
|
76
|
+
// one). Do not let a late lazy load undo successful local mutations.
|
|
77
|
+
const updates = [...localUpdates.values()].filter((a) => a !== null);
|
|
78
|
+
goingAttendeesOverride = [
|
|
79
|
+
...updates.filter((a) => a.status === 'going'),
|
|
80
|
+
...full.going.filter((a) => !localUpdates.has(a.did))
|
|
81
|
+
];
|
|
82
|
+
interestedAttendeesOverride = [
|
|
83
|
+
...updates.filter((a) => a.status === 'interested'),
|
|
84
|
+
...full.interested.filter((a) => !localUpdates.has(a.did))
|
|
85
|
+
];
|
|
86
|
+
if (localUpdates.size === 0) {
|
|
87
|
+
goingCountOverride = Math.max(goingCount, full.goingCount ?? 0, full.going.length);
|
|
88
|
+
interestedCountOverride = Math.max(
|
|
89
|
+
interestedCount,
|
|
90
|
+
full.interestedCount ?? 0,
|
|
91
|
+
full.interested.length
|
|
92
|
+
);
|
|
93
|
+
}
|
|
81
94
|
loadedAll = true;
|
|
82
95
|
} catch {
|
|
83
96
|
// Keep the sample; the next open tries again.
|
|
@@ -92,9 +105,21 @@
|
|
|
92
105
|
void loadEveryone();
|
|
93
106
|
}
|
|
94
107
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
// A partial list cannot tell us whether an account already contributes to
|
|
109
|
+
// the totals. Callers that know its previous status must supply it.
|
|
110
|
+
export function addAttendee(
|
|
111
|
+
attendee: AttendeeInfo,
|
|
112
|
+
previousStatus?: 'going' | 'interested' | 'notgoing' | null
|
|
113
|
+
) {
|
|
114
|
+
const wasGoing =
|
|
115
|
+
previousStatus === undefined
|
|
116
|
+
? goingAttendees.some((a) => a.did === attendee.did)
|
|
117
|
+
: previousStatus === 'going';
|
|
118
|
+
const wasInterested =
|
|
119
|
+
previousStatus === undefined
|
|
120
|
+
? interestedAttendees.some((a) => a.did === attendee.did)
|
|
121
|
+
: previousStatus === 'interested';
|
|
122
|
+
localUpdates.set(attendee.did, attendee);
|
|
98
123
|
const nextGoing = goingAttendees.filter((a) => a.did !== attendee.did);
|
|
99
124
|
const nextInterested = interestedAttendees.filter((a) => a.did !== attendee.did);
|
|
100
125
|
|
|
@@ -103,11 +128,11 @@
|
|
|
103
128
|
goingAttendeesOverride = [attendee, ...nextGoing];
|
|
104
129
|
interestedAttendeesOverride = nextInterested;
|
|
105
130
|
goingCountOverride = goingCount + (wasGoing ? 0 : 1);
|
|
106
|
-
interestedCountOverride = interestedCount - (wasInterested ? 1 : 0);
|
|
131
|
+
interestedCountOverride = Math.max(0, interestedCount - (wasInterested ? 1 : 0));
|
|
107
132
|
} else if (attendee.status === 'interested') {
|
|
108
133
|
goingAttendeesOverride = nextGoing;
|
|
109
134
|
interestedAttendeesOverride = [attendee, ...nextInterested];
|
|
110
|
-
goingCountOverride = goingCount - (wasGoing ? 1 : 0);
|
|
135
|
+
goingCountOverride = Math.max(0, goingCount - (wasGoing ? 1 : 0));
|
|
111
136
|
interestedCountOverride = interestedCount + (wasInterested ? 0 : 1);
|
|
112
137
|
}
|
|
113
138
|
}
|
|
@@ -116,13 +141,23 @@
|
|
|
116
141
|
return url?.replace('/avatar/', '/avatar_thumbnail/');
|
|
117
142
|
}
|
|
118
143
|
|
|
119
|
-
export function removeAttendee(
|
|
120
|
-
|
|
121
|
-
|
|
144
|
+
export function removeAttendee(
|
|
145
|
+
did: string,
|
|
146
|
+
previousStatus?: 'going' | 'interested' | 'notgoing' | null
|
|
147
|
+
) {
|
|
148
|
+
const wasGoing =
|
|
149
|
+
previousStatus === undefined
|
|
150
|
+
? goingAttendees.some((a) => a.did === did)
|
|
151
|
+
: previousStatus === 'going';
|
|
152
|
+
const wasInterested =
|
|
153
|
+
previousStatus === undefined
|
|
154
|
+
? interestedAttendees.some((a) => a.did === did)
|
|
155
|
+
: previousStatus === 'interested';
|
|
156
|
+
localUpdates.set(did, null);
|
|
122
157
|
goingAttendeesOverride = goingAttendees.filter((a) => a.did !== did);
|
|
123
158
|
interestedAttendeesOverride = interestedAttendees.filter((a) => a.did !== did);
|
|
124
|
-
if (wasGoing) goingCountOverride = goingCount - 1;
|
|
125
|
-
if (wasInterested) interestedCountOverride = interestedCount - 1;
|
|
159
|
+
if (wasGoing) goingCountOverride = Math.max(0, goingCount - 1);
|
|
160
|
+
if (wasInterested) interestedCountOverride = Math.max(0, interestedCount - 1);
|
|
126
161
|
}
|
|
127
162
|
</script>
|
|
128
163
|
|
|
@@ -14,8 +14,8 @@ type $$ComponentProps = {
|
|
|
14
14
|
loadAll?: AttendeeListLoader;
|
|
15
15
|
};
|
|
16
16
|
declare const EventAttendees: import("svelte").Component<$$ComponentProps, {
|
|
17
|
-
addAttendee: (attendee: AttendeeInfo) => void;
|
|
18
|
-
removeAttendee: (did: string) => void;
|
|
17
|
+
addAttendee: (attendee: AttendeeInfo, previousStatus?: "going" | "interested" | "notgoing" | null) => void;
|
|
18
|
+
removeAttendee: (did: string, previousStatus?: "going" | "interested" | "notgoing" | null) => void;
|
|
19
19
|
}, "">;
|
|
20
20
|
type EventAttendees = ReturnType<typeof EventAttendees>;
|
|
21
21
|
export default EventAttendees;
|
|
@@ -238,17 +238,28 @@
|
|
|
238
238
|
let vodApi: VodPlayerApi | undefined = $state();
|
|
239
239
|
|
|
240
240
|
let attendeesRef: EventAttendees | undefined = $state();
|
|
241
|
+
let viewerRsvpStatusOverride: 'going' | 'interested' | 'notgoing' | null | undefined =
|
|
242
|
+
$state(undefined);
|
|
243
|
+
let viewerRsvpStatus = $derived(
|
|
244
|
+
viewerRsvpStatusOverride === undefined
|
|
245
|
+
? (data.viewerRsvpStatus ?? null)
|
|
246
|
+
: viewerRsvpStatusOverride
|
|
247
|
+
);
|
|
241
248
|
|
|
242
249
|
function handleRsvp(status: 'going' | 'interested') {
|
|
243
250
|
if (!viewer.did) return;
|
|
244
|
-
attendeesRef?.addAttendee(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
251
|
+
attendeesRef?.addAttendee(
|
|
252
|
+
{
|
|
253
|
+
did: viewer.did,
|
|
254
|
+
status,
|
|
255
|
+
avatar: viewer.avatar,
|
|
256
|
+
name: viewer.displayName || viewer.handle || viewer.did,
|
|
257
|
+
handle: viewer.handle,
|
|
258
|
+
url: `/p/${encodeURIComponent(viewer.handle || viewer.did)}`
|
|
259
|
+
},
|
|
260
|
+
viewerRsvpStatus
|
|
261
|
+
);
|
|
262
|
+
viewerRsvpStatusOverride = status;
|
|
252
263
|
if (status === 'interested' || !share) return;
|
|
253
264
|
shareModalTitle = "You're going!";
|
|
254
265
|
shareModalText = `I'm going to "${eventData.name}".\n\n${shareUrl}`;
|
|
@@ -258,7 +269,8 @@
|
|
|
258
269
|
|
|
259
270
|
function handleRsvpCancel() {
|
|
260
271
|
if (!viewer.did) return;
|
|
261
|
-
attendeesRef?.removeAttendee(viewer.did);
|
|
272
|
+
attendeesRef?.removeAttendee(viewer.did, viewerRsvpStatus);
|
|
273
|
+
viewerRsvpStatusOverride = null;
|
|
262
274
|
}
|
|
263
275
|
</script>
|
|
264
276
|
|