@openpeepshq/react 0.5.1 → 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/markdown/CompiledMarkdown.d.ts +3 -1
- package/dist/components/markdown/CompiledMarkdown.js +17 -1
- package/dist/components/markdown/OpenpeepsMarkdown.d.ts +3 -7
- package/dist/components/markdown/OpenpeepsMarkdown.js +11 -7
- package/dist/components/markdown/classes.d.ts +3 -3
- package/dist/components/markdown/classes.js +3 -3
- package/dist/components/markdown/compileMarkdown.d.ts +3 -1
- package/dist/components/markdown/compileMarkdown.js +29 -4
- package/dist/components/markdown/index.d.ts +3 -1
- package/dist/components/markdown/linkTargets.d.ts +2 -3
- package/dist/components/markdown/linkTargets.js +2 -27
- 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/lib/analyticsClicks.js +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 +3 -1
- package/dist/react-native.js +2 -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 +7 -6
- package/src/components/index.ts +1 -0
- package/src/components/markdown/CompiledMarkdown.tsx +36 -7
- package/src/components/markdown/OpenpeepsMarkdown.tsx +16 -16
- package/src/components/markdown/classes.ts +3 -3
- package/src/components/markdown/compileMarkdown.ts +45 -5
- package/src/components/markdown/index.ts +6 -1
- package/src/components/markdown/linkTargets.ts +2 -31
- 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/lib/analyticsClicks.ts +1 -1
- 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 +12 -0
- package/src/stores/index.ts +1 -0
- package/src/stores/newPosts.ts +33 -2
- package/src/stores/types.ts +2 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { useMemo, useState, type KeyboardEvent } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
AudienceSetting,
|
|
4
|
+
PostCreationData,
|
|
5
|
+
ResourceKind,
|
|
6
|
+
ResourcePost,
|
|
7
|
+
} from '@openpeepshq/common/types';
|
|
8
|
+
import { RESOURCE_KINDS, normalizeResourceTags } from '@openpeepshq/common/lib';
|
|
9
|
+
import { Button, Input, Label } from '@openpeepshq/react-ui';
|
|
10
|
+
import { useT } from '../../../i18n';
|
|
11
|
+
import { useCurrentProfile } from '../../layout/IdentityContext';
|
|
12
|
+
import { applyAudienceSetting } from '../../../lib/audienceSetting';
|
|
13
|
+
import { CategoryPathPicker } from '../../resources/CategoryPathPicker';
|
|
14
|
+
import { useResourceLibrary } from '../../../hooks';
|
|
15
|
+
import { OpenpeepsMarkdownInput } from './OpenpeepsMarkdownInput';
|
|
16
|
+
import { PostAudienceSelector } from './PostAudienceSelector';
|
|
17
|
+
import { VisibilitySelector } from './VisibilitySelector';
|
|
18
|
+
import { useComposeAttachments } from './ComposeAttachments';
|
|
19
|
+
|
|
20
|
+
export interface ResourceFormProps {
|
|
21
|
+
postData: PostCreationData;
|
|
22
|
+
onChange: (data: PostCreationData) => void;
|
|
23
|
+
isEdit?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const ResourceForm = ({
|
|
27
|
+
postData,
|
|
28
|
+
onChange,
|
|
29
|
+
isEdit = false,
|
|
30
|
+
}: ResourceFormProps) => {
|
|
31
|
+
const t = useT();
|
|
32
|
+
const me = useCurrentProfile();
|
|
33
|
+
const resource = postData.data as ResourcePost;
|
|
34
|
+
const [audienceOpen, setAudienceOpen] = useState(false);
|
|
35
|
+
const [tagDraft, setTagDraft] = useState('');
|
|
36
|
+
const library = useResourceLibrary(postData.groupId ?? undefined);
|
|
37
|
+
const attachments = useComposeAttachments({
|
|
38
|
+
attachments: resource.attachments ?? [],
|
|
39
|
+
onChange: (next) => patchResource({ attachments: next }),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const patchResource = (patch: Partial<ResourcePost>) => {
|
|
43
|
+
onChange({
|
|
44
|
+
...postData,
|
|
45
|
+
data: { ...resource, ...patch },
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const setAudience = (settings: AudienceSetting) =>
|
|
50
|
+
onChange(applyAudienceSetting(postData, settings, me));
|
|
51
|
+
|
|
52
|
+
const addTag = () => {
|
|
53
|
+
const next = normalizeResourceTags([
|
|
54
|
+
...(resource.tags ?? []),
|
|
55
|
+
...tagDraft.split(/[,\s]+/),
|
|
56
|
+
]);
|
|
57
|
+
patchResource({ tags: next });
|
|
58
|
+
setTagDraft('');
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const onTagKey = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
62
|
+
if (event.key === 'Enter' || event.key === ',') {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
addTag();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const kindActions = useMemo(
|
|
69
|
+
() => ({
|
|
70
|
+
gallery: attachments.openImagePicker,
|
|
71
|
+
video: attachments.openImagePicker,
|
|
72
|
+
audio: attachments.openAudioPicker,
|
|
73
|
+
file: attachments.openDocumentPicker,
|
|
74
|
+
link: undefined,
|
|
75
|
+
}),
|
|
76
|
+
[attachments],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div>
|
|
81
|
+
<div className="mt-4 flex flex-col gap-4 px-3">
|
|
82
|
+
<h2 className="text-lg">
|
|
83
|
+
{t('resources.form.title', { defaultValue: 'New resource' })}
|
|
84
|
+
</h2>
|
|
85
|
+
|
|
86
|
+
<Label
|
|
87
|
+
title={t('resources.form.name', { defaultValue: 'Title' })}
|
|
88
|
+
htmlFor="resource-title"
|
|
89
|
+
>
|
|
90
|
+
<Input
|
|
91
|
+
id="resource-title"
|
|
92
|
+
data-testid="resources-title"
|
|
93
|
+
value={resource.title}
|
|
94
|
+
onChange={(event) => patchResource({ title: event.target.value })}
|
|
95
|
+
/>
|
|
96
|
+
</Label>
|
|
97
|
+
|
|
98
|
+
<div>
|
|
99
|
+
<p className="mb-2 text-sm font-medium">
|
|
100
|
+
{t('resources.form.kind', { defaultValue: 'Type' })}
|
|
101
|
+
</p>
|
|
102
|
+
<div className="flex flex-wrap gap-2">
|
|
103
|
+
{RESOURCE_KINDS.map((kind) => (
|
|
104
|
+
<Button
|
|
105
|
+
key={kind}
|
|
106
|
+
variant={resource.resourceKind === kind ? 'default' : 'outline'}
|
|
107
|
+
compact
|
|
108
|
+
data-testid={`resources-kind-${kind}`}
|
|
109
|
+
action={() =>
|
|
110
|
+
patchResource({ resourceKind: kind as ResourceKind })
|
|
111
|
+
}
|
|
112
|
+
>
|
|
113
|
+
{t(`resources.kinds.${kind}`, { defaultValue: kind })}
|
|
114
|
+
</Button>
|
|
115
|
+
))}
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
{resource.resourceKind === 'link' ? (
|
|
120
|
+
<Label
|
|
121
|
+
title={t('resources.form.url', { defaultValue: 'URL' })}
|
|
122
|
+
htmlFor="resource-url"
|
|
123
|
+
>
|
|
124
|
+
<Input
|
|
125
|
+
id="resource-url"
|
|
126
|
+
data-testid="resources-url"
|
|
127
|
+
value={resource.url ?? ''}
|
|
128
|
+
onChange={(event) => patchResource({ url: event.target.value })}
|
|
129
|
+
/>
|
|
130
|
+
</Label>
|
|
131
|
+
) : (
|
|
132
|
+
<div className="space-y-2">
|
|
133
|
+
<Button
|
|
134
|
+
variant="outline"
|
|
135
|
+
action={kindActions[resource.resourceKind]}
|
|
136
|
+
>
|
|
137
|
+
{t('resources.form.addMedia', {
|
|
138
|
+
defaultValue: 'Add files',
|
|
139
|
+
})}
|
|
140
|
+
</Button>
|
|
141
|
+
{attachments.previews}
|
|
142
|
+
{attachments.inputs}
|
|
143
|
+
</div>
|
|
144
|
+
)}
|
|
145
|
+
|
|
146
|
+
<OpenpeepsMarkdownInput
|
|
147
|
+
rows={8}
|
|
148
|
+
maxLength={4000}
|
|
149
|
+
value={resource.content ?? ''}
|
|
150
|
+
onChange={(content) => patchResource({ content })}
|
|
151
|
+
placeholder={t('resources.form.descriptionPlaceholder', {
|
|
152
|
+
defaultValue: 'Describe this resource',
|
|
153
|
+
})}
|
|
154
|
+
/>
|
|
155
|
+
|
|
156
|
+
<Label
|
|
157
|
+
title={t('resources.form.tags', { defaultValue: 'Tags' })}
|
|
158
|
+
htmlFor="resource-tags"
|
|
159
|
+
>
|
|
160
|
+
<Input
|
|
161
|
+
id="resource-tags"
|
|
162
|
+
value={tagDraft}
|
|
163
|
+
onChange={(event) => setTagDraft(event.target.value)}
|
|
164
|
+
onKeyDown={onTagKey}
|
|
165
|
+
onBlur={addTag}
|
|
166
|
+
placeholder={t('resources.form.tagsPlaceholder', {
|
|
167
|
+
defaultValue: 'Add tags, then press Enter',
|
|
168
|
+
})}
|
|
169
|
+
/>
|
|
170
|
+
</Label>
|
|
171
|
+
{resource.tags?.length ? (
|
|
172
|
+
<div className="flex flex-wrap gap-1">
|
|
173
|
+
{normalizeResourceTags(resource.tags).map((tag) => (
|
|
174
|
+
<button
|
|
175
|
+
key={tag}
|
|
176
|
+
type="button"
|
|
177
|
+
className="bg-muted rounded-full px-2 py-0.5 text-xs"
|
|
178
|
+
onClick={() =>
|
|
179
|
+
patchResource({
|
|
180
|
+
tags: (resource.tags ?? []).filter(
|
|
181
|
+
(value) => value.toLowerCase() !== tag,
|
|
182
|
+
),
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
>
|
|
186
|
+
#{tag}
|
|
187
|
+
</button>
|
|
188
|
+
))}
|
|
189
|
+
</div>
|
|
190
|
+
) : null}
|
|
191
|
+
|
|
192
|
+
<div>
|
|
193
|
+
<p className="mb-2 text-sm font-medium">
|
|
194
|
+
{t('resources.form.hierarchy', {
|
|
195
|
+
defaultValue: 'Place in the library',
|
|
196
|
+
})}
|
|
197
|
+
</p>
|
|
198
|
+
<CategoryPathPicker
|
|
199
|
+
path={resource.categoryPath ?? []}
|
|
200
|
+
tree={library.tree}
|
|
201
|
+
onChange={(categoryPath) => patchResource({ categoryPath })}
|
|
202
|
+
/>
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
<Label
|
|
206
|
+
title={t('resources.form.visibility', {
|
|
207
|
+
defaultValue: 'Who can see this (Required)',
|
|
208
|
+
})}
|
|
209
|
+
description={t('resources.form.visibilityNotChangeable', {
|
|
210
|
+
defaultValue:
|
|
211
|
+
"Once you post your resource, you can't change the visibility",
|
|
212
|
+
})}
|
|
213
|
+
>
|
|
214
|
+
<VisibilitySelector
|
|
215
|
+
postData={postData}
|
|
216
|
+
onClick={() => setAudienceOpen(true)}
|
|
217
|
+
disabled={isEdit}
|
|
218
|
+
showDirect
|
|
219
|
+
/>
|
|
220
|
+
</Label>
|
|
221
|
+
</div>
|
|
222
|
+
|
|
223
|
+
{!isEdit ? (
|
|
224
|
+
<PostAudienceSelector
|
|
225
|
+
open={audienceOpen}
|
|
226
|
+
onClose={() => setAudienceOpen(false)}
|
|
227
|
+
type="resource"
|
|
228
|
+
visibility={postData.visibility}
|
|
229
|
+
groupId={postData.groupId ?? undefined}
|
|
230
|
+
audience={postData.audience ?? []}
|
|
231
|
+
showDirect
|
|
232
|
+
onConfirm={setAudience}
|
|
233
|
+
/>
|
|
234
|
+
) : null}
|
|
235
|
+
</div>
|
|
236
|
+
);
|
|
237
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Download, ExternalLink, Image as ImageIcon, Play } from 'lucide-react';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import type { PublicPost } from '@openpeepshq/common/types';
|
|
4
|
+
import { attachmentMediaKind } from '@openpeepshq/common/lib';
|
|
5
|
+
import { useT } from '../../../../i18n';
|
|
6
|
+
import { FullPostLayout } from '../../FullPostLayout';
|
|
7
|
+
import { PostInfoHeader } from '../../pieces/PostInfoHeader';
|
|
8
|
+
import { PostMarkdown } from '../../Markdown';
|
|
9
|
+
import { ResourceCard } from '../../../resources/ResourceCard';
|
|
10
|
+
import { VideoPlayer } from '../../pieces/VideoPlayer';
|
|
11
|
+
import { AudioAttachment } from '../../pieces/AudioAttachment';
|
|
12
|
+
import { GalleryModal } from '../../pieces/GalleryModal';
|
|
13
|
+
|
|
14
|
+
export interface FullResourceProps {
|
|
15
|
+
post: PublicPost;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const FullResource = ({ post }: FullResourceProps) => {
|
|
19
|
+
const t = useT();
|
|
20
|
+
const resource = post.data?.type === 'resource' ? post.data : null;
|
|
21
|
+
const [galleryIndex, setGalleryIndex] = useState<number | null>(null);
|
|
22
|
+
const [playerVisible, setPlayerVisible] = useState(false);
|
|
23
|
+
|
|
24
|
+
if (!resource) return null;
|
|
25
|
+
|
|
26
|
+
const handlePreviewClick = () => {
|
|
27
|
+
switch (resource.resourceKind) {
|
|
28
|
+
case 'video':
|
|
29
|
+
case 'audio':
|
|
30
|
+
setPlayerVisible(true);
|
|
31
|
+
break;
|
|
32
|
+
case 'gallery':
|
|
33
|
+
setGalleryIndex(0);
|
|
34
|
+
break;
|
|
35
|
+
case 'file': {
|
|
36
|
+
const att = resource.attachments?.find(
|
|
37
|
+
(a) => attachmentMediaKind(a) === 'file',
|
|
38
|
+
);
|
|
39
|
+
if (att?.url) window.open(att.url, '_blank');
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case 'link':
|
|
43
|
+
if (resource.url) window.open(resource.url, '_blank');
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const previewIcon = () => {
|
|
51
|
+
switch (resource.resourceKind) {
|
|
52
|
+
case 'video':
|
|
53
|
+
case 'audio':
|
|
54
|
+
return <Play className="size-12 text-white" />;
|
|
55
|
+
case 'gallery':
|
|
56
|
+
return <ImageIcon className="size-12 text-white" />;
|
|
57
|
+
case 'file':
|
|
58
|
+
return <Download className="size-12 text-white" />;
|
|
59
|
+
case 'link':
|
|
60
|
+
return <ExternalLink className="size-12 text-white" />;
|
|
61
|
+
default:
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const previewLabel = () => {
|
|
67
|
+
switch (resource.resourceKind) {
|
|
68
|
+
case 'video':
|
|
69
|
+
return t('resources.actions.watch', { defaultValue: 'Play video' });
|
|
70
|
+
case 'audio':
|
|
71
|
+
return t('resources.actions.listen', {
|
|
72
|
+
defaultValue: 'Play audio',
|
|
73
|
+
});
|
|
74
|
+
case 'gallery':
|
|
75
|
+
return t('resources.actions.view', {
|
|
76
|
+
defaultValue: 'View images',
|
|
77
|
+
});
|
|
78
|
+
case 'file':
|
|
79
|
+
return t('resources.actions.download', {
|
|
80
|
+
defaultValue: 'Download',
|
|
81
|
+
});
|
|
82
|
+
case 'link':
|
|
83
|
+
return t('resources.actions.openLink', {
|
|
84
|
+
defaultValue: 'Open link',
|
|
85
|
+
});
|
|
86
|
+
default:
|
|
87
|
+
return '';
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const renderMedia = () => {
|
|
92
|
+
if (resource.resourceKind === 'video' && playerVisible) {
|
|
93
|
+
const videoAtt = resource.attachments?.find(
|
|
94
|
+
(a) => attachmentMediaKind(a) === 'video',
|
|
95
|
+
);
|
|
96
|
+
if (videoAtt) {
|
|
97
|
+
return (
|
|
98
|
+
<ResourceCard
|
|
99
|
+
post={post}
|
|
100
|
+
preview={
|
|
101
|
+
<VideoPlayer
|
|
102
|
+
attachment={videoAtt}
|
|
103
|
+
className="max-h-[600px] w-full"
|
|
104
|
+
/>
|
|
105
|
+
}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (resource.resourceKind === 'audio' && playerVisible) {
|
|
112
|
+
const audioAtt = resource.attachments?.find(
|
|
113
|
+
(a) => attachmentMediaKind(a) === 'audio',
|
|
114
|
+
);
|
|
115
|
+
if (audioAtt?.url) {
|
|
116
|
+
return (
|
|
117
|
+
<ResourceCard
|
|
118
|
+
post={post}
|
|
119
|
+
preview={
|
|
120
|
+
<AudioAttachment
|
|
121
|
+
src={audioAtt.url}
|
|
122
|
+
label={audioAtt.filename ?? audioAtt.description}
|
|
123
|
+
size={audioAtt.meta?.size}
|
|
124
|
+
/>
|
|
125
|
+
}
|
|
126
|
+
/>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// All kinds: ResourceCard with click overlay
|
|
132
|
+
return (
|
|
133
|
+
<div className="relative">
|
|
134
|
+
<ResourceCard post={post} />
|
|
135
|
+
<div className="pointer-events-none absolute left-0 right-0 top-0 flex h-48 items-center justify-center">
|
|
136
|
+
<div
|
|
137
|
+
className="pointer-events-auto flex size-20 cursor-pointer items-center justify-center rounded-full bg-black/60 text-white"
|
|
138
|
+
onClick={handlePreviewClick}
|
|
139
|
+
role="button"
|
|
140
|
+
aria-label={previewLabel()}
|
|
141
|
+
>
|
|
142
|
+
{previewIcon()}
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<FullPostLayout post={post} deleteCallback={() => window.history.back()}>
|
|
151
|
+
<article className="bg-background border-border relative min-w-0 border-b p-4">
|
|
152
|
+
<PostInfoHeader
|
|
153
|
+
post={post}
|
|
154
|
+
showMenu
|
|
155
|
+
deleteCallback={() => window.history.back()}
|
|
156
|
+
/>
|
|
157
|
+
<div className="flex w-full min-w-0 flex-col gap-3">
|
|
158
|
+
{renderMedia()}
|
|
159
|
+
{galleryIndex !== null ? (
|
|
160
|
+
<GalleryModal
|
|
161
|
+
attachments={resource.attachments ?? []}
|
|
162
|
+
initialIndex={galleryIndex}
|
|
163
|
+
onClose={() => setGalleryIndex(null)}
|
|
164
|
+
/>
|
|
165
|
+
) : null}
|
|
166
|
+
{resource?.content ? (
|
|
167
|
+
<PostMarkdown source={resource.content} />
|
|
168
|
+
) : null}
|
|
169
|
+
</div>
|
|
170
|
+
</article>
|
|
171
|
+
</FullPostLayout>
|
|
172
|
+
);
|
|
173
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import type { CategoryNode } from '@openpeepshq/common/lib';
|
|
3
|
+
import { Button, Input } from '@openpeepshq/react-ui';
|
|
4
|
+
import { useT } from '../../i18n';
|
|
5
|
+
|
|
6
|
+
export interface CategoryPathPickerProps {
|
|
7
|
+
path: string[];
|
|
8
|
+
tree: CategoryNode[];
|
|
9
|
+
onChange: (path: string[]) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const NodeList = ({
|
|
13
|
+
nodes,
|
|
14
|
+
selected,
|
|
15
|
+
onSelect,
|
|
16
|
+
}: {
|
|
17
|
+
nodes: CategoryNode[];
|
|
18
|
+
selected: string[];
|
|
19
|
+
onSelect: (path: string[]) => void;
|
|
20
|
+
}) => (
|
|
21
|
+
<ul className="border-border ml-3 border-l pl-3">
|
|
22
|
+
{nodes.map((node) => {
|
|
23
|
+
const active =
|
|
24
|
+
selected.length === node.path.length &&
|
|
25
|
+
node.path.every((segment, index) => selected[index] === segment);
|
|
26
|
+
return (
|
|
27
|
+
<li key={node.path.join('/')} className="py-0.5">
|
|
28
|
+
<button
|
|
29
|
+
type="button"
|
|
30
|
+
className={`text-sm ${active ? 'text-foreground font-semibold' : 'text-muted-foreground hover:text-foreground'}`}
|
|
31
|
+
onClick={() => onSelect(node.path)}
|
|
32
|
+
>
|
|
33
|
+
{node.name}
|
|
34
|
+
</button>
|
|
35
|
+
{node.children.length ? (
|
|
36
|
+
<NodeList
|
|
37
|
+
nodes={node.children}
|
|
38
|
+
selected={selected}
|
|
39
|
+
onSelect={onSelect}
|
|
40
|
+
/>
|
|
41
|
+
) : null}
|
|
42
|
+
</li>
|
|
43
|
+
);
|
|
44
|
+
})}
|
|
45
|
+
</ul>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export const CategoryPathPicker = ({
|
|
49
|
+
path,
|
|
50
|
+
tree,
|
|
51
|
+
onChange,
|
|
52
|
+
}: CategoryPathPickerProps) => {
|
|
53
|
+
const t = useT();
|
|
54
|
+
const [level, setLevel] = useState('');
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div className="space-y-2">
|
|
58
|
+
<p className="text-muted-foreground text-sm">
|
|
59
|
+
{path.length
|
|
60
|
+
? path.join(' / ')
|
|
61
|
+
: t('resources.form.uncategorized', {
|
|
62
|
+
defaultValue: 'Uncategorized',
|
|
63
|
+
})}
|
|
64
|
+
</p>
|
|
65
|
+
{tree.length ? (
|
|
66
|
+
<NodeList nodes={tree} selected={path} onSelect={onChange} />
|
|
67
|
+
) : null}
|
|
68
|
+
<div className="flex gap-2">
|
|
69
|
+
<Input
|
|
70
|
+
value={level}
|
|
71
|
+
onChange={(event) => setLevel(event.target.value)}
|
|
72
|
+
placeholder={t('resources.form.addLevel', {
|
|
73
|
+
defaultValue: 'Add a folder',
|
|
74
|
+
})}
|
|
75
|
+
/>
|
|
76
|
+
<Button
|
|
77
|
+
variant="outline"
|
|
78
|
+
action={() => {
|
|
79
|
+
const name = level.trim();
|
|
80
|
+
if (!name) return;
|
|
81
|
+
onChange([...path, name]);
|
|
82
|
+
setLevel('');
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
{t('resources.form.addLevelAction', { defaultValue: 'Add' })}
|
|
86
|
+
</Button>
|
|
87
|
+
{path.length ? (
|
|
88
|
+
<Button variant="ghost" action={() => onChange([])}>
|
|
89
|
+
{t('resources.form.clearPath', { defaultValue: 'Clear' })}
|
|
90
|
+
</Button>
|
|
91
|
+
) : null}
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
};
|