@openpeepshq/react 0.7.0 → 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.
- package/dist/components/configuration/ConfigurationCategory.js +3 -2
- package/dist/components/configuration/ConfigurationList.js +1 -1
- package/dist/components/form/LocationInput.js +1 -1
- package/dist/components/jams/JamCapacityGate.js +1 -1
- package/dist/components/jams/JamConference.js +2 -0
- package/dist/components/jams/JamParticipantConference.js +2 -0
- package/dist/components/jams/JamRoom.js +2 -3
- package/dist/components/jams/LiveJamsSection.js +8 -2
- package/dist/components/jams/LivekitUnavailableNotice.d.ts +9 -0
- package/dist/components/jams/LivekitUnavailableNotice.js +19 -0
- package/dist/components/jams/dropLateAudio.d.ts +22 -0
- package/dist/components/jams/dropLateAudio.js +115 -0
- package/dist/components/jams/index.d.ts +1 -0
- package/dist/components/jams/index.js +1 -0
- 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/notifications/TypedNotification.js +46 -4
- package/dist/components/post/CompactReplyParent.js +5 -6
- package/dist/components/post/Markdown.d.ts +2 -2
- package/dist/components/post/Markdown.js +1 -1
- package/dist/components/post/TruncatedMarkdown.d.ts +27 -0
- package/dist/components/post/TruncatedMarkdown.js +37 -0
- package/dist/components/post/attachmentPreview.js +1 -1
- 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/Attachments.js +23 -17
- package/dist/components/post/pieces/EventLocation.js +14 -0
- package/dist/components/post/pieces/EventRsvpButton.js +39 -7
- package/dist/components/post/pieces/EventRsvpList.js +23 -3
- package/dist/components/post/pieces/EventRsvpScopeDialog.d.ts +1 -1
- package/dist/components/post/pieces/EventRsvpScopeDialog.js +34 -22
- package/dist/components/post/pieces/EventWaitlistJoinDialog.d.ts +10 -0
- package/dist/components/post/pieces/EventWaitlistJoinDialog.js +26 -0
- package/dist/components/post/pieces/ParticipantsCard.d.ts +1 -1
- package/dist/components/post/pieces/ParticipantsCard.js +1 -1
- package/dist/components/post/pieces/PollContent.js +8 -2
- package/dist/components/post/pieces/PostActions.d.ts +1 -1
- package/dist/components/post/pieces/PostActions.js +20 -12
- package/dist/components/post/pieces/ShareMenu.d.ts +6 -1
- package/dist/components/post/pieces/ShareMenu.js +40 -7
- package/dist/components/post/post-form/ArticleForm.js +1 -1
- package/dist/components/post/post-form/EventForm.js +33 -5
- package/dist/components/post/post-form/ResourceForm.d.ts +3 -1
- package/dist/components/post/post-form/ResourceForm.js +48 -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/article/FullArticle.js +1 -1
- package/dist/components/post/types/event/CardEvent.js +2 -1
- package/dist/components/post/types/event/FullEvent.js +22 -13
- package/dist/components/post/types/event/ProfileEventRelationship.js +8 -0
- package/dist/components/post/types/resource/FullResource.js +3 -3
- package/dist/components/preview-link/LocalPreviewLink.js +4 -2
- package/dist/components/preview-link/PreviewLink.js +1 -1
- package/dist/components/preview-link/helpers.d.ts +5 -0
- package/dist/components/preview-link/helpers.js +27 -1
- package/dist/components/preview-link/local/WelcomePreview.d.ts +1 -0
- package/dist/components/preview-link/local/WelcomePreview.js +8 -0
- package/dist/components/profile/Avatar.js +2 -2
- package/dist/components/profile/ProfileFromId.js +1 -1
- package/dist/components/resources/ResourceCard.d.ts +5 -1
- package/dist/components/resources/ResourceCard.js +29 -5
- 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/components/server-data/context.d.ts +1 -0
- package/dist/contexts/openpeeps/hooks/accounts.d.ts +5 -5
- package/dist/contexts/openpeeps/hooks/accounts.js +1 -3
- package/dist/contexts/openpeeps/hooks/admin.d.ts +165 -66
- package/dist/contexts/openpeeps/hooks/admin.js +11 -3
- package/dist/contexts/openpeeps/hooks/auth.d.ts +2 -2
- package/dist/contexts/openpeeps/hooks/groups.d.ts +8 -8
- package/dist/contexts/openpeeps/hooks/jams.d.ts +73 -24
- package/dist/contexts/openpeeps/hooks/other.d.ts +7 -6
- package/dist/contexts/openpeeps/hooks/payments.d.ts +2 -2
- package/dist/contexts/openpeeps/hooks/posts.d.ts +368 -170
- package/dist/contexts/openpeeps/hooks/streaming.d.ts +1 -1
- package/dist/hooks/admin/useCanAccessAdminSection.d.ts +13 -0
- package/dist/hooks/admin/useCanAccessAdminSection.js +21 -0
- package/dist/hooks/events/useEventComposer.d.ts +94 -41
- package/dist/hooks/events/useEventForm.d.ts +1 -0
- package/dist/hooks/events/useEventRsvp.d.ts +12 -2
- package/dist/hooks/events/useEventRsvp.js +59 -10
- package/dist/hooks/events/useEventsCalendar.d.ts +174 -76
- package/dist/hooks/groups/useNewGroup.js +22 -2
- package/dist/hooks/index.d.ts +5 -1
- package/dist/hooks/index.js +4 -1
- package/dist/hooks/jams/useCanDiagnoseLivekit.d.ts +2 -0
- package/dist/hooks/jams/useCanDiagnoseLivekit.js +3 -0
- package/dist/hooks/jams/useCreateNewJamForm.d.ts +3 -1
- package/dist/hooks/jams/useJamDetails.d.ts +87 -38
- package/dist/hooks/jams/useJamLobby.d.ts +1 -0
- package/dist/hooks/jams/useJamRoom.d.ts +175 -76
- package/dist/hooks/posts/useArticleComposer.d.ts +93 -41
- package/dist/hooks/posts/useFeedPostPresentation.d.ts +174 -76
- package/dist/hooks/posts/usePostDetailTitle.d.ts +87 -38
- package/dist/hooks/posts/useResourceComposer.d.ts +95 -41
- package/dist/hooks/posts/useResourceComposer.js +135 -27
- package/dist/hooks/posts/useShareMenu.d.ts +2 -0
- package/dist/hooks/posts/useShareMenu.js +7 -0
- package/dist/hooks/resources/useResourceLibrary.d.ts +177 -79
- package/dist/hooks/resources/useResourceLibrary.js +6 -2
- package/dist/hooks/settings/useNotificationPreferences.d.ts +1 -1
- package/dist/hooks/useWelcomePreview.d.ts +16 -0
- package/dist/hooks/useWelcomePreview.js +40 -0
- package/dist/lib/groupFormErrors.d.ts +1 -0
- package/dist/lib/groupFormErrors.js +5 -2
- package/dist/lib/threadHelpers.js +1 -5
- package/dist/navigation/menuItems.js +15 -0
- package/dist/navigation/targets.d.ts +2 -0
- package/dist/pages/admin/ConfigurationCommunity.js +1 -1
- package/dist/pages/admin/Diagnostics.js +1 -1
- package/dist/pages/admin/DiagnosticsLivekit.d.ts +1 -0
- package/dist/pages/admin/DiagnosticsLivekit.js +50 -0
- package/dist/pages/admin/Invites.js +5 -3
- package/dist/pages/admin/Media.d.ts +1 -0
- package/dist/pages/admin/Media.js +135 -0
- package/dist/pages/admin/community/CommunityForbiddenUsernames.d.ts +1 -0
- package/dist/pages/admin/community/CommunityForbiddenUsernames.js +106 -0
- package/dist/pages/admin/community/CommunityMarkdownPage.js +2 -1
- package/dist/pages/admin/community/CommunityRoles.js +1 -1
- package/dist/pages/admin/community/useCommunityConfig.d.ts +2 -0
- package/dist/pages/admin/components/EditInviteLinkModal.d.ts +5 -0
- package/dist/pages/admin/components/EditInviteLinkModal.js +131 -0
- package/dist/pages/auth/Register.js +33 -9
- package/dist/pages/conversations/Show.js +11 -0
- package/dist/pages/index.d.ts +3 -0
- package/dist/pages/index.js +3 -0
- package/dist/pages/jams/Index.js +2 -4
- 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/dist/pages/settings/PublicProfile.js +15 -3
- package/dist/pwa/sw.d.ts +0 -1
- package/dist/react-native.d.ts +1 -0
- package/dist/react-native.js +1 -0
- package/dist/stores/newPosts.d.ts +4 -2
- package/dist/stores/newPosts.js +6 -1
- package/package.json +12 -7
- package/src/components/configuration/ConfigurationCategory.tsx +23 -10
- package/src/components/configuration/ConfigurationList.tsx +6 -1
- package/src/components/form/LocationInput.tsx +7 -1
- package/src/components/jams/JamCapacityGate.tsx +1 -1
- package/src/components/jams/JamConference.tsx +2 -0
- package/src/components/jams/JamParticipantConference.tsx +2 -0
- package/src/components/jams/JamRoom.tsx +2 -6
- package/src/components/jams/LiveJamsSection.tsx +16 -2
- package/src/components/jams/LivekitUnavailableNotice.tsx +40 -0
- package/src/components/jams/dropLateAudio.ts +153 -0
- package/src/components/jams/index.ts +1 -0
- 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/notifications/TypedNotification.tsx +81 -9
- package/src/components/post/CompactReplyParent.tsx +17 -10
- package/src/components/post/Markdown.tsx +8 -2
- package/src/components/post/TruncatedMarkdown.tsx +91 -0
- package/src/components/post/attachmentPreview.ts +1 -3
- package/src/components/post/helpers.ts +4 -18
- package/src/components/post/index.ts +2 -0
- package/src/components/post/pieces/Attachments.tsx +93 -78
- package/src/components/post/pieces/EventLocation.tsx +27 -0
- package/src/components/post/pieces/EventRsvpButton.tsx +110 -7
- package/src/components/post/pieces/EventRsvpList.tsx +64 -0
- package/src/components/post/pieces/EventRsvpScopeDialog.tsx +39 -27
- package/src/components/post/pieces/EventWaitlistJoinDialog.tsx +77 -0
- package/src/components/post/pieces/ParticipantsCard.tsx +4 -1
- package/src/components/post/pieces/PollContent.tsx +8 -2
- package/src/components/post/pieces/PostActions.tsx +73 -42
- package/src/components/post/pieces/ShareMenu.tsx +67 -9
- package/src/components/post/post-form/ArticleForm.tsx +1 -1
- package/src/components/post/post-form/EventForm.tsx +69 -15
- package/src/components/post/post-form/ResourceForm.tsx +132 -4
- package/src/components/post/post-form/VisibilitySelector.tsx +12 -5
- package/src/components/post/types/Article.tsx +6 -6
- package/src/components/post/types/Event.tsx +68 -7
- package/src/components/post/types/article/FullArticle.tsx +2 -2
- package/src/components/post/types/event/CardEvent.tsx +26 -14
- package/src/components/post/types/event/FullEvent.tsx +48 -35
- package/src/components/post/types/event/ProfileEventRelationship.tsx +8 -0
- package/src/components/post/types/note/FullNote.tsx +1 -4
- package/src/components/post/types/poll/FullPoll.tsx +1 -4
- package/src/components/post/types/resource/FullResource.tsx +9 -1
- package/src/components/preview-link/LocalPreviewLink.tsx +4 -1
- package/src/components/preview-link/PreviewLink.tsx +2 -7
- package/src/components/preview-link/helpers.ts +32 -1
- package/src/components/preview-link/local/GroupPreview.tsx +1 -1
- package/src/components/preview-link/local/JamPreview.tsx +1 -1
- package/src/components/preview-link/local/WelcomePreview.tsx +45 -0
- package/src/components/profile/Avatar.tsx +6 -2
- package/src/components/profile/ProfileFromId.tsx +1 -5
- package/src/components/resources/ResourceCard.tsx +68 -11
- package/src/components/resources/ResourceLibrary.tsx +2 -2
- package/src/contexts/openpeeps/hooks/accounts.ts +1 -3
- package/src/contexts/openpeeps/hooks/admin.ts +11 -3
- package/src/contexts/openpeeps/hooks/other.ts +9 -12
- package/src/contexts/openpeeps/hooks/streaming.ts +3 -3
- package/src/css.d.ts +4 -0
- package/src/hooks/admin/useCanAccessAdminSection.ts +27 -0
- package/src/hooks/events/useEventRsvp.ts +69 -13
- package/src/hooks/groups/useNewGroup.ts +28 -3
- package/src/hooks/index.ts +8 -1
- package/src/hooks/jams/useCanDiagnoseLivekit.ts +5 -0
- package/src/hooks/posts/useResourceComposer.ts +165 -39
- package/src/hooks/posts/useShareMenu.ts +9 -0
- package/src/hooks/resources/useResourceLibrary.ts +6 -2
- package/src/hooks/useWelcomePreview.ts +61 -0
- package/src/i18n/I18nProvider.tsx +1 -4
- package/src/lib/groupFormErrors.ts +9 -2
- package/src/lib/threadHelpers.ts +1 -5
- package/src/navigation/menuItems.ts +16 -0
- package/src/navigation/targets.ts +2 -0
- package/src/pages/admin/ConfigurationCommunity.tsx +5 -0
- package/src/pages/admin/Diagnostics.tsx +4 -0
- package/src/pages/admin/DiagnosticsLivekit.tsx +147 -0
- package/src/pages/admin/Invites.tsx +23 -1
- package/src/pages/admin/Media.tsx +290 -0
- package/src/pages/admin/community/CommunityForbiddenUsernames.tsx +223 -0
- package/src/pages/admin/community/CommunityMarkdownPage.tsx +5 -1
- package/src/pages/admin/community/CommunityRoles.tsx +2 -2
- package/src/pages/admin/components/EditInviteLinkModal.tsx +263 -0
- package/src/pages/auth/Register.tsx +45 -4
- package/src/pages/conversations/Show.tsx +11 -0
- package/src/pages/index.ts +3 -0
- package/src/pages/jams/Index.tsx +2 -6
- package/src/pages/resources/Edit.tsx +3 -2
- package/src/pages/resources/New.tsx +6 -1
- package/src/pages/settings/Account.tsx +51 -1
- package/src/pages/settings/PublicProfile.tsx +20 -2
- package/src/pwa/sw.ts +6 -3
- package/src/pwa/useNotificationBadgeSync.ts +3 -1
- package/src/react-native.ts +1 -0
- package/src/stores/newPosts.ts +6 -1
- package/src/streaming.ts +3 -3
- package/dist/setupTests.d.ts +0 -1
- package/dist/setupTests.js +0 -5
|
@@ -1,21 +1,47 @@
|
|
|
1
|
+
import { markdownPlainText } from '@openpeepshq/common';
|
|
1
2
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3
|
+
const EXCERPT_MAX = 180;
|
|
2
4
|
export const isPostPath = (path) => path.startsWith('/posts/') && UUID_RE.test(path.substring(7));
|
|
3
5
|
export const isJamPath = (path) => path.startsWith('/events/') &&
|
|
4
6
|
UUID_RE.test(path.substring(8, 44)) &&
|
|
5
7
|
path.endsWith('/jam');
|
|
6
8
|
export const isGroupPath = (path) => path.startsWith('/groups/@');
|
|
9
|
+
export const isWelcomePath = (path) => path === '/welcome' || path === '/welcome/';
|
|
7
10
|
export const isLocalLink = (url, origin) => {
|
|
8
11
|
try {
|
|
9
12
|
const urlObj = new URL(url);
|
|
10
13
|
return (urlObj.origin === origin &&
|
|
11
14
|
(isPostPath(urlObj.pathname) ||
|
|
12
15
|
isJamPath(urlObj.pathname) ||
|
|
13
|
-
isGroupPath(urlObj.pathname)
|
|
16
|
+
isGroupPath(urlObj.pathname) ||
|
|
17
|
+
isWelcomePath(urlObj.pathname)));
|
|
14
18
|
}
|
|
15
19
|
catch {
|
|
16
20
|
return false;
|
|
17
21
|
}
|
|
18
22
|
};
|
|
23
|
+
/** Plain-text clip of the welcome page, without image markup. */
|
|
24
|
+
export const welcomePreviewExcerpt = (markdown) => {
|
|
25
|
+
const plain = markdownPlainText((markdown ?? '').replace(/!\[[^\]]*]\([^)]*\)/g, ' '));
|
|
26
|
+
if (plain.length <= EXCERPT_MAX)
|
|
27
|
+
return plain;
|
|
28
|
+
const cut = plain.slice(0, EXCERPT_MAX);
|
|
29
|
+
const lastSpace = cut.lastIndexOf(' ');
|
|
30
|
+
const clipped = lastSpace > 80 ? cut.slice(0, lastSpace) : cut;
|
|
31
|
+
return `${clipped.trimEnd()}…`;
|
|
32
|
+
};
|
|
33
|
+
/** First content image on the welcome page, ignoring inline data URLs. */
|
|
34
|
+
export const firstMarkdownImage = (markdown) => {
|
|
35
|
+
if (!markdown)
|
|
36
|
+
return undefined;
|
|
37
|
+
const pattern = /!\[[^\]]*]\(\s*(<([^>]+)>|([^\s)]+))/g;
|
|
38
|
+
for (const match of markdown.matchAll(pattern)) {
|
|
39
|
+
const src = (match[2] ?? match[3])?.trim();
|
|
40
|
+
if (src && !src.startsWith('data:'))
|
|
41
|
+
return src;
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
};
|
|
19
45
|
export const isValidUrl = (url) => {
|
|
20
46
|
if (!url)
|
|
21
47
|
return false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const WelcomePreview: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useWelcomePreview } from '../../../hooks/useWelcomePreview.js';
|
|
3
|
+
import { truncateMarkdown, stripMarkdownImages } from '@openpeepshq/common/lib';
|
|
4
|
+
import { TruncatedMarkdown } from '../../post/TruncatedMarkdown.js';
|
|
5
|
+
export const WelcomePreview = () => {
|
|
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] })] }));
|
|
8
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { getTheme, isDeletedProfile } from '@openpeepshq/common';
|
|
2
|
+
import { DELETED_AUTHOR_DISPLAY_NAME, getTheme, isDeletedProfile, } from '@openpeepshq/common';
|
|
3
3
|
import { UserX } from 'lucide-react';
|
|
4
4
|
import { useServerInfo } from '../server-data/index.js';
|
|
5
5
|
import { useCurrentProfileSettings } from '../layout/IdentityContext.js';
|
|
@@ -28,7 +28,7 @@ export function Avatar({ profile, size = 3.5, borderless = false, containerClass
|
|
|
28
28
|
width: `${size}rem`,
|
|
29
29
|
height: `${size}rem`,
|
|
30
30
|
backgroundColor,
|
|
31
|
-
}, children: deleted ? (_jsx(UserX, { "aria-label": profile?.displayName ||
|
|
31
|
+
}, children: deleted ? (_jsx(UserX, { "aria-label": profile?.displayName || DELETED_AUTHOR_DISPLAY_NAME, className: "text-muted-foreground", size: iconSize })) : src ? (_jsx("img", { src: svgCoverSrc(src), alt: profile?.displayName || profile?.handle || 'avatar', className: "h-full w-full rounded-full object-cover" })) : (_jsx("span", { className: "text-primary font-medium", style: { fontSize: `${size / 4}rem` }, children: getInitials(profile?.displayName, profile?.handle) })) }));
|
|
32
32
|
return (_jsx("div", { className: containerClassName, style: {
|
|
33
33
|
width: `${size}rem`,
|
|
34
34
|
height: `${size}rem`,
|
|
@@ -7,7 +7,7 @@ export function ProfileFromId({ profileId, avatarSize = 2, action, }) {
|
|
|
7
7
|
const profileQuery = openpeepsApi.useProfile(profileId);
|
|
8
8
|
const profile = profileQuery.data;
|
|
9
9
|
if (profileQuery.isLoading) {
|
|
10
|
-
return
|
|
10
|
+
return _jsx("div", { className: "text-muted-foreground py-2 text-sm", children: "Loading\u2026" });
|
|
11
11
|
}
|
|
12
12
|
if (!profile)
|
|
13
13
|
return null;
|
|
@@ -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,
|
|
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,
|
|
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,
|
|
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
|
};
|
|
@@ -70,6 +70,7 @@ export declare const useServerInfo: () => {
|
|
|
70
70
|
defaultTimeZone?: string | undefined;
|
|
71
71
|
defaultFeedFormat?: "threaded" | "linear" | undefined;
|
|
72
72
|
indexProfiles?: boolean | undefined;
|
|
73
|
+
additionalForbiddenHandles?: string[] | undefined;
|
|
73
74
|
};
|
|
74
75
|
roles: {
|
|
75
76
|
onRegistration: {
|
|
@@ -14,7 +14,7 @@ export declare const accountHooks: (client: OpenpeepsClient) => {
|
|
|
14
14
|
email?: string | undefined;
|
|
15
15
|
newPassword?: string | undefined;
|
|
16
16
|
confirmPassword?: string | undefined;
|
|
17
|
-
}, pathParams?:
|
|
17
|
+
}, pathParams?: never, queryParams?: never, headers?: Record<string, string>) => Promise<{
|
|
18
18
|
success: true;
|
|
19
19
|
}>;
|
|
20
20
|
createPushSubscriptionAction: (defaultPathParams?: undefined) => (input: {
|
|
@@ -93,7 +93,7 @@ export declare const accountHooks: (client: OpenpeepsClient) => {
|
|
|
93
93
|
report: boolean;
|
|
94
94
|
};
|
|
95
95
|
} | undefined;
|
|
96
|
-
}, pathParams?:
|
|
96
|
+
}, pathParams?: never, queryParams?: never, headers?: Record<string, string>) => Promise<{
|
|
97
97
|
type: "web";
|
|
98
98
|
endpoint: string;
|
|
99
99
|
keys: {
|
|
@@ -283,19 +283,19 @@ export declare const accountHooks: (client: OpenpeepsClient) => {
|
|
|
283
283
|
message?: string | undefined;
|
|
284
284
|
key?: string | undefined;
|
|
285
285
|
}>;
|
|
286
|
-
validationEmailAction: (defaultPathParams?: undefined) => (pathParams?:
|
|
286
|
+
validationEmailAction: (defaultPathParams?: undefined) => (pathParams?: never, queryParams?: never, headers?: Record<string, string>) => Promise<{
|
|
287
287
|
success: true;
|
|
288
288
|
}>;
|
|
289
289
|
testPushSubscriptionAction: (defaultPathParams?: undefined) => (input: {
|
|
290
290
|
subscriptionKey: string;
|
|
291
|
-
}, pathParams?:
|
|
291
|
+
}, pathParams?: never, queryParams?: never, headers?: Record<string, string>) => Promise<{
|
|
292
292
|
success: true;
|
|
293
293
|
}>;
|
|
294
294
|
deletePushSubscriptionAction: (defaultPathParams?: {
|
|
295
295
|
pushSubscriptionId: string;
|
|
296
296
|
} | undefined) => (pathParams?: {
|
|
297
297
|
pushSubscriptionId: string;
|
|
298
|
-
}
|
|
298
|
+
}, queryParams?: never, headers?: Record<string, string>) => Promise<{
|
|
299
299
|
success: true;
|
|
300
300
|
}>;
|
|
301
301
|
};
|
|
@@ -12,9 +12,7 @@ const useHasAccountJwt = () => {
|
|
|
12
12
|
let cancelled = false;
|
|
13
13
|
const refresh = async () => {
|
|
14
14
|
const token = (await credentialsStore.get())?.token;
|
|
15
|
-
const next = !!token &&
|
|
16
|
-
!isAccountlessJwt(token) &&
|
|
17
|
-
!isServiceOnlyJwt(token);
|
|
15
|
+
const next = !!token && !isAccountlessJwt(token) && !isServiceOnlyJwt(token);
|
|
18
16
|
if (!cancelled)
|
|
19
17
|
setHasAccount(next);
|
|
20
18
|
};
|