@openpeepshq/react 0.6.0 → 0.6.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/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/post/CompactReplyParent.js +8 -0
- package/dist/components/post/FeedPostContent.js +3 -0
- package/dist/components/post/NewResourceButton.d.ts +8 -0
- package/dist/components/post/NewResourceButton.js +36 -0
- package/dist/components/post/PostDetail.js +3 -0
- package/dist/components/post/index.d.ts +5 -0
- package/dist/components/post/index.js +3 -0
- package/dist/components/post/pieces/PostMenu.js +4 -0
- package/dist/components/post/post-form/PostTypeSwitcher.js +12 -2
- package/dist/components/post/post-form/ResourceForm.d.ts +7 -0
- package/dist/components/post/post-form/ResourceForm.js +68 -0
- package/dist/components/post/types/resource/FullResource.d.ts +5 -0
- package/dist/components/post/types/resource/FullResource.js +99 -0
- package/dist/components/resources/CategoryPathPicker.d.ts +7 -0
- package/dist/components/resources/CategoryPathPicker.js +26 -0
- package/dist/components/resources/ResourceCard.d.ts +8 -0
- package/dist/components/resources/ResourceCard.js +121 -0
- package/dist/components/resources/ResourceLibrary.d.ts +4 -0
- package/dist/components/resources/ResourceLibrary.js +106 -0
- package/dist/components/resources/index.d.ts +6 -0
- package/dist/components/resources/index.js +3 -0
- package/dist/contexts/openpeeps/hooks/admin.d.ts +1064 -38
- package/dist/contexts/openpeeps/hooks/jams.d.ts +1064 -38
- package/dist/contexts/openpeeps/hooks/posts.d.ts +4508 -39936
- package/dist/hooks/events/useEventComposer.d.ts +1184 -44
- package/dist/hooks/events/useEventsCalendar.d.ts +2113 -61
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/jams/useCreateNewJamForm.d.ts +39 -1
- package/dist/hooks/jams/useJamDetails.d.ts +1064 -38
- package/dist/hooks/jams/useJamRoom.d.ts +2113 -61
- package/dist/hooks/posts/useArticleComposer.d.ts +1184 -44
- package/dist/hooks/posts/useFeedPostPresentation.d.ts +2113 -61
- package/dist/hooks/posts/usePostDetailTitle.d.ts +1064 -38
- package/dist/hooks/posts/useResourceComposer.d.ts +12019 -0
- package/dist/hooks/posts/useResourceComposer.js +139 -0
- package/dist/hooks/resources/useResourceLibrary.d.ts +21880 -0
- package/dist/hooks/resources/useResourceLibrary.js +130 -0
- package/dist/hooks/settings/useNotificationPreferences.d.ts +1 -1
- package/dist/navigation/menuItems.js +5 -0
- package/dist/navigation/targets.d.ts +4 -0
- package/dist/pages/admin/analytics/Content.js +2 -1
- package/dist/pages/admin/analytics/Overview.js +15 -3
- package/dist/pages/groups/Show.js +7 -3
- package/dist/pages/index.d.ts +3 -0
- package/dist/pages/index.js +3 -0
- package/dist/pages/resources/Edit.d.ts +1 -0
- package/dist/pages/resources/Edit.js +26 -0
- package/dist/pages/resources/Index.d.ts +1 -0
- package/dist/pages/resources/Index.js +29 -0
- package/dist/pages/resources/New.d.ts +1 -0
- package/dist/pages/resources/New.js +15 -0
- package/dist/react-native.d.ts +1 -1
- package/dist/react-native.js +1 -1
- package/dist/stores/index.d.ts +1 -1
- package/dist/stores/index.js +1 -1
- package/dist/stores/newPosts.d.ts +79 -2
- package/dist/stores/newPosts.js +26 -2
- package/dist/stores/types.d.ts +2 -0
- package/package.json +6 -6
- package/src/components/index.ts +1 -0
- package/src/components/post/CompactReplyParent.tsx +8 -0
- package/src/components/post/FeedPostContent.tsx +3 -0
- package/src/components/post/NewResourceButton.tsx +75 -0
- package/src/components/post/PostDetail.tsx +3 -0
- package/src/components/post/index.ts +5 -0
- package/src/components/post/pieces/PostMenu.tsx +4 -0
- package/src/components/post/post-form/PostTypeSwitcher.tsx +19 -1
- package/src/components/post/post-form/ResourceForm.tsx +237 -0
- package/src/components/post/types/resource/FullResource.tsx +173 -0
- package/src/components/resources/CategoryPathPicker.tsx +95 -0
- package/src/components/resources/ResourceCard.tsx +335 -0
- package/src/components/resources/ResourceLibrary.tsx +374 -0
- package/src/components/resources/index.ts +6 -0
- package/src/contexts/openpeeps/hooks/posts.ts +11 -2
- package/src/hooks/index.ts +2 -0
- package/src/hooks/posts/useResourceComposer.ts +165 -0
- package/src/hooks/resources/useResourceLibrary.ts +156 -0
- package/src/navigation/menuItems.ts +6 -0
- package/src/navigation/targets.ts +1 -0
- package/src/pages/admin/analytics/Content.tsx +2 -1
- package/src/pages/admin/analytics/Overview.tsx +15 -3
- package/src/pages/groups/Show.tsx +30 -1
- package/src/pages/index.ts +3 -0
- package/src/pages/resources/Edit.tsx +73 -0
- package/src/pages/resources/Index.tsx +45 -0
- package/src/pages/resources/New.tsx +53 -0
- package/src/react-native.ts +1 -0
- package/src/stores/index.ts +1 -0
- package/src/stores/newPosts.ts +33 -2
- package/src/stores/types.ts +2 -0
package/dist/components/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from './registry/index.js';
|
|
|
6
6
|
export * from './form/index.js';
|
|
7
7
|
export * from './profile/index.js';
|
|
8
8
|
export * from './post/index.js';
|
|
9
|
+
export * from './resources/index.js';
|
|
9
10
|
export * from './markdown/index.js';
|
|
10
11
|
export * from './notifications/index.js';
|
|
11
12
|
export * from './groups/index.js';
|
|
@@ -39,6 +39,8 @@ const compactThumb = (post, t) => {
|
|
|
39
39
|
return null;
|
|
40
40
|
return _jsx(CompactThumb, { src: article.image, alt: article.title ?? alt });
|
|
41
41
|
}
|
|
42
|
+
case 'resource':
|
|
43
|
+
return attachmentThumb(attachmentsOf(post), alt);
|
|
42
44
|
default:
|
|
43
45
|
return null;
|
|
44
46
|
}
|
|
@@ -102,6 +104,12 @@ const CompactTypeBody = ({ post, t }) => {
|
|
|
102
104
|
return _jsx(CompactEventBody, { post: post });
|
|
103
105
|
case 'article':
|
|
104
106
|
return _jsx(CompactArticleBody, { post: post });
|
|
107
|
+
case 'resource': {
|
|
108
|
+
const title = post.data?.type === 'resource' ? post.data.title.trim() : '';
|
|
109
|
+
if (!title)
|
|
110
|
+
return null;
|
|
111
|
+
return _jsx("p", { className: "line-clamp-2 text-sm font-medium", children: title });
|
|
112
|
+
}
|
|
105
113
|
default:
|
|
106
114
|
return null;
|
|
107
115
|
}
|
|
@@ -5,6 +5,7 @@ import { FeedArticle } from './types/Article.js';
|
|
|
5
5
|
import { FeedEvent } from './types/Event.js';
|
|
6
6
|
import { FeedNote } from './types/Note.js';
|
|
7
7
|
import { FeedPoll } from './types/Poll.js';
|
|
8
|
+
import { ResourceCard } from '../resources/ResourceCard.js';
|
|
8
9
|
export function FeedPostContent({ post }) {
|
|
9
10
|
const t = useT();
|
|
10
11
|
const staticRender = useStaticRender();
|
|
@@ -23,6 +24,8 @@ export function FeedPostContent({ post }) {
|
|
|
23
24
|
return _jsx(FeedEvent, { post: post });
|
|
24
25
|
case 'article':
|
|
25
26
|
return _jsx(FeedArticle, { post: post });
|
|
27
|
+
case 'resource':
|
|
28
|
+
return _jsx(ResourceCard, { post: post });
|
|
26
29
|
default:
|
|
27
30
|
return null;
|
|
28
31
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type GroupWithMeta, type ProfileWithMeta, type VisibilityType } from '@openpeepshq/common';
|
|
2
|
+
export interface NewResourceButtonProps {
|
|
3
|
+
visibility: VisibilityType;
|
|
4
|
+
currentProfile?: ProfileWithMeta;
|
|
5
|
+
group?: GroupWithMeta;
|
|
6
|
+
showButton?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const NewResourceButton: ({ visibility, currentProfile, group, showButton, }: NewResourceButtonProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo } from 'react';
|
|
3
|
+
import { FilePlus } from 'lucide-react';
|
|
4
|
+
import { canCreatePost, } from '@openpeepshq/common';
|
|
5
|
+
import { Button } from '@openpeepshq/react-ui';
|
|
6
|
+
import { useT } from '../../i18n/index.js';
|
|
7
|
+
import { getNewPostStores, useSetPlusButtonActions } from '../../stores/index.js';
|
|
8
|
+
import { useAuthData } from '../layout/IdentityContext.js';
|
|
9
|
+
import { useNavigate } from '../../contexts/router/index.js';
|
|
10
|
+
export const NewResourceButton = ({ visibility, currentProfile, group, showButton = true, }) => {
|
|
11
|
+
const t = useT();
|
|
12
|
+
const authData = useAuthData();
|
|
13
|
+
const navigate = useNavigate();
|
|
14
|
+
const stores = getNewPostStores();
|
|
15
|
+
const profile = currentProfile ?? authData.profile;
|
|
16
|
+
const canPost = !!profile && canCreatePost(authData, 'resource', visibility, group);
|
|
17
|
+
const openNew = useCallback(() => {
|
|
18
|
+
stores.resource = {
|
|
19
|
+
...stores.resource,
|
|
20
|
+
visibility,
|
|
21
|
+
groupId: group?.id,
|
|
22
|
+
};
|
|
23
|
+
navigate({ type: 'resources', view: 'new' });
|
|
24
|
+
}, [group?.id, navigate, stores, visibility]);
|
|
25
|
+
const plusActions = useMemo(() => canPost
|
|
26
|
+
? {
|
|
27
|
+
title: t('resources.new', { defaultValue: 'New resource' }),
|
|
28
|
+
icon: FilePlus,
|
|
29
|
+
action: openNew,
|
|
30
|
+
}
|
|
31
|
+
: undefined, [canPost, openNew, t]);
|
|
32
|
+
useSetPlusButtonActions(plusActions);
|
|
33
|
+
if (!canPost || !showButton)
|
|
34
|
+
return null;
|
|
35
|
+
return (_jsx("div", { className: "mb-4 p-4 pb-0", children: _jsxs(Button, { title: t('resources.new', { defaultValue: 'New resource' }), variant: "default", action: openNew, "data-testid": "resources-new-resource-button", children: [_jsx(FilePlus, { className: "mr-1 size-4" }), t('resources.new', { defaultValue: 'New resource' })] }) }));
|
|
36
|
+
};
|
|
@@ -5,6 +5,7 @@ import { FullNote } from './types/note/FullNote.js';
|
|
|
5
5
|
import { FullArticle } from './types/article/FullArticle.js';
|
|
6
6
|
import { FullPoll } from './types/poll/FullPoll.js';
|
|
7
7
|
import { FullEvent } from './types/event/FullEvent.js';
|
|
8
|
+
import { FullResource } from './types/resource/FullResource.js';
|
|
8
9
|
import { LoadingSpinner } from '@openpeepshq/react-ui';
|
|
9
10
|
export function PostDetail({ postId, occurrence }) {
|
|
10
11
|
const t = useT();
|
|
@@ -20,6 +21,8 @@ export function PostDetail({ postId, occurrence }) {
|
|
|
20
21
|
switch (post.type) {
|
|
21
22
|
case 'article':
|
|
22
23
|
return _jsx(FullArticle, { post: post });
|
|
24
|
+
case 'resource':
|
|
25
|
+
return _jsx(FullResource, { post: post });
|
|
23
26
|
case 'event':
|
|
24
27
|
return _jsx(FullEvent, { post: post, occurrence: occurrence });
|
|
25
28
|
case 'question':
|
|
@@ -24,6 +24,8 @@ export { OpenpeepsMarkdownInput } from './post-form/OpenpeepsMarkdownInput';
|
|
|
24
24
|
export type { OpenpeepsMarkdownInputProps } from './post-form/OpenpeepsMarkdownInput';
|
|
25
25
|
export { ArticleForm } from './post-form/ArticleForm';
|
|
26
26
|
export type { ArticleFormProps } from './post-form/ArticleForm';
|
|
27
|
+
export { ResourceForm } from './post-form/ResourceForm';
|
|
28
|
+
export type { ResourceFormProps } from './post-form/ResourceForm';
|
|
27
29
|
export { EventForm } from './post-form/EventForm';
|
|
28
30
|
export type { EventFormProps } from './post-form/EventForm';
|
|
29
31
|
export { PreviewLink } from '../preview-link/PreviewLink';
|
|
@@ -31,6 +33,8 @@ export { NewNoteButton, useNewNotePlusButton } from './NewNoteButton';
|
|
|
31
33
|
export type { NewNoteButtonProps } from './NewNoteButton';
|
|
32
34
|
export { NewEventButton } from './NewEventButton';
|
|
33
35
|
export type { NewEventButtonProps } from './NewEventButton';
|
|
36
|
+
export { NewResourceButton } from './NewResourceButton';
|
|
37
|
+
export type { NewResourceButtonProps } from './NewResourceButton';
|
|
34
38
|
export { PinnedPost } from './PinnedPost';
|
|
35
39
|
export type { PinnedPostProps } from './PinnedPost';
|
|
36
40
|
export { FullPostLayout } from './FullPostLayout';
|
|
@@ -56,6 +60,7 @@ export { ParticipantsCard } from './pieces/ParticipantsCard';
|
|
|
56
60
|
export type { ParticipantsCardProps } from './pieces/ParticipantsCard';
|
|
57
61
|
export { FullNote } from './types/note/FullNote';
|
|
58
62
|
export { FullArticle } from './types/article/FullArticle';
|
|
63
|
+
export { FullResource } from './types/resource/FullResource';
|
|
59
64
|
export { FullPoll } from './types/poll/FullPoll';
|
|
60
65
|
export { FullEvent } from './types/event/FullEvent';
|
|
61
66
|
export { PollContent } from './pieces/PollContent';
|
|
@@ -15,10 +15,12 @@ export { ComposeAttachments } from './post-form/ComposeAttachments.js';
|
|
|
15
15
|
export { DescriptionEditModal } from './post-form/DescriptionEditModal.js';
|
|
16
16
|
export { OpenpeepsMarkdownInput } from './post-form/OpenpeepsMarkdownInput.js';
|
|
17
17
|
export { ArticleForm } from './post-form/ArticleForm.js';
|
|
18
|
+
export { ResourceForm } from './post-form/ResourceForm.js';
|
|
18
19
|
export { EventForm } from './post-form/EventForm.js';
|
|
19
20
|
export { PreviewLink } from '../preview-link/PreviewLink.js';
|
|
20
21
|
export { NewNoteButton, useNewNotePlusButton } from './NewNoteButton.js';
|
|
21
22
|
export { NewEventButton } from './NewEventButton.js';
|
|
23
|
+
export { NewResourceButton } from './NewResourceButton.js';
|
|
22
24
|
export { PinnedPost } from './PinnedPost.js';
|
|
23
25
|
export { FullPostLayout } from './FullPostLayout.js';
|
|
24
26
|
export { ReplyBox } from './ReplyBox.js';
|
|
@@ -33,6 +35,7 @@ export { ProfileEventRelationship } from './types/event/ProfileEventRelationship
|
|
|
33
35
|
export { ParticipantsCard } from './pieces/ParticipantsCard.js';
|
|
34
36
|
export { FullNote } from './types/note/FullNote.js';
|
|
35
37
|
export { FullArticle } from './types/article/FullArticle.js';
|
|
38
|
+
export { FullResource } from './types/resource/FullResource.js';
|
|
36
39
|
export { FullPoll } from './types/poll/FullPoll.js';
|
|
37
40
|
export { FullEvent } from './types/event/FullEvent.js';
|
|
38
41
|
export { PollContent } from './pieces/PollContent.js';
|
|
@@ -63,6 +63,10 @@ export function PostMenu({ post, deleteCallback }) {
|
|
|
63
63
|
window.location.assign(`/articles/${post.id}/edit`);
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
+
if (post.data?.type === 'resource') {
|
|
67
|
+
window.location.assign(`/resources/${post.id}/edit`);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
66
70
|
openEditPost(post);
|
|
67
71
|
};
|
|
68
72
|
return (_jsxs(_Fragment, { children: [_jsxs(PopupMenu, { className: "h-max rounded-lg p-2 hover:opacity-80", title: t('posts.menu.title', { defaultValue: 'Post menu' }), children: [postProfile.id !== me.id ? (isFollowing ? (_jsx(PopupMenuButton, { title: t('profile.actions.unfollow', {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { CalendarDays, ChartColumnBig, Notebook, ScrollText, } from 'lucide-react';
|
|
2
|
+
import { CalendarDays, ChartColumnBig, Library, Notebook, ScrollText, } from 'lucide-react';
|
|
3
3
|
import { Button } from '@openpeepshq/react-ui';
|
|
4
4
|
import { useT } from '../../../i18n/index.js';
|
|
5
5
|
import { useNavigate } from '../../../contexts/router/index.js';
|
|
@@ -25,6 +25,14 @@ export function PostTypeSwitcher({ type, onSelect, onClose, showEventType = true
|
|
|
25
25
|
groupId,
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
else if (path === '/resources/new') {
|
|
29
|
+
stores.resource = {
|
|
30
|
+
...stores.resource,
|
|
31
|
+
type: 'resource',
|
|
32
|
+
visibility: visibility ?? stores.resource.visibility,
|
|
33
|
+
groupId,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
28
36
|
else {
|
|
29
37
|
stores.event = {
|
|
30
38
|
...stores.event,
|
|
@@ -36,5 +44,7 @@ export function PostTypeSwitcher({ type, onSelect, onClose, showEventType = true
|
|
|
36
44
|
onClose();
|
|
37
45
|
navigate(path);
|
|
38
46
|
};
|
|
39
|
-
return (_jsxs("div", { className: "flex items-center gap-1", children: [type !== 'note' ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.note', { defaultValue: 'Write Note' }), action: () => onSelect('note'), children: _jsx(Notebook, { className: "size-5" }) })) : null, type !== 'question' ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.poll', { defaultValue: 'Add Poll' }), action: () => onSelect('question'), "data-testid": "posts-composer-poll-type", children: _jsx(ChartColumnBig, { className: "size-5" }) })) : null, showEventType && isOwner ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.event', { defaultValue: 'Create an Event' }), action: () => goto('/events/new'), children: _jsx(CalendarDays, { className: "size-5" }) })) : null, showArticleType ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.article', { defaultValue: 'Write Article' }), action: () => goto('/articles/new'), children: _jsx(ScrollText, { className: "size-5" }) })) : null
|
|
47
|
+
return (_jsxs("div", { className: "flex items-center gap-1", children: [type !== 'note' ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.note', { defaultValue: 'Write Note' }), action: () => onSelect('note'), children: _jsx(Notebook, { className: "size-5" }) })) : null, type !== 'question' ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.poll', { defaultValue: 'Add Poll' }), action: () => onSelect('question'), "data-testid": "posts-composer-poll-type", children: _jsx(ChartColumnBig, { className: "size-5" }) })) : null, showEventType && isOwner ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.event', { defaultValue: 'Create an Event' }), action: () => goto('/events/new'), children: _jsx(CalendarDays, { className: "size-5" }) })) : null, showArticleType ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.article', { defaultValue: 'Write Article' }), action: () => goto('/articles/new'), children: _jsx(ScrollText, { className: "size-5" }) })) : null, _jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.resource', {
|
|
48
|
+
defaultValue: 'Add a resource',
|
|
49
|
+
}), action: () => goto('/resources/new'), children: _jsx(Library, { className: "size-5" }) })] }));
|
|
40
50
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PostCreationData } from '@openpeepshq/common/types';
|
|
2
|
+
export interface ResourceFormProps {
|
|
3
|
+
postData: PostCreationData;
|
|
4
|
+
onChange: (data: PostCreationData) => void;
|
|
5
|
+
isEdit?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const ResourceForm: ({ postData, onChange, isEdit, }: ResourceFormProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from 'react';
|
|
3
|
+
import { RESOURCE_KINDS, normalizeResourceTags } from '@openpeepshq/common/lib';
|
|
4
|
+
import { Button, Input, Label } from '@openpeepshq/react-ui';
|
|
5
|
+
import { useT } from '../../../i18n/index.js';
|
|
6
|
+
import { useCurrentProfile } from '../../layout/IdentityContext.js';
|
|
7
|
+
import { applyAudienceSetting } from '../../../lib/audienceSetting.js';
|
|
8
|
+
import { CategoryPathPicker } from '../../resources/CategoryPathPicker.js';
|
|
9
|
+
import { useResourceLibrary } from '../../../hooks/index.js';
|
|
10
|
+
import { OpenpeepsMarkdownInput } from './OpenpeepsMarkdownInput.js';
|
|
11
|
+
import { PostAudienceSelector } from './PostAudienceSelector.js';
|
|
12
|
+
import { VisibilitySelector } from './VisibilitySelector.js';
|
|
13
|
+
import { useComposeAttachments } from './ComposeAttachments.js';
|
|
14
|
+
export const ResourceForm = ({ postData, onChange, isEdit = false, }) => {
|
|
15
|
+
const t = useT();
|
|
16
|
+
const me = useCurrentProfile();
|
|
17
|
+
const resource = postData.data;
|
|
18
|
+
const [audienceOpen, setAudienceOpen] = useState(false);
|
|
19
|
+
const [tagDraft, setTagDraft] = useState('');
|
|
20
|
+
const library = useResourceLibrary(postData.groupId ?? undefined);
|
|
21
|
+
const attachments = useComposeAttachments({
|
|
22
|
+
attachments: resource.attachments ?? [],
|
|
23
|
+
onChange: (next) => patchResource({ attachments: next }),
|
|
24
|
+
});
|
|
25
|
+
const patchResource = (patch) => {
|
|
26
|
+
onChange({
|
|
27
|
+
...postData,
|
|
28
|
+
data: { ...resource, ...patch },
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const setAudience = (settings) => onChange(applyAudienceSetting(postData, settings, me));
|
|
32
|
+
const addTag = () => {
|
|
33
|
+
const next = normalizeResourceTags([
|
|
34
|
+
...(resource.tags ?? []),
|
|
35
|
+
...tagDraft.split(/[,\s]+/),
|
|
36
|
+
]);
|
|
37
|
+
patchResource({ tags: next });
|
|
38
|
+
setTagDraft('');
|
|
39
|
+
};
|
|
40
|
+
const onTagKey = (event) => {
|
|
41
|
+
if (event.key === 'Enter' || event.key === ',') {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
addTag();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const kindActions = useMemo(() => ({
|
|
47
|
+
gallery: attachments.openImagePicker,
|
|
48
|
+
video: attachments.openImagePicker,
|
|
49
|
+
audio: attachments.openAudioPicker,
|
|
50
|
+
file: attachments.openDocumentPicker,
|
|
51
|
+
link: undefined,
|
|
52
|
+
}), [attachments]);
|
|
53
|
+
return (_jsxs("div", { children: [_jsxs("div", { className: "mt-4 flex flex-col gap-4 px-3", children: [_jsx("h2", { className: "text-lg", children: t('resources.form.title', { defaultValue: 'New resource' }) }), _jsx(Label, { title: t('resources.form.name', { defaultValue: 'Title' }), htmlFor: "resource-title", children: _jsx(Input, { id: "resource-title", "data-testid": "resources-title", value: resource.title, onChange: (event) => patchResource({ title: event.target.value }) }) }), _jsxs("div", { children: [_jsx("p", { className: "mb-2 text-sm font-medium", children: t('resources.form.kind', { defaultValue: 'Type' }) }), _jsx("div", { className: "flex flex-wrap gap-2", children: RESOURCE_KINDS.map((kind) => (_jsx(Button, { variant: resource.resourceKind === kind ? 'default' : 'outline', compact: true, "data-testid": `resources-kind-${kind}`, action: () => patchResource({ resourceKind: kind }), children: t(`resources.kinds.${kind}`, { defaultValue: kind }) }, kind))) })] }), resource.resourceKind === 'link' ? (_jsx(Label, { title: t('resources.form.url', { defaultValue: 'URL' }), htmlFor: "resource-url", children: _jsx(Input, { id: "resource-url", "data-testid": "resources-url", value: resource.url ?? '', onChange: (event) => patchResource({ url: event.target.value }) }) })) : (_jsxs("div", { className: "space-y-2", children: [_jsx(Button, { variant: "outline", action: kindActions[resource.resourceKind], children: t('resources.form.addMedia', {
|
|
54
|
+
defaultValue: 'Add files',
|
|
55
|
+
}) }), attachments.previews, attachments.inputs] })), _jsx(OpenpeepsMarkdownInput, { rows: 8, maxLength: 4000, value: resource.content ?? '', onChange: (content) => patchResource({ content }), placeholder: t('resources.form.descriptionPlaceholder', {
|
|
56
|
+
defaultValue: 'Describe this resource',
|
|
57
|
+
}) }), _jsx(Label, { title: t('resources.form.tags', { defaultValue: 'Tags' }), htmlFor: "resource-tags", children: _jsx(Input, { id: "resource-tags", value: tagDraft, onChange: (event) => setTagDraft(event.target.value), onKeyDown: onTagKey, onBlur: addTag, placeholder: t('resources.form.tagsPlaceholder', {
|
|
58
|
+
defaultValue: 'Add tags, then press Enter',
|
|
59
|
+
}) }) }), resource.tags?.length ? (_jsx("div", { className: "flex flex-wrap gap-1", children: normalizeResourceTags(resource.tags).map((tag) => (_jsxs("button", { type: "button", className: "bg-muted rounded-full px-2 py-0.5 text-xs", onClick: () => patchResource({
|
|
60
|
+
tags: (resource.tags ?? []).filter((value) => value.toLowerCase() !== tag),
|
|
61
|
+
}), children: ["#", tag] }, tag))) })) : null, _jsxs("div", { children: [_jsx("p", { className: "mb-2 text-sm font-medium", children: t('resources.form.hierarchy', {
|
|
62
|
+
defaultValue: 'Place in the library',
|
|
63
|
+
}) }), _jsx(CategoryPathPicker, { path: resource.categoryPath ?? [], tree: library.tree, onChange: (categoryPath) => patchResource({ categoryPath }) })] }), _jsx(Label, { title: t('resources.form.visibility', {
|
|
64
|
+
defaultValue: 'Who can see this (Required)',
|
|
65
|
+
}), description: t('resources.form.visibilityNotChangeable', {
|
|
66
|
+
defaultValue: "Once you post your resource, you can't change the visibility",
|
|
67
|
+
}), children: _jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }) })] }), !isEdit ? (_jsx(PostAudienceSelector, { open: audienceOpen, onClose: () => setAudienceOpen(false), type: "resource", visibility: postData.visibility, groupId: postData.groupId ?? undefined, audience: postData.audience ?? [], showDirect: true, onConfirm: setAudience })) : null] }));
|
|
68
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Download, ExternalLink, Image as ImageIcon, Play } from 'lucide-react';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { attachmentMediaKind } from '@openpeepshq/common/lib';
|
|
5
|
+
import { useT } from '../../../../i18n/index.js';
|
|
6
|
+
import { FullPostLayout } from '../../FullPostLayout.js';
|
|
7
|
+
import { PostInfoHeader } from '../../pieces/PostInfoHeader.js';
|
|
8
|
+
import { PostMarkdown } from '../../Markdown.js';
|
|
9
|
+
import { ResourceCard } from '../../../resources/ResourceCard.js';
|
|
10
|
+
import { VideoPlayer } from '../../pieces/VideoPlayer.js';
|
|
11
|
+
import { AudioAttachment } from '../../pieces/AudioAttachment.js';
|
|
12
|
+
import { GalleryModal } from '../../pieces/GalleryModal.js';
|
|
13
|
+
export const FullResource = ({ post }) => {
|
|
14
|
+
const t = useT();
|
|
15
|
+
const resource = post.data?.type === 'resource' ? post.data : null;
|
|
16
|
+
const [galleryIndex, setGalleryIndex] = useState(null);
|
|
17
|
+
const [playerVisible, setPlayerVisible] = useState(false);
|
|
18
|
+
if (!resource)
|
|
19
|
+
return null;
|
|
20
|
+
const handlePreviewClick = () => {
|
|
21
|
+
switch (resource.resourceKind) {
|
|
22
|
+
case 'video':
|
|
23
|
+
case 'audio':
|
|
24
|
+
setPlayerVisible(true);
|
|
25
|
+
break;
|
|
26
|
+
case 'gallery':
|
|
27
|
+
setGalleryIndex(0);
|
|
28
|
+
break;
|
|
29
|
+
case 'file': {
|
|
30
|
+
const att = resource.attachments?.find((a) => attachmentMediaKind(a) === 'file');
|
|
31
|
+
if (att?.url)
|
|
32
|
+
window.open(att.url, '_blank');
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case 'link':
|
|
36
|
+
if (resource.url)
|
|
37
|
+
window.open(resource.url, '_blank');
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const previewIcon = () => {
|
|
44
|
+
switch (resource.resourceKind) {
|
|
45
|
+
case 'video':
|
|
46
|
+
case 'audio':
|
|
47
|
+
return _jsx(Play, { className: "size-12 text-white" });
|
|
48
|
+
case 'gallery':
|
|
49
|
+
return _jsx(ImageIcon, { className: "size-12 text-white" });
|
|
50
|
+
case 'file':
|
|
51
|
+
return _jsx(Download, { className: "size-12 text-white" });
|
|
52
|
+
case 'link':
|
|
53
|
+
return _jsx(ExternalLink, { className: "size-12 text-white" });
|
|
54
|
+
default:
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const previewLabel = () => {
|
|
59
|
+
switch (resource.resourceKind) {
|
|
60
|
+
case 'video':
|
|
61
|
+
return t('resources.actions.watch', { defaultValue: 'Play video' });
|
|
62
|
+
case 'audio':
|
|
63
|
+
return t('resources.actions.listen', {
|
|
64
|
+
defaultValue: 'Play audio',
|
|
65
|
+
});
|
|
66
|
+
case 'gallery':
|
|
67
|
+
return t('resources.actions.view', {
|
|
68
|
+
defaultValue: 'View images',
|
|
69
|
+
});
|
|
70
|
+
case 'file':
|
|
71
|
+
return t('resources.actions.download', {
|
|
72
|
+
defaultValue: 'Download',
|
|
73
|
+
});
|
|
74
|
+
case 'link':
|
|
75
|
+
return t('resources.actions.openLink', {
|
|
76
|
+
defaultValue: 'Open link',
|
|
77
|
+
});
|
|
78
|
+
default:
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const renderMedia = () => {
|
|
83
|
+
if (resource.resourceKind === 'video' && playerVisible) {
|
|
84
|
+
const videoAtt = resource.attachments?.find((a) => attachmentMediaKind(a) === 'video');
|
|
85
|
+
if (videoAtt) {
|
|
86
|
+
return (_jsx(ResourceCard, { post: post, preview: _jsx(VideoPlayer, { attachment: videoAtt, className: "max-h-[600px] w-full" }) }));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (resource.resourceKind === 'audio' && playerVisible) {
|
|
90
|
+
const audioAtt = resource.attachments?.find((a) => attachmentMediaKind(a) === 'audio');
|
|
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 }) }));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
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() }) })] }));
|
|
97
|
+
};
|
|
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
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CategoryNode } from '@openpeepshq/common/lib';
|
|
2
|
+
export interface CategoryPathPickerProps {
|
|
3
|
+
path: string[];
|
|
4
|
+
tree: CategoryNode[];
|
|
5
|
+
onChange: (path: string[]) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const CategoryPathPicker: ({ path, tree, onChange, }: CategoryPathPickerProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Button, Input } from '@openpeepshq/react-ui';
|
|
4
|
+
import { useT } from '../../i18n/index.js';
|
|
5
|
+
const NodeList = ({ nodes, selected, onSelect, }) => (_jsx("ul", { className: "border-border ml-3 border-l pl-3", children: nodes.map((node) => {
|
|
6
|
+
const active = selected.length === node.path.length &&
|
|
7
|
+
node.path.every((segment, index) => selected[index] === segment);
|
|
8
|
+
return (_jsxs("li", { className: "py-0.5", children: [_jsx("button", { type: "button", className: `text-sm ${active ? 'text-foreground font-semibold' : 'text-muted-foreground hover:text-foreground'}`, onClick: () => onSelect(node.path), children: node.name }), node.children.length ? (_jsx(NodeList, { nodes: node.children, selected: selected, onSelect: onSelect })) : null] }, node.path.join('/')));
|
|
9
|
+
}) }));
|
|
10
|
+
export const CategoryPathPicker = ({ path, tree, onChange, }) => {
|
|
11
|
+
const t = useT();
|
|
12
|
+
const [level, setLevel] = useState('');
|
|
13
|
+
return (_jsxs("div", { className: "space-y-2", children: [_jsx("p", { className: "text-muted-foreground text-sm", children: path.length
|
|
14
|
+
? path.join(' / ')
|
|
15
|
+
: t('resources.form.uncategorized', {
|
|
16
|
+
defaultValue: 'Uncategorized',
|
|
17
|
+
}) }), tree.length ? (_jsx(NodeList, { nodes: tree, selected: path, onSelect: onChange })) : null, _jsxs("div", { className: "flex gap-2", children: [_jsx(Input, { value: level, onChange: (event) => setLevel(event.target.value), placeholder: t('resources.form.addLevel', {
|
|
18
|
+
defaultValue: 'Add a folder',
|
|
19
|
+
}) }), _jsx(Button, { variant: "outline", action: () => {
|
|
20
|
+
const name = level.trim();
|
|
21
|
+
if (!name)
|
|
22
|
+
return;
|
|
23
|
+
onChange([...path, name]);
|
|
24
|
+
setLevel('');
|
|
25
|
+
}, children: t('resources.form.addLevelAction', { defaultValue: 'Add' }) }), path.length ? (_jsx(Button, { variant: "ghost", action: () => onChange([]), children: t('resources.form.clearPath', { defaultValue: 'Clear' }) })) : null] })] }));
|
|
26
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { PublicPost } from '@openpeepshq/common/types';
|
|
3
|
+
export interface ResourceCardProps {
|
|
4
|
+
post: PublicPost;
|
|
5
|
+
layout?: 'card' | 'list';
|
|
6
|
+
preview?: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export declare const ResourceCard: ({ post, layout, preview, }: ResourceCardProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from 'react';
|
|
3
|
+
import { BookmarkCheck, BookmarkPlus, Link as LinkIcon, ImageOff, } from 'lucide-react';
|
|
4
|
+
import { attachmentMediaKind, normalizeResourceTags, truncateMarkdown, formatSize, } from '@openpeepshq/common/lib';
|
|
5
|
+
import { useT } from '../../i18n/index.js';
|
|
6
|
+
import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
|
|
7
|
+
import { useCurrentProfile } from '../layout/IdentityContext.js';
|
|
8
|
+
import { VideoPlayOverlay } from '../post/VideoPlayOverlay.js';
|
|
9
|
+
const visualAttachments = (attachments) => attachments.filter((att) => attachmentMediaKind(att) !== 'audio');
|
|
10
|
+
const previewSrc = (att) => att.previewUrl ?? att.url;
|
|
11
|
+
/** Thumbnail size shared between list and card previews. */
|
|
12
|
+
const THUMB_CLASS = 'h-12 w-12 object-cover';
|
|
13
|
+
const CARD_IMG_CLASS = 'h-48 w-full object-cover';
|
|
14
|
+
const primaryActionLabel = (kind, t) => {
|
|
15
|
+
switch (kind) {
|
|
16
|
+
case 'video':
|
|
17
|
+
return t('resources.actions.watch', { defaultValue: 'Watch' });
|
|
18
|
+
case 'file':
|
|
19
|
+
return t('resources.actions.download', { defaultValue: 'Download' });
|
|
20
|
+
case 'audio':
|
|
21
|
+
return t('resources.actions.listen', { defaultValue: 'Listen' });
|
|
22
|
+
case 'gallery':
|
|
23
|
+
return t('resources.actions.view', { defaultValue: 'View images' });
|
|
24
|
+
default:
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const MediaPreview = ({ src, alt, className, isVideo, isLast, extra, }) => {
|
|
29
|
+
const [errored, setErrored] = useState(false);
|
|
30
|
+
if (!src) {
|
|
31
|
+
return (_jsx("div", { className: "bg-surface flex h-full w-full items-center justify-center overflow-hidden", children: _jsx(ImageOff, { className: "text-muted-foreground/50 size-6" }) }));
|
|
32
|
+
}
|
|
33
|
+
if (errored) {
|
|
34
|
+
return (_jsx("div", { className: "bg-surface flex h-full w-full items-center justify-center overflow-hidden", children: _jsx(ImageOff, { className: "text-muted-foreground/50 size-6" }) }));
|
|
35
|
+
}
|
|
36
|
+
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
|
+
};
|
|
38
|
+
export const ResourceCard = ({ post, layout = 'card', preview, }) => {
|
|
39
|
+
const t = useT();
|
|
40
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
41
|
+
const me = useCurrentProfile();
|
|
42
|
+
if (post.data?.type !== 'resource')
|
|
43
|
+
return null;
|
|
44
|
+
const resource = post.data;
|
|
45
|
+
const attachments = resource.attachments ?? [];
|
|
46
|
+
const visuals = visualAttachments(attachments);
|
|
47
|
+
const excerpt = truncateMarkdown(resource.content, 2, 240);
|
|
48
|
+
const tags = normalizeResourceTags(resource.tags);
|
|
49
|
+
const isGallery = resource.resourceKind === 'gallery' && visuals.length > 1;
|
|
50
|
+
const tiles = isGallery ? visuals.slice(0, 4) : visuals.slice(0, 1);
|
|
51
|
+
const extra = isGallery ? Math.max(0, visuals.length - 4) : 0;
|
|
52
|
+
const actionLabel = primaryActionLabel(resource.resourceKind, t);
|
|
53
|
+
const thumbnail = visuals[0];
|
|
54
|
+
const thumbSrc = thumbnail ? previewSrc(thumbnail) : null;
|
|
55
|
+
const metaText = useMemo(() => {
|
|
56
|
+
if (resource.resourceKind === 'gallery' && visuals.length > 1) {
|
|
57
|
+
return t('resources.meta.imagesCount', {
|
|
58
|
+
defaultValue: '{{count}} images',
|
|
59
|
+
count: visuals.length,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const fileAtt = attachments.find((att) => attachmentMediaKind(att) === 'file' ||
|
|
63
|
+
attachmentMediaKind(att) === 'video' ||
|
|
64
|
+
attachmentMediaKind(att) === 'audio');
|
|
65
|
+
const size = fileAtt?.meta?.size;
|
|
66
|
+
if (size)
|
|
67
|
+
return formatSize(size);
|
|
68
|
+
return null;
|
|
69
|
+
}, [resource.resourceKind, visuals, attachments, t]);
|
|
70
|
+
const bookmarkedIdsQuery = openpeepsApi.useCurrentProfileBookmarkedIds();
|
|
71
|
+
const isBookmarked = bookmarkedIdsQuery.data?.includes(post.id) ?? false;
|
|
72
|
+
const bookmarkPost = openpeepsApi.bookmarkPostAction({ id: post.id });
|
|
73
|
+
const unbookmarkPost = openpeepsApi.unbookmarkPostAction({ id: post.id });
|
|
74
|
+
const toggleBookmark = () => {
|
|
75
|
+
if (!me)
|
|
76
|
+
return;
|
|
77
|
+
if (isBookmarked) {
|
|
78
|
+
unbookmarkPost(undefined);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
bookmarkPost(undefined);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const downloadUrl = resource.resourceKind === 'file'
|
|
85
|
+
? attachments.find((att) => attachmentMediaKind(att) === 'file')?.url
|
|
86
|
+
: null;
|
|
87
|
+
const renderBookmarkButton = (className) => (_jsx("button", { type: "button", onClick: (e) => {
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
e.stopPropagation();
|
|
90
|
+
toggleBookmark();
|
|
91
|
+
}, disabled: !me, className: className, title: isBookmarked
|
|
92
|
+
? t('resources.actions.saved', { defaultValue: 'Saved' })
|
|
93
|
+
: t('resources.actions.save', { defaultValue: 'Save' }), children: isBookmarked ? (_jsx(BookmarkCheck, { className: "text-primary size-4" })) : (_jsx(BookmarkPlus, { className: "size-4" })) }));
|
|
94
|
+
const renderThumbnail = () => {
|
|
95
|
+
if (thumbSrc) {
|
|
96
|
+
return (_jsx("img", { src: thumbSrc, alt: thumbnail?.description ?? resource.title, className: THUMB_CLASS, onError: (e) => {
|
|
97
|
+
e.target.style.display = 'none';
|
|
98
|
+
} }));
|
|
99
|
+
}
|
|
100
|
+
if (resource.resourceKind === 'link' && resource.url) {
|
|
101
|
+
return (_jsx("div", { className: "bg-muted flex h-12 w-12 items-center justify-center rounded-md", children: _jsx(LinkIcon, { className: "text-muted-foreground size-5" }) }));
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
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' &&
|
|
107
|
+
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
|
+
}
|
|
109
|
+
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
|
|
110
|
+
? 'grid h-48 grid-cols-2 grid-rows-2 gap-1'
|
|
111
|
+
: 'h-48 w-full'}`, children: tiles.map((att, index) => {
|
|
112
|
+
const src = previewSrc(att);
|
|
113
|
+
const last = index === tiles.length - 1 && extra > 0;
|
|
114
|
+
const kind = attachmentMediaKind(att);
|
|
115
|
+
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
|
+
? 'h-full w-full object-cover'
|
|
117
|
+
: 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}`, {
|
|
119
|
+
defaultValue: resource.resourceKind,
|
|
120
|
+
}) })] }));
|
|
121
|
+
};
|