@openpeepshq/react 0.7.1 → 0.8.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.
- package/dist/components/markdown/compileMarkdown.js +1 -0
- package/dist/components/navigation/FooterMobile.js +4 -3
- package/dist/components/navigation/HeaderMobile.js +5 -2
- package/dist/components/navigation/MobileMenuItem.d.ts +3 -1
- package/dist/components/navigation/MobileMenuItem.js +7 -2
- package/dist/components/navigation/NavWithTooltip.d.ts +9 -0
- package/dist/components/navigation/NavWithTooltip.js +4 -0
- package/dist/components/navigation/index.d.ts +2 -0
- package/dist/components/navigation/index.js +1 -0
- package/dist/components/navigation/sideBarNavLinkClass.d.ts +6 -4
- package/dist/components/navigation/sideBarNavLinkClass.js +6 -2
- package/dist/components/post/CompactReplyParent.js +5 -6
- package/dist/components/post/TruncatedMarkdown.d.ts +27 -0
- package/dist/components/post/TruncatedMarkdown.js +37 -0
- package/dist/components/post/helpers.d.ts +2 -2
- package/dist/components/post/helpers.js +3 -16
- package/dist/components/post/index.d.ts +2 -0
- package/dist/components/post/index.js +1 -0
- package/dist/components/post/pieces/EventLocation.js +14 -0
- package/dist/components/post/pieces/EventRsvpButton.js +3 -1
- package/dist/components/post/pieces/PollContent.js +8 -2
- package/dist/components/post/post-form/ArticleForm.js +1 -1
- package/dist/components/post/post-form/ComposeAttachments.d.ts +5 -1
- package/dist/components/post/post-form/ComposeAttachments.js +20 -6
- package/dist/components/post/post-form/ComposeAttachments.test.d.ts +1 -0
- package/dist/components/post/post-form/ComposeAttachments.test.js +131 -0
- package/dist/components/post/post-form/EventForm.js +23 -3
- package/dist/components/post/post-form/ResourceForm.d.ts +3 -1
- package/dist/components/post/post-form/ResourceForm.js +51 -7
- package/dist/components/post/post-form/VisibilitySelector.js +9 -3
- package/dist/components/post/types/Article.js +2 -3
- package/dist/components/post/types/Event.js +10 -1
- package/dist/components/post/types/resource/FullResource.js +3 -3
- package/dist/components/preview-link/local/WelcomePreview.js +4 -2
- package/dist/components/resources/ResourceCard.d.ts +5 -1
- package/dist/components/resources/ResourceCard.js +94 -37
- package/dist/components/resources/ResourceCard.test.d.ts +1 -0
- package/dist/components/resources/ResourceCard.test.js +75 -0
- package/dist/components/resources/ResourceLibrary.js +1 -1
- package/dist/hooks/events/useEventRsvp.d.ts +1 -0
- package/dist/hooks/events/useEventRsvp.js +15 -7
- package/dist/hooks/posts/useResourceComposer.d.ts +2 -0
- package/dist/hooks/posts/useResourceComposer.js +131 -25
- package/dist/hooks/resources/useResourceLibrary.d.ts +1 -1
- package/dist/hooks/resources/useResourceLibrary.js +6 -2
- package/dist/hooks/useWelcomePreview.d.ts +3 -0
- package/dist/hooks/useWelcomePreview.js +1 -0
- package/dist/navigation/menuItems.js +15 -0
- package/dist/navigation/targets.d.ts +2 -0
- package/dist/pages/admin/community/CommunityMarkdownPage.js +2 -1
- package/dist/pages/auth/Register.js +3 -1
- package/dist/pages/resources/Edit.js +3 -3
- package/dist/pages/resources/New.js +2 -2
- package/dist/pages/settings/Account.js +30 -2
- package/package.json +2 -2
- package/src/components/markdown/compileMarkdown.ts +1 -0
- package/src/components/navigation/FooterMobile.tsx +41 -33
- package/src/components/navigation/HeaderMobile.tsx +55 -41
- package/src/components/navigation/MobileMenuItem.tsx +15 -2
- package/src/components/navigation/NavWithTooltip.tsx +26 -0
- package/src/components/navigation/index.ts +2 -0
- package/src/components/navigation/sideBarNavLinkClass.ts +9 -6
- package/src/components/post/CompactReplyParent.tsx +17 -10
- package/src/components/post/TruncatedMarkdown.tsx +91 -0
- package/src/components/post/helpers.ts +4 -18
- package/src/components/post/index.ts +2 -0
- package/src/components/post/pieces/EventLocation.tsx +27 -0
- package/src/components/post/pieces/EventRsvpButton.tsx +3 -0
- package/src/components/post/pieces/PollContent.tsx +8 -2
- package/src/components/post/post-form/ArticleForm.tsx +1 -1
- package/src/components/post/post-form/ComposeAttachments.tsx +24 -3
- package/src/components/post/post-form/EventForm.tsx +43 -15
- package/src/components/post/post-form/ResourceForm.tsx +135 -4
- package/src/components/post/post-form/VisibilitySelector.tsx +11 -3
- package/src/components/post/types/Article.tsx +5 -5
- package/src/components/post/types/Event.tsx +68 -7
- package/src/components/post/types/resource/FullResource.tsx +9 -1
- package/src/components/preview-link/local/WelcomePreview.tsx +11 -2
- package/src/components/resources/ResourceCard.tsx +184 -62
- package/src/components/resources/ResourceLibrary.tsx +2 -2
- package/src/hooks/events/useEventRsvp.ts +19 -7
- package/src/hooks/posts/useResourceComposer.ts +157 -33
- package/src/hooks/resources/useResourceLibrary.ts +6 -2
- package/src/hooks/useWelcomePreview.ts +4 -0
- package/src/navigation/menuItems.ts +16 -0
- package/src/navigation/targets.ts +2 -0
- package/src/pages/admin/community/CommunityMarkdownPage.tsx +5 -1
- package/src/pages/auth/Register.tsx +12 -0
- package/src/pages/resources/Edit.tsx +3 -2
- package/src/pages/resources/New.tsx +6 -1
- package/src/pages/settings/Account.tsx +51 -1
|
@@ -7,25 +7,33 @@ import {
|
|
|
7
7
|
ImageOff,
|
|
8
8
|
} from 'lucide-react';
|
|
9
9
|
import type {
|
|
10
|
+
GroupWithMeta,
|
|
10
11
|
MediaAttachmentData,
|
|
11
12
|
PublicPost,
|
|
12
13
|
ResourceKind,
|
|
13
14
|
} from '@openpeepshq/common/types';
|
|
14
15
|
import {
|
|
15
16
|
attachmentMediaKind,
|
|
16
|
-
normalizeResourceTags,
|
|
17
|
-
truncateMarkdown,
|
|
18
17
|
formatSize,
|
|
18
|
+
groupName,
|
|
19
|
+
normalizeResourceTags,
|
|
19
20
|
} from '@openpeepshq/common/lib';
|
|
21
|
+
import { useHrefOf, useNavigate } from '../../contexts/router';
|
|
20
22
|
import { useT } from '../../i18n';
|
|
23
|
+
import { useStaticRender } from '../markdown/staticRender';
|
|
21
24
|
import { useOpenpeeps } from '../../contexts/openpeeps';
|
|
22
25
|
import { useCurrentProfile } from '../layout/IdentityContext';
|
|
23
26
|
import { VideoPlayOverlay } from '../post/VideoPlayOverlay';
|
|
27
|
+
import { TruncatedMarkdown } from '../post/TruncatedMarkdown';
|
|
24
28
|
|
|
25
29
|
export interface ResourceCardProps {
|
|
26
30
|
post: PublicPost;
|
|
27
31
|
layout?: 'card' | 'list';
|
|
28
32
|
preview?: ReactNode;
|
|
33
|
+
/** Set false when the full description is rendered by the surrounding layout (e.g. the post detail page). */
|
|
34
|
+
showDescription?: boolean;
|
|
35
|
+
/** When true, hides the group label (already shown by the group context). */
|
|
36
|
+
inGroup?: boolean;
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
const visualAttachments = (attachments: MediaAttachmentData[]) =>
|
|
@@ -52,6 +60,108 @@ const primaryActionLabel = (kind: ResourceKind, t: ReturnType<typeof useT>) => {
|
|
|
52
60
|
}
|
|
53
61
|
};
|
|
54
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Bookmark toggle. Lives in its own component so ResourceCard itself stays
|
|
65
|
+
* free of app providers (OpenpeepsProvider, IdentityContext, RouterProvider)
|
|
66
|
+
* and can render in provider-less static contexts such as notification emails.
|
|
67
|
+
*/
|
|
68
|
+
const ResourceSaveButton = ({
|
|
69
|
+
postId,
|
|
70
|
+
className,
|
|
71
|
+
}: {
|
|
72
|
+
postId: string;
|
|
73
|
+
className: string;
|
|
74
|
+
}) => {
|
|
75
|
+
const t = useT();
|
|
76
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
77
|
+
const me = useCurrentProfile();
|
|
78
|
+
const bookmarkedIdsQuery = openpeepsApi.useCurrentProfileBookmarkedIds();
|
|
79
|
+
const bookmarkPost = openpeepsApi.bookmarkPostAction({ id: postId });
|
|
80
|
+
const unbookmarkPost = openpeepsApi.unbookmarkPostAction({ id: postId });
|
|
81
|
+
const isBookmarked = bookmarkedIdsQuery.data?.includes(postId) ?? false;
|
|
82
|
+
|
|
83
|
+
const toggleBookmark = () => {
|
|
84
|
+
if (!me) return;
|
|
85
|
+
if (isBookmarked) {
|
|
86
|
+
unbookmarkPost(undefined);
|
|
87
|
+
} else {
|
|
88
|
+
bookmarkPost(undefined);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<button
|
|
94
|
+
type="button"
|
|
95
|
+
onClick={(e) => {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
e.stopPropagation();
|
|
98
|
+
toggleBookmark();
|
|
99
|
+
}}
|
|
100
|
+
disabled={!me}
|
|
101
|
+
className={className}
|
|
102
|
+
title={
|
|
103
|
+
isBookmarked
|
|
104
|
+
? t('resources.actions.saved', { defaultValue: 'Saved' })
|
|
105
|
+
: t('resources.actions.save', { defaultValue: 'Save' })
|
|
106
|
+
}
|
|
107
|
+
>
|
|
108
|
+
{isBookmarked ? (
|
|
109
|
+
<BookmarkCheck className="text-primary size-4" />
|
|
110
|
+
) : (
|
|
111
|
+
<BookmarkPlus className="size-4" />
|
|
112
|
+
)}
|
|
113
|
+
</button>
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Clickable hashtag chip. Child component like ResourceSaveButton so the
|
|
119
|
+
* router hook stays out of ResourceCard's static (email) render path.
|
|
120
|
+
*/
|
|
121
|
+
const ResourceTagChip = ({ value }: { value: string }) => {
|
|
122
|
+
const navigate = useNavigate();
|
|
123
|
+
return (
|
|
124
|
+
<button
|
|
125
|
+
type="button"
|
|
126
|
+
className="bg-muted text-muted-foreground hover:text-foreground rounded-full px-2 py-0.5 text-xs"
|
|
127
|
+
onClick={(e) => {
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
e.stopPropagation();
|
|
130
|
+
navigate({ type: 'tags', hashtag: value });
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
#{value}
|
|
134
|
+
</button>
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** Clickable group label. Child component so the router hook stays out of the static render path. */
|
|
139
|
+
const ResourceGroupLabel = ({ group }: { group: GroupWithMeta }) => {
|
|
140
|
+
const t = useT();
|
|
141
|
+
const hrefOf = useHrefOf();
|
|
142
|
+
const groupLabel = groupName(group);
|
|
143
|
+
return (
|
|
144
|
+
<a
|
|
145
|
+
href={hrefOf({ type: 'group', handle: group.handle })}
|
|
146
|
+
onClick={(e) => {
|
|
147
|
+
e.stopPropagation();
|
|
148
|
+
}}
|
|
149
|
+
className="text-muted-foreground hover:text-foreground inline-flex items-center gap-1 text-xs"
|
|
150
|
+
title={t('resources.group.inGroup', {
|
|
151
|
+
defaultValue: 'in {{groupName}}',
|
|
152
|
+
groupName: groupLabel,
|
|
153
|
+
})}
|
|
154
|
+
>
|
|
155
|
+
<span className="bg-muted rounded-full px-2 py-0.5 text-xs">
|
|
156
|
+
{t('resources.group.inGroup', {
|
|
157
|
+
defaultValue: 'in {{groupName}}',
|
|
158
|
+
groupName: groupLabel,
|
|
159
|
+
})}
|
|
160
|
+
</span>
|
|
161
|
+
</a>
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
|
|
55
165
|
const MediaPreview = ({
|
|
56
166
|
src,
|
|
57
167
|
alt,
|
|
@@ -107,24 +217,29 @@ export const ResourceCard = ({
|
|
|
107
217
|
post,
|
|
108
218
|
layout = 'card',
|
|
109
219
|
preview,
|
|
220
|
+
showDescription = true,
|
|
221
|
+
inGroup = false,
|
|
110
222
|
}: ResourceCardProps) => {
|
|
111
223
|
const t = useT();
|
|
112
|
-
const {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
const resource = post.data;
|
|
116
|
-
const attachments = resource.attachments ?? [];
|
|
224
|
+
const { enabled: staticRender } = useStaticRender();
|
|
225
|
+
const resource = post.data?.type === 'resource' ? post.data : undefined;
|
|
226
|
+
const attachments = resource?.attachments ?? [];
|
|
117
227
|
const visuals = visualAttachments(attachments);
|
|
118
|
-
const
|
|
119
|
-
const
|
|
120
|
-
const isGallery = resource.resourceKind === 'gallery' && visuals.length > 1;
|
|
228
|
+
const tags = normalizeResourceTags(resource?.tags);
|
|
229
|
+
const isGallery = resource?.resourceKind === 'gallery' && visuals.length > 1;
|
|
121
230
|
const tiles = isGallery ? visuals.slice(0, 4) : visuals.slice(0, 1);
|
|
122
231
|
const extra = isGallery ? Math.max(0, visuals.length - 4) : 0;
|
|
123
|
-
const actionLabel =
|
|
232
|
+
const actionLabel = resource
|
|
233
|
+
? primaryActionLabel(resource.resourceKind, t)
|
|
234
|
+
: null;
|
|
124
235
|
const thumbnail = visuals[0];
|
|
125
236
|
const thumbSrc = thumbnail ? previewSrc(thumbnail) : null;
|
|
126
237
|
|
|
238
|
+
const group = post.group;
|
|
239
|
+
const groupLabel = group ? groupName(group) : null;
|
|
240
|
+
|
|
127
241
|
const metaText = useMemo(() => {
|
|
242
|
+
if (!resource) return null;
|
|
128
243
|
if (resource.resourceKind === 'gallery' && visuals.length > 1) {
|
|
129
244
|
return t('resources.meta.imagesCount', {
|
|
130
245
|
defaultValue: '{{count}} images',
|
|
@@ -140,50 +255,37 @@ export const ResourceCard = ({
|
|
|
140
255
|
const size = fileAtt?.meta?.size;
|
|
141
256
|
if (size) return formatSize(size);
|
|
142
257
|
return null;
|
|
143
|
-
}, [resource
|
|
144
|
-
|
|
145
|
-
const bookmarkedIdsQuery = openpeepsApi.useCurrentProfileBookmarkedIds();
|
|
146
|
-
const isBookmarked = bookmarkedIdsQuery.data?.includes(post.id) ?? false;
|
|
147
|
-
const bookmarkPost = openpeepsApi.bookmarkPostAction({ id: post.id });
|
|
148
|
-
const unbookmarkPost = openpeepsApi.unbookmarkPostAction({ id: post.id });
|
|
258
|
+
}, [resource, visuals, attachments, t]);
|
|
149
259
|
|
|
150
|
-
|
|
151
|
-
if (!me) return;
|
|
152
|
-
if (isBookmarked) {
|
|
153
|
-
unbookmarkPost(undefined);
|
|
154
|
-
} else {
|
|
155
|
-
bookmarkPost(undefined);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
260
|
+
if (!resource) return null;
|
|
158
261
|
|
|
159
262
|
const downloadUrl =
|
|
160
263
|
resource.resourceKind === 'file'
|
|
161
264
|
? attachments.find((att) => attachmentMediaKind(att) === 'file')?.url
|
|
162
265
|
: null;
|
|
163
266
|
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
);
|
|
267
|
+
const renderSaveButton = (className: string) =>
|
|
268
|
+
staticRender ? null : (
|
|
269
|
+
<ResourceSaveButton postId={post.id} className={className} />
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
const renderGroupLabel = () => {
|
|
273
|
+
if (!group || !groupLabel || inGroup) return null;
|
|
274
|
+
const label = t('resources.group.inGroup', {
|
|
275
|
+
defaultValue: 'in {{groupName}}',
|
|
276
|
+
groupName: groupLabel,
|
|
277
|
+
});
|
|
278
|
+
if (staticRender) {
|
|
279
|
+
return (
|
|
280
|
+
<span className="text-muted-foreground inline-flex items-center gap-1 text-xs">
|
|
281
|
+
<span className="bg-muted rounded-full px-2 py-0.5 text-xs">
|
|
282
|
+
{label}
|
|
283
|
+
</span>
|
|
284
|
+
</span>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
return <ResourceGroupLabel group={group} />;
|
|
288
|
+
};
|
|
187
289
|
|
|
188
290
|
const renderThumbnail = () => {
|
|
189
291
|
if (thumbSrc) {
|
|
@@ -219,8 +321,16 @@ export const ResourceCard = ({
|
|
|
219
321
|
{resource.categoryPath.join(' / ')}
|
|
220
322
|
</p>
|
|
221
323
|
) : null}
|
|
222
|
-
{
|
|
223
|
-
|
|
324
|
+
{renderGroupLabel()}
|
|
325
|
+
{showDescription ? (
|
|
326
|
+
<TruncatedMarkdown
|
|
327
|
+
source={resource.content ?? ''}
|
|
328
|
+
maxBlocks={2}
|
|
329
|
+
maxChars={240}
|
|
330
|
+
maxLines={2}
|
|
331
|
+
interactive={!staticRender}
|
|
332
|
+
className="text-sm text-muted-foreground"
|
|
333
|
+
/>
|
|
224
334
|
) : null}
|
|
225
335
|
{metaText ? (
|
|
226
336
|
<p className="text-muted-foreground text-xs">{metaText}</p>
|
|
@@ -244,7 +354,7 @@ export const ResourceCard = ({
|
|
|
244
354
|
</span>
|
|
245
355
|
)
|
|
246
356
|
) : null}
|
|
247
|
-
{
|
|
357
|
+
{renderSaveButton(
|
|
248
358
|
'text-muted-foreground hover:text-foreground disabled:opacity-50',
|
|
249
359
|
)}
|
|
250
360
|
</div>
|
|
@@ -295,7 +405,7 @@ export const ResourceCard = ({
|
|
|
295
405
|
<LinkIcon className="text-muted-foreground/50 size-8" />
|
|
296
406
|
</div>
|
|
297
407
|
) : null}
|
|
298
|
-
{
|
|
408
|
+
{renderSaveButton(
|
|
299
409
|
'bg-background text-muted-foreground hover:text-foreground absolute right-2 top-2 rounded-full p-1 opacity-70 hover:opacity-100 disabled:opacity-50',
|
|
300
410
|
)}
|
|
301
411
|
</div>
|
|
@@ -306,22 +416,34 @@ export const ResourceCard = ({
|
|
|
306
416
|
{resource.categoryPath.join(' / ')}
|
|
307
417
|
</p>
|
|
308
418
|
) : null}
|
|
309
|
-
{
|
|
310
|
-
|
|
419
|
+
{renderGroupLabel()}
|
|
420
|
+
{showDescription ? (
|
|
421
|
+
<TruncatedMarkdown
|
|
422
|
+
source={resource.content ?? ''}
|
|
423
|
+
maxBlocks={2}
|
|
424
|
+
maxChars={240}
|
|
425
|
+
maxLines={2}
|
|
426
|
+
interactive={!staticRender}
|
|
427
|
+
className="text-sm text-muted-foreground"
|
|
428
|
+
/>
|
|
311
429
|
) : null}
|
|
312
430
|
{metaText ? (
|
|
313
431
|
<p className="text-muted-foreground text-xs">{metaText}</p>
|
|
314
432
|
) : null}
|
|
315
433
|
{tags.length ? (
|
|
316
434
|
<div className="flex flex-wrap gap-1">
|
|
317
|
-
{tags.map((value) =>
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
435
|
+
{tags.map((value) =>
|
|
436
|
+
staticRender ? (
|
|
437
|
+
<span
|
|
438
|
+
key={value}
|
|
439
|
+
className="bg-muted text-muted-foreground rounded-full px-2 py-0.5 text-xs"
|
|
440
|
+
>
|
|
441
|
+
#{value}
|
|
442
|
+
</span>
|
|
443
|
+
) : (
|
|
444
|
+
<ResourceTagChip key={value} value={value} />
|
|
445
|
+
),
|
|
446
|
+
)}
|
|
325
447
|
</div>
|
|
326
448
|
) : null}
|
|
327
449
|
<p className="text-muted-foreground text-xs uppercase">
|
|
@@ -352,7 +352,7 @@ export const ResourceLibrary = ({ groupId }: ResourceLibraryProps) => {
|
|
|
352
352
|
href={hrefOf({ type: 'post', id: post.id })}
|
|
353
353
|
className="block"
|
|
354
354
|
>
|
|
355
|
-
<ResourceCard post={post} layout="list" />
|
|
355
|
+
<ResourceCard post={post} layout="list" inGroup={!!groupId} />
|
|
356
356
|
</a>
|
|
357
357
|
))}
|
|
358
358
|
</div>
|
|
@@ -364,7 +364,7 @@ export const ResourceLibrary = ({ groupId }: ResourceLibraryProps) => {
|
|
|
364
364
|
href={hrefOf({ type: 'post', id: post.id })}
|
|
365
365
|
className="block"
|
|
366
366
|
>
|
|
367
|
-
<ResourceCard post={post} layout="card" />
|
|
367
|
+
<ResourceCard post={post} layout="card" inGroup={!!groupId} />
|
|
368
368
|
</a>
|
|
369
369
|
))}
|
|
370
370
|
</div>
|
|
@@ -6,10 +6,12 @@ import {
|
|
|
6
6
|
checkPostCapabilities,
|
|
7
7
|
defaultRsvpRecurrenceId,
|
|
8
8
|
displayRsvpForProfile,
|
|
9
|
+
effectiveEventTimes,
|
|
9
10
|
eventRsvpOpen,
|
|
10
11
|
isCapacityEvent,
|
|
11
12
|
isRecurringEvent,
|
|
12
13
|
listRsvpOccurrences,
|
|
14
|
+
occurrenceHasEnded,
|
|
13
15
|
offerStillOpen,
|
|
14
16
|
seriesHasClaimableOccurrence,
|
|
15
17
|
} from '@openpeepshq/common/lib';
|
|
@@ -58,13 +60,21 @@ export const useEventRsvp = ({
|
|
|
58
60
|
|
|
59
61
|
const eventData = post.data?.type === 'event' ? post.data : undefined;
|
|
60
62
|
const recurring = eventData ? isRecurringEvent(eventData) : false;
|
|
63
|
+
const viewedTimes = eventData
|
|
64
|
+
? effectiveEventTimes(eventData, recurrenceId)
|
|
65
|
+
: undefined;
|
|
66
|
+
// Series home shows its first start. Once that time has passed, RSVP stays
|
|
67
|
+
// off that page; upcoming dates are opened from their own links.
|
|
68
|
+
const viewedEnded =
|
|
69
|
+
!!viewedTimes && occurrenceHasEnded(viewedTimes.start, viewedTimes.end);
|
|
70
|
+
// A selected date, or a one-off, is closed on its own end time.
|
|
61
71
|
const rsvpClosed = eventData
|
|
62
|
-
? !eventRsvpOpen(
|
|
72
|
+
? !eventRsvpOpen(
|
|
73
|
+
eventData,
|
|
74
|
+
recurrenceId ? { recurrenceId, lockToOccurrence: true } : undefined,
|
|
75
|
+
)
|
|
63
76
|
: false;
|
|
64
|
-
const queriedOccurrenceClosed =
|
|
65
|
-
!!eventData &&
|
|
66
|
-
!!recurrenceId &&
|
|
67
|
-
!eventRsvpOpen(eventData, { recurrenceId, lockToOccurrence: true });
|
|
77
|
+
const queriedOccurrenceClosed = !!recurrenceId && rsvpClosed;
|
|
68
78
|
const defaultId = eventData
|
|
69
79
|
? defaultRsvpRecurrenceId(
|
|
70
80
|
eventData,
|
|
@@ -131,7 +141,7 @@ export const useEventRsvp = ({
|
|
|
131
141
|
};
|
|
132
142
|
|
|
133
143
|
const requestJoinWaitlist = () => {
|
|
134
|
-
if (rsvpClosed) return;
|
|
144
|
+
if (rsvpClosed || viewedEnded) return;
|
|
135
145
|
if (!recurring || lockToOccurrence) {
|
|
136
146
|
setError(null);
|
|
137
147
|
setConfirmingWaitlist(true);
|
|
@@ -152,6 +162,7 @@ export const useEventRsvp = ({
|
|
|
152
162
|
};
|
|
153
163
|
|
|
154
164
|
const claimSpot = () => {
|
|
165
|
+
if (rsvpClosed || viewedEnded) return;
|
|
155
166
|
const id = recurring
|
|
156
167
|
? (myRsvp?.recurrenceId ?? (lockToOccurrence ? recurrenceId : defaultId))
|
|
157
168
|
: undefined;
|
|
@@ -159,7 +170,7 @@ export const useEventRsvp = ({
|
|
|
159
170
|
};
|
|
160
171
|
|
|
161
172
|
const requestRespond = (response: RsvpChoice) => {
|
|
162
|
-
if (rsvpClosed) return;
|
|
173
|
+
if (rsvpClosed || viewedEnded) return;
|
|
163
174
|
if (!recurring || lockToOccurrence) {
|
|
164
175
|
writeRsvp(response, recurrenceId ? [recurrenceId] : undefined).catch(
|
|
165
176
|
() => undefined,
|
|
@@ -193,6 +204,7 @@ export const useEventRsvp = ({
|
|
|
193
204
|
myRsvp,
|
|
194
205
|
canRsvp,
|
|
195
206
|
rsvpClosed,
|
|
207
|
+
hideRsvpButton: rsvpClosed || viewedEnded,
|
|
196
208
|
recurring,
|
|
197
209
|
defaultId,
|
|
198
210
|
occurrences,
|