@openpeepshq/react 0.7.1 → 0.8.0

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.
Files changed (86) hide show
  1. package/dist/components/markdown/compileMarkdown.js +1 -0
  2. package/dist/components/navigation/FooterMobile.js +4 -3
  3. package/dist/components/navigation/HeaderMobile.js +5 -2
  4. package/dist/components/navigation/MobileMenuItem.d.ts +3 -1
  5. package/dist/components/navigation/MobileMenuItem.js +7 -2
  6. package/dist/components/navigation/NavWithTooltip.d.ts +9 -0
  7. package/dist/components/navigation/NavWithTooltip.js +4 -0
  8. package/dist/components/navigation/index.d.ts +2 -0
  9. package/dist/components/navigation/index.js +1 -0
  10. package/dist/components/navigation/sideBarNavLinkClass.d.ts +6 -4
  11. package/dist/components/navigation/sideBarNavLinkClass.js +6 -2
  12. package/dist/components/post/CompactReplyParent.js +5 -6
  13. package/dist/components/post/TruncatedMarkdown.d.ts +27 -0
  14. package/dist/components/post/TruncatedMarkdown.js +37 -0
  15. package/dist/components/post/helpers.d.ts +2 -2
  16. package/dist/components/post/helpers.js +3 -16
  17. package/dist/components/post/index.d.ts +2 -0
  18. package/dist/components/post/index.js +1 -0
  19. package/dist/components/post/pieces/EventLocation.js +14 -0
  20. package/dist/components/post/pieces/EventRsvpButton.js +3 -1
  21. package/dist/components/post/pieces/PollContent.js +8 -2
  22. package/dist/components/post/post-form/ArticleForm.js +1 -1
  23. package/dist/components/post/post-form/EventForm.js +23 -3
  24. package/dist/components/post/post-form/ResourceForm.d.ts +3 -1
  25. package/dist/components/post/post-form/ResourceForm.js +48 -7
  26. package/dist/components/post/post-form/VisibilitySelector.js +9 -3
  27. package/dist/components/post/types/Article.js +2 -3
  28. package/dist/components/post/types/Event.js +10 -1
  29. package/dist/components/post/types/resource/FullResource.js +3 -3
  30. package/dist/components/preview-link/local/WelcomePreview.js +4 -2
  31. package/dist/components/resources/ResourceCard.d.ts +5 -1
  32. package/dist/components/resources/ResourceCard.js +29 -5
  33. package/dist/components/resources/ResourceCard.test.d.ts +1 -0
  34. package/dist/components/resources/ResourceCard.test.js +75 -0
  35. package/dist/components/resources/ResourceLibrary.js +1 -1
  36. package/dist/hooks/events/useEventRsvp.d.ts +1 -0
  37. package/dist/hooks/events/useEventRsvp.js +15 -7
  38. package/dist/hooks/posts/useResourceComposer.d.ts +2 -0
  39. package/dist/hooks/posts/useResourceComposer.js +131 -25
  40. package/dist/hooks/resources/useResourceLibrary.d.ts +1 -1
  41. package/dist/hooks/resources/useResourceLibrary.js +6 -2
  42. package/dist/hooks/useWelcomePreview.d.ts +3 -0
  43. package/dist/hooks/useWelcomePreview.js +1 -0
  44. package/dist/navigation/menuItems.js +15 -0
  45. package/dist/navigation/targets.d.ts +2 -0
  46. package/dist/pages/admin/community/CommunityMarkdownPage.js +2 -1
  47. package/dist/pages/auth/Register.js +3 -1
  48. package/dist/pages/resources/Edit.js +3 -3
  49. package/dist/pages/resources/New.js +2 -2
  50. package/dist/pages/settings/Account.js +30 -2
  51. package/package.json +2 -2
  52. package/src/components/markdown/compileMarkdown.ts +1 -0
  53. package/src/components/navigation/FooterMobile.tsx +41 -33
  54. package/src/components/navigation/HeaderMobile.tsx +55 -41
  55. package/src/components/navigation/MobileMenuItem.tsx +15 -2
  56. package/src/components/navigation/NavWithTooltip.tsx +26 -0
  57. package/src/components/navigation/index.ts +2 -0
  58. package/src/components/navigation/sideBarNavLinkClass.ts +9 -6
  59. package/src/components/post/CompactReplyParent.tsx +17 -10
  60. package/src/components/post/TruncatedMarkdown.tsx +91 -0
  61. package/src/components/post/helpers.ts +4 -18
  62. package/src/components/post/index.ts +2 -0
  63. package/src/components/post/pieces/EventLocation.tsx +27 -0
  64. package/src/components/post/pieces/EventRsvpButton.tsx +3 -0
  65. package/src/components/post/pieces/PollContent.tsx +8 -2
  66. package/src/components/post/post-form/ArticleForm.tsx +1 -1
  67. package/src/components/post/post-form/EventForm.tsx +43 -15
  68. package/src/components/post/post-form/ResourceForm.tsx +132 -4
  69. package/src/components/post/post-form/VisibilitySelector.tsx +11 -3
  70. package/src/components/post/types/Article.tsx +5 -5
  71. package/src/components/post/types/Event.tsx +68 -7
  72. package/src/components/post/types/resource/FullResource.tsx +9 -1
  73. package/src/components/preview-link/local/WelcomePreview.tsx +11 -2
  74. package/src/components/resources/ResourceCard.tsx +68 -10
  75. package/src/components/resources/ResourceLibrary.tsx +2 -2
  76. package/src/hooks/events/useEventRsvp.ts +19 -7
  77. package/src/hooks/posts/useResourceComposer.ts +157 -33
  78. package/src/hooks/resources/useResourceLibrary.ts +6 -2
  79. package/src/hooks/useWelcomePreview.ts +4 -0
  80. package/src/navigation/menuItems.ts +16 -0
  81. package/src/navigation/targets.ts +2 -0
  82. package/src/pages/admin/community/CommunityMarkdownPage.tsx +5 -1
  83. package/src/pages/auth/Register.tsx +12 -0
  84. package/src/pages/resources/Edit.tsx +3 -2
  85. package/src/pages/resources/New.tsx +6 -1
  86. package/src/pages/settings/Account.tsx +51 -1
@@ -19,15 +19,21 @@ export const VisibilitySelector = ({ postData, onClick, disabled = false, showDi
19
19
  }), [postData.type, authData, t, serverInfo.publicContent, showDirect]);
20
20
  const selectedGroup = useMemo(() => me?.memberships?.find((m) => m.group.id === postData.groupId)?.group, [me?.memberships, postData.groupId]);
21
21
  const description = (visibility) => audienceChoices.find((c) => c.value === visibility)?.description ?? '';
22
+ const choiceLabel = (visibility) => description(visibility) ||
23
+ (audienceChoices.length > 0
24
+ ? t('posts.form.chooseAudience', {
25
+ defaultValue: 'Choose who can see this',
26
+ })
27
+ : '');
22
28
  const content = () => {
23
29
  if (postData.visibility === 'group') {
24
- return (_jsxs("span", { className: "flex min-w-0 items-center gap-1 text-sm font-normal", children: [_jsx("span", { className: "shrink-0 pr-2", children: description('group') }), selectedGroup ? (_jsxs("span", { className: "flex min-w-0 items-center gap-1 truncate", children: [_jsx(GroupAvatar, { group: selectedGroup, size: 1.5, borderless: true }), _jsx("span", { className: "truncate", children: groupName(selectedGroup) })] })) : null] }));
30
+ return (_jsxs("span", { className: "flex min-w-0 items-center gap-1 text-sm font-normal", children: [_jsx("span", { className: "shrink-0 pr-2", children: choiceLabel('group') }), selectedGroup ? (_jsxs("span", { className: "flex min-w-0 items-center gap-1 truncate", children: [_jsx(GroupAvatar, { group: selectedGroup, size: 1.5, borderless: true }), _jsx("span", { className: "truncate", children: groupName(selectedGroup) })] })) : null] }));
25
31
  }
26
32
  if (postData.visibility === 'direct') {
27
33
  const audience = postData.audience ?? [];
28
- return (_jsxs("span", { className: "flex min-w-0 items-center gap-1 text-sm font-light", children: [_jsx("span", { className: "shrink-0 pr-2", children: description('direct') }), audience.length ? (_jsx("span", { className: "flex min-w-0 flex-wrap items-center gap-1", children: audience.map((profile) => (_jsx(ProfileBadge, { profile: profile }, profile.id))) })) : null] }));
34
+ return (_jsxs("span", { className: "flex min-w-0 items-center gap-1 text-sm font-light", children: [_jsx("span", { className: "shrink-0 pr-2", children: choiceLabel('direct') }), audience.length ? (_jsx("span", { className: "flex min-w-0 flex-wrap items-center gap-1", children: audience.map((profile) => (_jsx(ProfileBadge, { profile: profile }, profile.id))) })) : null] }));
29
35
  }
30
- return (_jsx("span", { className: "text-sm font-light", children: description(postData.visibility) }));
36
+ return (_jsx("span", { className: "text-sm font-light", children: choiceLabel(postData.visibility) }));
31
37
  };
32
38
  return (_jsxs("div", { className: "op-input-group grid grid-cols-[auto_1fr_auto]", children: [_jsx("div", { className: "op-input-group-shim", children: _jsx(Eye, { className: "size-4" }) }), _jsx("button", { type: "button", title: t('posts.form.changeAudience', {
33
39
  defaultValue: 'Change audience',
@@ -2,8 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { ArrowRight } from 'lucide-react';
3
3
  import { useT } from '../../../i18n/index.js';
4
4
  import { resolveStaticUrl, useStaticRender } from '../../markdown/staticRender.js';
5
- import { PostMarkdown } from '../Markdown.js';
6
- import { OPENPEEPS_POST_CAPTION_CLASS } from '../../markdown/classes.js';
5
+ import { TruncatedMarkdown } from '../TruncatedMarkdown.js';
7
6
  import { firstNWords } from '../helpers.js';
8
7
  import { minutesToRead } from '@openpeepshq/common/lib';
9
8
  export function FeedArticle({ post }) {
@@ -13,5 +12,5 @@ export function FeedArticle({ post }) {
13
12
  const previewContent = firstNWords(article.content, 50);
14
13
  const minutes = minutesToRead(article.content);
15
14
  const showReadMore = !!article.content && previewContent.length < article.content.length;
16
- return (_jsxs("div", { className: "flex w-full min-w-0 flex-col gap-2", children: [article.image && (_jsx("img", { src: article.image, className: "w-full object-cover", alt: `image for ${article.title ?? 'article'}` })), _jsxs("div", { className: "prose-sm", children: [_jsx("h3", { className: "text-foreground", children: article.title }), minutes > 0 && (_jsx("p", { className: "text-muted-foreground text-xs", children: t('posts.article.minutesToRead', { count: minutes }) }))] }), _jsx(PostMarkdown, { source: `${previewContent}${showReadMore ? '...' : ''}`, className: OPENPEEPS_POST_CAPTION_CLASS }), showReadMore && (_jsx("div", { className: "flex justify-end", children: _jsxs("a", { href: resolveStaticUrl(`/posts/${post.id}`, staticRender ? baseUrl : undefined), className: "text-primary inline-flex items-center gap-1 text-sm hover:underline", children: [t('posts.article.readMore', { defaultValue: 'Read more' }), _jsx(ArrowRight, { className: "inline-block size-4" })] }) }))] }));
15
+ return (_jsxs("div", { className: "flex w-full min-w-0 flex-col gap-2", children: [article.image && (_jsx("img", { src: article.image, className: "w-full object-cover", alt: `image for ${article.title ?? 'article'}` })), _jsxs("div", { className: "prose-sm", children: [_jsx("h3", { className: "text-foreground", children: article.title }), minutes > 0 && (_jsx("p", { className: "text-muted-foreground text-xs", children: t('posts.article.minutesToRead', { count: minutes }) }))] }), _jsx(TruncatedMarkdown, { source: article.content ?? '', snippet: previewContent, interactive: false }), showReadMore && (_jsx("div", { className: "flex justify-end", children: _jsxs("a", { href: resolveStaticUrl(`/posts/${post.id}`, staticRender ? baseUrl : undefined), className: "text-primary inline-flex items-center gap-1 text-sm hover:underline", children: [t('posts.article.readMore', { defaultValue: 'Read more' }), _jsx(ArrowRight, { className: "inline-block size-4" })] }) }))] }));
17
16
  }
@@ -26,5 +26,14 @@ export function FeedEvent({ post }) {
26
26
  allDay: event.wholeDay,
27
27
  })
28
28
  : fmtRange(start, end);
29
- return (_jsxs("div", { className: "flex w-full flex-col gap-2", children: [event.image && (_jsx("span", { className: "aspect-video w-full overflow-hidden", children: _jsx("img", { src: event.image, className: "h-full w-full object-cover", alt: `image for ${event.name ?? 'event'}` }) })), _jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsxs("span", { className: "text-destructive text-sm", children: [when, ' ', staticRender ? null : (_jsx("span", { className: "text-muted-foreground", children: "(your local time)" }))] }), _jsx(Button, { action: resolveStaticUrl(`/posts/${post.id}`, staticRender ? baseUrl : undefined), variant: "outline", compact: true, className: "shrink-0", children: t('posts.event.viewEvent', { defaultValue: 'View Event' }) })] }), _jsx("div", { className: "text-lg font-medium", children: event.name }), event.recurrence ? (_jsx("p", { className: "text-muted-foreground text-sm", children: formatEventRecurrence(event.recurrence, t, event.start) })) : null, _jsx(EventLocation, { post: post })] }));
29
+ const viewEventHref = resolveStaticUrl(`/posts/${post.id}`, staticRender ? baseUrl : undefined);
30
+ if (staticRender) {
31
+ return (_jsx("table", { role: "presentation", width: "100%", cellPadding: 0, cellSpacing: 0, style: { width: '100%', borderCollapse: 'collapse' }, children: _jsxs("tbody", { children: [event.image ? (_jsx("tr", { children: _jsx("td", { style: { paddingBottom: '8px' }, children: _jsx("img", { src: event.image, alt: `image for ${event.name ?? 'event'}`, width: "100%", style: {
32
+ display: 'block',
33
+ width: '100%',
34
+ maxWidth: '100%',
35
+ height: 'auto',
36
+ } }) }) })) : null, _jsx("tr", { children: _jsx("td", { className: "text-destructive pb-2 text-sm", children: when }) }), _jsx("tr", { children: _jsx("td", { className: "pb-2 text-lg font-medium", children: event.name }) }), event.recurrence ? (_jsx("tr", { children: _jsx("td", { className: "text-muted-foreground pb-2 text-sm", children: formatEventRecurrence(event.recurrence, t, event.start) }) })) : null, event.physicalLocation || event.jam || event.url ? (_jsx("tr", { children: _jsx("td", { className: "pb-2", children: _jsx(EventLocation, { post: post }) }) })) : null, _jsx("tr", { children: _jsx("td", { children: _jsx("a", { href: viewEventHref, className: "text-primary text-sm underline", children: t('posts.event.viewEvent', { defaultValue: 'View Event' }) }) }) })] }) }));
37
+ }
38
+ return (_jsxs("div", { className: "flex w-full flex-col gap-2", children: [event.image && (_jsx("span", { className: "aspect-video w-full overflow-hidden", children: _jsx("img", { src: event.image, className: "h-full w-full object-cover", alt: `image for ${event.name ?? 'event'}` }) })), _jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsxs("span", { className: "text-destructive text-sm", children: [when, ' ', _jsx("span", { className: "text-muted-foreground", children: "(your local time)" })] }), _jsx(Button, { action: viewEventHref, variant: "outline", compact: true, className: "shrink-0", children: t('posts.event.viewEvent', { defaultValue: 'View Event' }) })] }), _jsx("div", { className: "text-lg font-medium", children: event.name }), event.recurrence ? (_jsx("p", { className: "text-muted-foreground text-sm", children: formatEventRecurrence(event.recurrence, t, event.start) })) : null, _jsx(EventLocation, { post: post })] }));
30
39
  }
@@ -83,17 +83,17 @@ export const FullResource = ({ post }) => {
83
83
  if (resource.resourceKind === 'video' && playerVisible) {
84
84
  const videoAtt = resource.attachments?.find((a) => attachmentMediaKind(a) === 'video');
85
85
  if (videoAtt) {
86
- return (_jsx(ResourceCard, { post: post, preview: _jsx(VideoPlayer, { attachment: videoAtt, className: "max-h-[600px] w-full" }) }));
86
+ return (_jsx(ResourceCard, { post: post, showDescription: false, inGroup: !!post.group, preview: _jsx(VideoPlayer, { attachment: videoAtt, className: "max-h-[600px] w-full" }) }));
87
87
  }
88
88
  }
89
89
  if (resource.resourceKind === 'audio' && playerVisible) {
90
90
  const audioAtt = resource.attachments?.find((a) => attachmentMediaKind(a) === 'audio');
91
91
  if (audioAtt?.url) {
92
- return (_jsx(ResourceCard, { post: post, preview: _jsx(AudioAttachment, { src: audioAtt.url, label: audioAtt.filename ?? audioAtt.description, size: audioAtt.meta?.size }) }));
92
+ return (_jsx(ResourceCard, { post: post, showDescription: false, inGroup: !!post.group, preview: _jsx(AudioAttachment, { src: audioAtt.url, label: audioAtt.filename ?? audioAtt.description, size: audioAtt.meta?.size }) }));
93
93
  }
94
94
  }
95
95
  // All kinds: ResourceCard with click overlay
96
- return (_jsxs("div", { className: "relative", children: [_jsx(ResourceCard, { post: post }), _jsx("div", { className: "pointer-events-none absolute left-0 right-0 top-0 flex h-48 items-center justify-center", children: _jsx("div", { className: "pointer-events-auto flex size-20 cursor-pointer items-center justify-center rounded-full bg-black/60 text-white", onClick: handlePreviewClick, role: "button", "aria-label": previewLabel(), children: previewIcon() }) })] }));
96
+ return (_jsxs("div", { className: "relative", children: [_jsx(ResourceCard, { post: post, showDescription: false, inGroup: !!post.group }), _jsx("div", { className: "pointer-events-none absolute left-0 right-0 top-0 flex h-48 items-center justify-center", children: _jsx("div", { className: "pointer-events-auto flex size-20 cursor-pointer items-center justify-center rounded-full bg-black/60 text-white", onClick: handlePreviewClick, role: "button", "aria-label": previewLabel(), children: previewIcon() }) })] }));
97
97
  };
98
98
  return (_jsx(FullPostLayout, { post: post, deleteCallback: () => window.history.back(), children: _jsxs("article", { className: "bg-background border-border relative min-w-0 border-b p-4", children: [_jsx(PostInfoHeader, { post: post, showMenu: true, deleteCallback: () => window.history.back() }), _jsxs("div", { className: "flex w-full min-w-0 flex-col gap-3", children: [renderMedia(), galleryIndex !== null ? (_jsx(GalleryModal, { attachments: resource.attachments ?? [], initialIndex: galleryIndex, onClose: () => setGalleryIndex(null) })) : null, resource?.content ? (_jsx(PostMarkdown, { source: resource.content })) : null] })] }) }));
99
99
  };
@@ -1,6 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useWelcomePreview } from '../../../hooks/useWelcomePreview.js';
3
+ import { truncateMarkdown, stripMarkdownImages } from '@openpeepshq/common/lib';
4
+ import { TruncatedMarkdown } from '../../post/TruncatedMarkdown.js';
3
5
  export const WelcomePreview = () => {
4
- const { eyebrow, title, description, imageUrl, imageFit } = useWelcomePreview();
5
- return (_jsxs("div", { "data-testid": "welcome-preview-card", className: "flex w-full min-w-0 flex-row items-center gap-4", children: [imageUrl ? (_jsx("div", { className: "flex h-24 w-24 shrink-0 items-center justify-center overflow-hidden rounded-md", children: _jsx("img", { src: imageUrl, alt: "", className: `h-full w-full ${imageFit === 'cover' ? 'object-cover' : 'object-contain'}` }) })) : null, _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [eyebrow ? (_jsx("p", { className: "text-muted-foreground truncate text-xs", children: eyebrow })) : null, _jsx("p", { className: "line-clamp-2 font-semibold", children: title }), description ? (_jsx("p", { className: "text-muted-foreground line-clamp-3 break-words text-sm", children: description })) : null] })] }));
6
+ const { eyebrow, title, description, markdown, imageUrl, imageFit } = useWelcomePreview();
7
+ return (_jsxs("div", { "data-testid": "welcome-preview-card", className: "flex w-full min-w-0 flex-row items-center gap-4", children: [imageUrl ? (_jsx("div", { className: "flex h-24 w-24 shrink-0 items-center justify-center overflow-hidden rounded-md", children: _jsx("img", { src: imageUrl, alt: "", className: `h-full w-full ${imageFit === 'cover' ? 'object-cover' : 'object-contain'}` }) })) : null, _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [eyebrow ? (_jsx("p", { className: "text-muted-foreground truncate text-xs", children: eyebrow })) : null, _jsx("p", { className: "line-clamp-2 font-semibold", children: title }), markdown ? (_jsx(TruncatedMarkdown, { source: markdown, snippet: truncateMarkdown(stripMarkdownImages(markdown), 2, 240), maxLines: 2, className: "break-words text-sm text-muted-foreground" })) : description ? (_jsx("p", { className: "text-muted-foreground line-clamp-3 break-words text-sm", children: description })) : null] })] }));
6
8
  };
@@ -4,5 +4,9 @@ export interface ResourceCardProps {
4
4
  post: PublicPost;
5
5
  layout?: 'card' | 'list';
6
6
  preview?: ReactNode;
7
+ /** Set false when the full description is rendered by the surrounding layout (e.g. the post detail page). */
8
+ showDescription?: boolean;
9
+ /** When true, hides the group label (already shown by the group context). */
10
+ inGroup?: boolean;
7
11
  }
8
- export declare const ResourceCard: ({ post, layout, preview, }: ResourceCardProps) => import("react/jsx-runtime").JSX.Element | null;
12
+ export declare const ResourceCard: ({ post, layout, preview, showDescription, inGroup, }: ResourceCardProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,11 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useMemo, useState } from 'react';
3
3
  import { BookmarkCheck, BookmarkPlus, Link as LinkIcon, ImageOff, } from 'lucide-react';
4
- import { attachmentMediaKind, normalizeResourceTags, truncateMarkdown, formatSize, } from '@openpeepshq/common/lib';
4
+ import { attachmentMediaKind, formatSize, groupName, normalizeResourceTags, } from '@openpeepshq/common/lib';
5
+ import { useHrefOf } from '../../contexts/router/index.js';
5
6
  import { useT } from '../../i18n/index.js';
6
7
  import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
7
8
  import { useCurrentProfile } from '../layout/IdentityContext.js';
8
9
  import { VideoPlayOverlay } from '../post/VideoPlayOverlay.js';
10
+ import { TruncatedMarkdown } from '../post/TruncatedMarkdown.js';
11
+ import { useNavigate } from '../../contexts/router/index.js';
9
12
  const visualAttachments = (attachments) => attachments.filter((att) => attachmentMediaKind(att) !== 'audio');
10
13
  const previewSrc = (att) => att.previewUrl ?? att.url;
11
14
  /** Thumbnail size shared between list and card previews. */
@@ -35,8 +38,10 @@ const MediaPreview = ({ src, alt, className, isVideo, isLast, extra, }) => {
35
38
  }
36
39
  return (_jsxs(_Fragment, { children: [_jsx("img", { src: src, alt: alt, className: className, onError: () => setErrored(true) }), isVideo ? _jsx(VideoPlayOverlay, { video: true }) : null, isLast && extra > 0 ? (_jsxs("div", { className: "absolute inset-0 flex items-center justify-center bg-black/60 text-lg font-semibold text-white", children: ["+", extra] })) : null] }));
37
40
  };
38
- export const ResourceCard = ({ post, layout = 'card', preview, }) => {
41
+ export const ResourceCard = ({ post, layout = 'card', preview, showDescription = true, inGroup = false, }) => {
39
42
  const t = useT();
43
+ const navigate = useNavigate();
44
+ const hrefOf = useHrefOf();
40
45
  const { openpeepsApi } = useOpenpeeps();
41
46
  const me = useCurrentProfile();
42
47
  if (post.data?.type !== 'resource')
@@ -44,7 +49,6 @@ export const ResourceCard = ({ post, layout = 'card', preview, }) => {
44
49
  const resource = post.data;
45
50
  const attachments = resource.attachments ?? [];
46
51
  const visuals = visualAttachments(attachments);
47
- const excerpt = truncateMarkdown(resource.content, 2, 240);
48
52
  const tags = normalizeResourceTags(resource.tags);
49
53
  const isGallery = resource.resourceKind === 'gallery' && visuals.length > 1;
50
54
  const tiles = isGallery ? visuals.slice(0, 4) : visuals.slice(0, 1);
@@ -52,6 +56,8 @@ export const ResourceCard = ({ post, layout = 'card', preview, }) => {
52
56
  const actionLabel = primaryActionLabel(resource.resourceKind, t);
53
57
  const thumbnail = visuals[0];
54
58
  const thumbSrc = thumbnail ? previewSrc(thumbnail) : null;
59
+ const group = post.group;
60
+ const groupLabel = group ? groupName(group) : null;
55
61
  const metaText = useMemo(() => {
56
62
  if (resource.resourceKind === 'gallery' && visuals.length > 1) {
57
63
  return t('resources.meta.imagesCount', {
@@ -91,6 +97,20 @@ export const ResourceCard = ({ post, layout = 'card', preview, }) => {
91
97
  }, disabled: !me, className: className, title: isBookmarked
92
98
  ? t('resources.actions.saved', { defaultValue: 'Saved' })
93
99
  : t('resources.actions.save', { defaultValue: 'Save' }), children: isBookmarked ? (_jsx(BookmarkCheck, { className: "text-primary size-4" })) : (_jsx(BookmarkPlus, { className: "size-4" })) }));
100
+ const renderGroupLabel = () => {
101
+ if (!group || !groupLabel || inGroup)
102
+ return null;
103
+ const groupHref = hrefOf({ type: 'group', handle: group.handle });
104
+ return (_jsx("a", { href: groupHref, onClick: (e) => {
105
+ e.stopPropagation();
106
+ }, className: "text-muted-foreground hover:text-foreground inline-flex items-center gap-1 text-xs", title: t('resources.group.inGroup', {
107
+ defaultValue: 'in {{groupName}}',
108
+ groupName: groupLabel,
109
+ }), children: _jsx("span", { className: "bg-muted rounded-full px-2 py-0.5 text-xs", children: t('resources.group.inGroup', {
110
+ defaultValue: 'in {{groupName}}',
111
+ groupName: groupLabel,
112
+ }) }) }));
113
+ };
94
114
  const renderThumbnail = () => {
95
115
  if (thumbSrc) {
96
116
  return (_jsx("img", { src: thumbSrc, alt: thumbnail?.description ?? resource.title, className: THUMB_CLASS, onError: (e) => {
@@ -103,7 +123,7 @@ export const ResourceCard = ({ post, layout = 'card', preview, }) => {
103
123
  return null;
104
124
  };
105
125
  if (layout === 'list') {
106
- return (_jsxs("div", { className: "flex w-full min-w-0 items-center gap-3 px-4 py-3", children: [renderThumbnail(), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("h3", { className: "text-lg font-semibold", children: resource.title }), resource.categoryPath?.length ? (_jsx("p", { className: "text-muted-foreground text-xs", children: resource.categoryPath.join(' / ') })) : null, excerpt ? (_jsx("p", { className: "text-muted-foreground text-sm", children: excerpt })) : null, metaText ? (_jsx("p", { className: "text-muted-foreground text-xs", children: metaText })) : null] }), _jsxs("div", { className: "flex items-center gap-2", children: [resource.resourceKind === 'link' &&
126
+ return (_jsxs("div", { className: "flex w-full min-w-0 items-center gap-3 px-4 py-3", children: [renderThumbnail(), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("h3", { className: "text-lg font-semibold", children: resource.title }), resource.categoryPath?.length ? (_jsx("p", { className: "text-muted-foreground text-xs", children: resource.categoryPath.join(' / ') })) : null, renderGroupLabel(), showDescription ? (_jsx(TruncatedMarkdown, { source: resource.content ?? '', maxBlocks: 2, maxChars: 240, maxLines: 2, className: "text-sm text-muted-foreground" })) : null, metaText ? (_jsx("p", { className: "text-muted-foreground text-xs", children: metaText })) : null] }), _jsxs("div", { className: "flex items-center gap-2", children: [resource.resourceKind === 'link' &&
107
127
  resource.url ? null : actionLabel ? (resource.resourceKind === 'file' && downloadUrl ? (_jsx("a", { href: downloadUrl, download: true, onClick: (e) => e.stopPropagation(), className: "text-primary text-xs font-medium", children: actionLabel })) : (_jsx("span", { className: "text-muted-foreground text-xs", children: actionLabel }))) : null, renderBookmarkButton('text-muted-foreground hover:text-foreground disabled:opacity-50')] })] }));
108
128
  }
109
129
  return (_jsxs("div", { className: "flex w-full min-w-0 flex-col gap-2", children: [_jsxs("div", { className: "relative", children: [preview ? (preview) : tiles.length ? (_jsx("div", { className: `overflow-hidden rounded-md ${tiles.length > 1
@@ -115,7 +135,11 @@ export const ResourceCard = ({ post, layout = 'card', preview, }) => {
115
135
  return (_jsx("div", { className: "bg-surface relative h-full w-full overflow-hidden", children: _jsx(MediaPreview, { src: src, alt: att.description ?? resource.title, className: tiles.length > 1
116
136
  ? 'h-full w-full object-cover'
117
137
  : CARD_IMG_CLASS, isVideo: kind === 'video', isLast: last, extra: extra }) }, `${att.url ?? index}-${index}`));
118
- }) })) : resource.resourceKind === 'link' && resource.url ? (_jsx("div", { className: "bg-muted flex h-48 w-full items-center justify-center rounded-md", children: _jsx(LinkIcon, { className: "text-muted-foreground/50 size-8" }) })) : null, renderBookmarkButton('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')] }), _jsx("h3", { className: "text-lg font-semibold", children: resource.title }), resource.categoryPath?.length ? (_jsx("p", { className: "text-muted-foreground text-xs", children: resource.categoryPath.join(' / ') })) : null, excerpt ? (_jsx("p", { className: "text-muted-foreground text-sm", children: excerpt })) : null, metaText ? (_jsx("p", { className: "text-muted-foreground text-xs", children: metaText })) : null, tags.length ? (_jsx("div", { className: "flex flex-wrap gap-1", children: tags.map((value) => (_jsxs("span", { className: "bg-muted text-muted-foreground rounded-full px-2 py-0.5 text-xs", children: ["#", value] }, value))) })) : null, _jsx("p", { className: "text-muted-foreground text-xs uppercase", children: t(`resources.kinds.${resource.resourceKind}`, {
138
+ }) })) : resource.resourceKind === 'link' && resource.url ? (_jsx("div", { className: "bg-muted flex h-48 w-full items-center justify-center rounded-md", children: _jsx(LinkIcon, { className: "text-muted-foreground/50 size-8" }) })) : null, renderBookmarkButton('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')] }), _jsx("h3", { className: "text-lg font-semibold", children: resource.title }), resource.categoryPath?.length ? (_jsx("p", { className: "text-muted-foreground text-xs", children: resource.categoryPath.join(' / ') })) : null, renderGroupLabel(), showDescription ? (_jsx(TruncatedMarkdown, { source: resource.content ?? '', maxBlocks: 2, maxChars: 240, maxLines: 2, className: "text-sm text-muted-foreground" })) : null, metaText ? (_jsx("p", { className: "text-muted-foreground text-xs", children: metaText })) : null, tags.length ? (_jsx("div", { className: "flex flex-wrap gap-1", children: tags.map((value) => (_jsxs("button", { type: "button", className: "bg-muted text-muted-foreground hover:text-foreground rounded-full px-2 py-0.5 text-xs", onClick: (e) => {
139
+ e.preventDefault();
140
+ e.stopPropagation();
141
+ navigate({ type: 'tags', hashtag: value });
142
+ }, children: ["#", value] }, value))) })) : null, _jsx("p", { className: "text-muted-foreground text-xs uppercase", children: t(`resources.kinds.${resource.resourceKind}`, {
119
143
  defaultValue: resource.resourceKind,
120
144
  }) })] }));
121
145
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
1
+ /** @vitest-environment jsdom */
2
+ import { act, createElement } from 'react';
3
+ import { createRoot } from 'react-dom/client';
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
+ import { ResourceCard } from './ResourceCard.js';
6
+ const navigate = vi.fn();
7
+ vi.mock('../../i18n', () => ({
8
+ useT: () => (key, opts) => opts?.defaultValue ?? key,
9
+ }));
10
+ vi.mock('../../contexts/openpeeps', () => ({
11
+ useOpenpeeps: () => ({
12
+ openpeepsApi: {
13
+ useCurrentProfileBookmarkedIds: () => ({ data: [] }),
14
+ bookmarkPostAction: () => async () => undefined,
15
+ unbookmarkPostAction: () => async () => undefined,
16
+ },
17
+ }),
18
+ }));
19
+ vi.mock('../layout/IdentityContext', () => ({
20
+ useCurrentProfile: () => undefined,
21
+ }));
22
+ vi.mock('../../contexts/router', () => ({
23
+ useNavigate: () => navigate,
24
+ useHrefOf: () => () => '#',
25
+ }));
26
+ vi.mock('../post/TruncatedMarkdown', () => ({
27
+ TruncatedMarkdown: () => null,
28
+ }));
29
+ vi.mock('../post/VideoPlayOverlay', () => ({
30
+ VideoPlayOverlay: () => null,
31
+ }));
32
+ const resourcePost = (tags) => ({
33
+ id: 'post-1',
34
+ type: 'resource',
35
+ data: {
36
+ type: 'resource',
37
+ title: 'Guide',
38
+ resourceKind: 'link',
39
+ url: 'https://example.com',
40
+ tags,
41
+ },
42
+ });
43
+ describe('ResourceCard', () => {
44
+ let root;
45
+ let container;
46
+ beforeEach(() => {
47
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
48
+ navigate.mockClear();
49
+ });
50
+ afterEach(() => {
51
+ act(() => {
52
+ root?.unmount();
53
+ });
54
+ container?.remove();
55
+ root = undefined;
56
+ container = undefined;
57
+ });
58
+ it('navigates to the tag page when a hashtag chip is clicked', async () => {
59
+ container = document.createElement('div');
60
+ document.body.appendChild(container);
61
+ root = createRoot(container);
62
+ await act(async () => {
63
+ root?.render(createElement(ResourceCard, { post: resourcePost(['Juneteenth']) }));
64
+ });
65
+ const chip = [...container.querySelectorAll('button')].find((button) => button.textContent === '#juneteenth');
66
+ expect(chip).toBeTruthy();
67
+ await act(async () => {
68
+ chip?.click();
69
+ });
70
+ expect(navigate).toHaveBeenCalledWith({
71
+ type: 'tags',
72
+ hashtag: 'juneteenth',
73
+ });
74
+ });
75
+ });
@@ -102,5 +102,5 @@ export const ResourceLibrary = ({ groupId }) => {
102
102
  })
103
103
  : t('resources.library.empty', {
104
104
  defaultValue: 'No resources yet.',
105
- }) })) : library.view === 'list' ? (_jsx("div", { className: "divide-border flex flex-col divide-y", children: library.posts.map((post) => (_jsx("a", { href: hrefOf({ type: 'post', id: post.id }), className: "block", children: _jsx(ResourceCard, { post: post, layout: "list" }) }, post.id))) })) : (_jsx("div", { className: "grid grid-cols-1 gap-4 p-4 sm:grid-cols-2 lg:grid-cols-3", children: library.posts.map((post) => (_jsx("a", { href: hrefOf({ type: 'post', id: post.id }), className: "block", children: _jsx(ResourceCard, { post: post, layout: "card" }) }, post.id))) }))] }));
105
+ }) })) : library.view === 'list' ? (_jsx("div", { className: "divide-border flex flex-col divide-y", children: library.posts.map((post) => (_jsx("a", { href: hrefOf({ type: 'post', id: post.id }), className: "block", children: _jsx(ResourceCard, { post: post, layout: "list", inGroup: !!groupId }) }, post.id))) })) : (_jsx("div", { className: "grid grid-cols-1 gap-4 p-4 sm:grid-cols-2 lg:grid-cols-3", children: library.posts.map((post) => (_jsx("a", { href: hrefOf({ type: 'post', id: post.id }), className: "block", children: _jsx(ResourceCard, { post: post, layout: "card", inGroup: !!groupId }) }, post.id))) }))] }));
106
106
  };
@@ -88,6 +88,7 @@ export declare const useEventRsvp: ({ post, recurrenceId, lockToOccurrence, onSu
88
88
  } | undefined;
89
89
  canRsvp: boolean;
90
90
  rsvpClosed: boolean;
91
+ hideRsvpButton: boolean;
91
92
  recurring: boolean;
92
93
  defaultId: string | undefined;
93
94
  occurrences: ExpandedOccurrence[];
@@ -1,5 +1,5 @@
1
1
  import { useMemo, useState } from 'react';
2
- import { canClaimYesRsvp, checkPostCapabilities, defaultRsvpRecurrenceId, displayRsvpForProfile, eventRsvpOpen, isCapacityEvent, isRecurringEvent, listRsvpOccurrences, offerStillOpen, seriesHasClaimableOccurrence, } from '@openpeepshq/common/lib';
2
+ import { canClaimYesRsvp, checkPostCapabilities, defaultRsvpRecurrenceId, displayRsvpForProfile, effectiveEventTimes, eventRsvpOpen, isCapacityEvent, isRecurringEvent, listRsvpOccurrences, occurrenceHasEnded, offerStillOpen, seriesHasClaimableOccurrence, } from '@openpeepshq/common/lib';
3
3
  import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
4
4
  import { useT } from '../../i18n/context.js';
5
5
  import { apiErrorMessage } from '../../lib/apiErrorMessage.js';
@@ -18,12 +18,17 @@ export const useEventRsvp = ({ post, recurrenceId, lockToOccurrence = false, onS
18
18
  const [submitting, setSubmitting] = useState(false);
19
19
  const eventData = post.data?.type === 'event' ? post.data : undefined;
20
20
  const recurring = eventData ? isRecurringEvent(eventData) : false;
21
+ const viewedTimes = eventData
22
+ ? effectiveEventTimes(eventData, recurrenceId)
23
+ : undefined;
24
+ // Series home shows its first start. Once that time has passed, RSVP stays
25
+ // off that page; upcoming dates are opened from their own links.
26
+ const viewedEnded = !!viewedTimes && occurrenceHasEnded(viewedTimes.start, viewedTimes.end);
27
+ // A selected date, or a one-off, is closed on its own end time.
21
28
  const rsvpClosed = eventData
22
- ? !eventRsvpOpen(eventData, { recurrenceId, lockToOccurrence })
29
+ ? !eventRsvpOpen(eventData, recurrenceId ? { recurrenceId, lockToOccurrence: true } : undefined)
23
30
  : false;
24
- const queriedOccurrenceClosed = !!eventData &&
25
- !!recurrenceId &&
26
- !eventRsvpOpen(eventData, { recurrenceId, lockToOccurrence: true });
31
+ const queriedOccurrenceClosed = !!recurrenceId && rsvpClosed;
27
32
  const defaultId = eventData
28
33
  ? defaultRsvpRecurrenceId(eventData, queriedOccurrenceClosed ? undefined : recurrenceId)
29
34
  : undefined;
@@ -77,7 +82,7 @@ export const useEventRsvp = ({ post, recurrenceId, lockToOccurrence = false, onS
77
82
  }
78
83
  };
79
84
  const requestJoinWaitlist = () => {
80
- if (rsvpClosed)
85
+ if (rsvpClosed || viewedEnded)
81
86
  return;
82
87
  if (!recurring || lockToOccurrence) {
83
88
  setError(null);
@@ -98,13 +103,15 @@ export const useEventRsvp = ({ post, recurrenceId, lockToOccurrence = false, onS
98
103
  }
99
104
  };
100
105
  const claimSpot = () => {
106
+ if (rsvpClosed || viewedEnded)
107
+ return;
101
108
  const id = recurring
102
109
  ? (myRsvp?.recurrenceId ?? (lockToOccurrence ? recurrenceId : defaultId))
103
110
  : undefined;
104
111
  writeRsvp('yes', id ? [id] : undefined).catch(() => undefined);
105
112
  };
106
113
  const requestRespond = (response) => {
107
- if (rsvpClosed)
114
+ if (rsvpClosed || viewedEnded)
108
115
  return;
109
116
  if (!recurring || lockToOccurrence) {
110
117
  writeRsvp(response, recurrenceId ? [recurrenceId] : undefined).catch(() => undefined);
@@ -139,6 +146,7 @@ export const useEventRsvp = ({ post, recurrenceId, lockToOccurrence = false, onS
139
146
  myRsvp,
140
147
  canRsvp,
141
148
  rsvpClosed,
149
+ hideRsvpButton: rsvpClosed || viewedEnded,
142
150
  recurring,
143
151
  defaultId,
144
152
  occurrences,
@@ -360,6 +360,7 @@ export declare const useNewResource: () => {
360
360
  capabilitiesNeeded?: string[] | null | undefined;
361
361
  };
362
362
  setPostData: (data: PostCreationData) => void;
363
+ groupOnly: boolean;
363
364
  canSubmit: boolean;
364
365
  submitting: boolean;
365
366
  error: string | null;
@@ -12064,6 +12065,7 @@ export declare const useEditResource: (resourceId: string) => {
12064
12065
  capabilitiesNeeded?: string[] | null | undefined;
12065
12066
  } | null>>;
12066
12067
  resourceTitle: string | undefined;
12068
+ canSubmit: boolean;
12067
12069
  submitting: boolean;
12068
12070
  error: string | null;
12069
12071
  clearError: () => void;
@@ -1,9 +1,11 @@
1
- import { useCallback, useEffect, useState } from 'react';
2
- import { normalizeResourceTags, resourceHasRequiredMedia, } from '@openpeepshq/common/lib';
1
+ import { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import { checkGroupCapabilities, normalizeResourceTags, resourceFormIssues, resourceVisibilityForCapabilities, } from '@openpeepshq/common/lib';
3
3
  import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
4
4
  import { useNavigate } from '../../contexts/router/index.js';
5
5
  import { useT } from '../../i18n/context.js';
6
+ import { useAuthData, useCurrentProfile, } from '../../components/layout/IdentityContext.js';
6
7
  import { useServerInfo } from '../../components/server-data/index.js';
8
+ import { buildAudienceChoiceValues } from '../../lib/audienceChoices.js';
7
9
  import { defaultNewResource, getNewPostStores } from '../../stores/index.js';
8
10
  const asResource = (data) => data?.type === 'resource' ? data : null;
9
11
  const preparedResource = (resource) => ({
@@ -13,12 +15,69 @@ const preparedResource = (resource) => ({
13
15
  categoryPath: (resource.categoryPath ?? [])
14
16
  .map((segment) => segment.trim())
15
17
  .filter(Boolean),
16
- url: resource.url?.trim() || undefined,
18
+ url: resource.resourceKind === 'link'
19
+ ? resource.url?.trim() || undefined
20
+ : undefined,
17
21
  });
22
+ const issuesFor = (postData) => {
23
+ const resource = asResource(postData.data);
24
+ if (!resource)
25
+ return ['title'];
26
+ return resourceFormIssues({
27
+ title: resource.title,
28
+ resourceKind: resource.resourceKind,
29
+ url: resource.url,
30
+ attachments: resource.attachments,
31
+ visibility: postData.visibility,
32
+ audience: postData.audience,
33
+ groupId: postData.groupId,
34
+ });
35
+ };
36
+ const issueMessage = (issue, t) => {
37
+ if (issue === 'title') {
38
+ return t('resources.validation.titleRequired', {
39
+ defaultValue: 'Title is required',
40
+ });
41
+ }
42
+ if (issue === 'titleLength') {
43
+ return t('resources.validation.titleTooLong', {
44
+ defaultValue: 'Title must be 200 characters or fewer',
45
+ });
46
+ }
47
+ if (issue === 'url') {
48
+ return t('resources.validation.url', {
49
+ defaultValue: 'Enter a real link, like https://example.com',
50
+ });
51
+ }
52
+ if (issue === 'media') {
53
+ return t('resources.validation.mediaRequired', {
54
+ defaultValue: 'Add the media or link this resource needs',
55
+ });
56
+ }
57
+ if (issue === 'group') {
58
+ return t('resources.validation.groupRequired', {
59
+ defaultValue: 'Choose a group before creating this resource.',
60
+ });
61
+ }
62
+ return t('resources.validation.directAudience', {
63
+ defaultValue: 'Choose at least one recipient for a direct resource.',
64
+ });
65
+ };
66
+ const submitErrorMessage = (err, t) => {
67
+ const message = err instanceof Error ? err.message : '';
68
+ if (message === 'Forbidden') {
69
+ return t('resources.validation.audienceForbidden', {
70
+ defaultValue: 'Choose a group you can post this resource in.',
71
+ });
72
+ }
73
+ return message;
74
+ };
18
75
  export const useNewResource = () => {
19
76
  const t = useT();
20
77
  const navigate = useNavigate();
21
78
  const serverInfo = useServerInfo();
79
+ const authData = useAuthData();
80
+ const me = useCurrentProfile();
22
81
  const { openpeepsApi } = useOpenpeeps();
23
82
  const createPost = openpeepsApi.createPostAction();
24
83
  const stores = getNewPostStores();
@@ -31,33 +90,71 @@ export const useNewResource = () => {
31
90
  });
32
91
  const [submitting, setSubmitting] = useState(false);
33
92
  const [error, setError] = useState(null);
93
+ const audience = useMemo(() => {
94
+ if (!authData.profile || authData.scopes.length === 0)
95
+ return null;
96
+ const choices = buildAudienceChoiceValues('resource', authData, t, {
97
+ publicContent: serverInfo.publicContent,
98
+ showDirect: true,
99
+ });
100
+ const memberships = me?.memberships;
101
+ const postableGroupIds = memberships == null
102
+ ? null
103
+ : memberships
104
+ .map((membership) => membership.group)
105
+ .filter((group) => checkGroupCapabilities(authData, ['core-posts-create-resource'], group).success)
106
+ .map((group) => group.id);
107
+ const next = resourceVisibilityForCapabilities({
108
+ visibility: postData.visibility,
109
+ groupId: postData.groupId,
110
+ allowed: choices.map((choice) => choice.value),
111
+ postableGroupIds,
112
+ });
113
+ return {
114
+ ...next,
115
+ groupOnly: choices.length === 1 && choices[0]?.value === 'group',
116
+ hasChoice: choices.length > 0,
117
+ };
118
+ }, [
119
+ authData,
120
+ me?.memberships,
121
+ postData.groupId,
122
+ postData.visibility,
123
+ serverInfo.publicContent,
124
+ t,
125
+ ]);
126
+ useEffect(() => {
127
+ if (!audience?.hasChoice)
128
+ return;
129
+ if (audience.visibility === postData.visibility &&
130
+ (audience.groupId ?? undefined) === (postData.groupId ?? undefined)) {
131
+ return;
132
+ }
133
+ const next = {
134
+ ...postData,
135
+ visibility: audience.visibility,
136
+ groupId: audience.groupId,
137
+ };
138
+ setPostDataState(next);
139
+ stores.resource = next;
140
+ }, [audience, postData, stores]);
34
141
  const resource = asResource(postData.data);
35
- const canSubmit = !!resource?.title.trim() &&
36
- !!resource &&
37
- resourceHasRequiredMedia(resource) &&
38
- !(postData.visibility === 'direct' && !postData.audience?.length);
142
+ const audienceReady = !!audience?.hasChoice &&
143
+ audience.visibility === postData.visibility &&
144
+ (audience.groupId ?? undefined) === (postData.groupId ?? undefined);
145
+ const canSubmit = audienceReady && issuesFor(postData).length === 0;
39
146
  const setPostData = (data) => {
40
147
  setPostDataState(data);
41
148
  stores.resource = data;
42
149
  };
43
150
  const submit = useCallback(async () => {
44
151
  setError(null);
45
- if (!resource?.title.trim()) {
46
- setError(t('resources.validation.titleRequired', {
47
- defaultValue: 'Title is required',
48
- }));
152
+ if (!audienceReady)
49
153
  return;
50
- }
51
- if (!resourceHasRequiredMedia(resource)) {
52
- setError(t('resources.validation.mediaRequired', {
53
- defaultValue: 'Add the media or link this resource needs',
54
- }));
55
- return;
56
- }
57
- if (postData.visibility === 'direct' && !postData.audience?.length) {
58
- setError(t('resources.validation.directAudience', {
59
- defaultValue: 'Choose at least one recipient for a direct resource.',
60
- }));
154
+ const issue = issuesFor(postData)[0];
155
+ if (!resource || issue) {
156
+ if (issue)
157
+ setError(issueMessage(issue, t));
61
158
  return;
62
159
  }
63
160
  setSubmitting(true);
@@ -71,15 +168,16 @@ export const useNewResource = () => {
71
168
  navigate({ type: 'post', id: created.id });
72
169
  }
73
170
  catch (err) {
74
- setError(err.message);
171
+ setError(submitErrorMessage(err, t));
75
172
  }
76
173
  finally {
77
174
  setSubmitting(false);
78
175
  }
79
- }, [createPost, navigate, postData, resource, stores, t]);
176
+ }, [audienceReady, createPost, navigate, postData, resource, stores, t]);
80
177
  return {
81
178
  postData,
82
179
  setPostData,
180
+ groupOnly: audience?.groupOnly ?? false,
83
181
  canSubmit,
84
182
  submitting,
85
183
  error,
@@ -88,6 +186,7 @@ export const useNewResource = () => {
88
186
  };
89
187
  };
90
188
  export const useEditResource = (resourceId) => {
189
+ const t = useT();
91
190
  const navigate = useNavigate();
92
191
  const { openpeepsApi } = useOpenpeeps();
93
192
  const postQuery = openpeepsApi.usePost(resourceId);
@@ -109,6 +208,7 @@ export const useEditResource = (resourceId) => {
109
208
  }
110
209
  }, [postQuery.data]);
111
210
  const resourceTitle = asResource(postQuery.data?.data)?.title;
211
+ const canSubmit = !!postData && issuesFor(postData).length === 0;
112
212
  const submit = useCallback(async () => {
113
213
  if (!postData)
114
214
  return;
@@ -116,6 +216,11 @@ export const useEditResource = (resourceId) => {
116
216
  if (!resource)
117
217
  return;
118
218
  setError(null);
219
+ const issue = issuesFor(postData)[0];
220
+ if (issue) {
221
+ setError(issueMessage(issue, t));
222
+ return;
223
+ }
119
224
  setSubmitting(true);
120
225
  try {
121
226
  await updatePost(preparedResource(resource));
@@ -127,12 +232,13 @@ export const useEditResource = (resourceId) => {
127
232
  finally {
128
233
  setSubmitting(false);
129
234
  }
130
- }, [navigate, postData, resourceId, updatePost]);
235
+ }, [navigate, postData, resourceId, t, updatePost]);
131
236
  return {
132
237
  postQuery,
133
238
  postData,
134
239
  setPostData,
135
240
  resourceTitle,
241
+ canSubmit,
136
242
  submitting,
137
243
  error,
138
244
  clearError: () => setError(null),
@@ -1,4 +1,4 @@
1
- export declare const useResourceLibrary: (groupId?: string) => {
1
+ export declare const useResourceLibrary: (groupId?: string, ungrouped?: boolean) => {
2
2
  query: import("@tanstack/react-query").UseInfiniteQueryResult<import("@tanstack/react-query").InfiniteData<{
3
3
  id: string;
4
4
  type: "event" | "resource" | "note" | "question" | "article";