@openpeepshq/react 0.7.1 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/markdown/compileMarkdown.js +1 -0
- package/dist/components/navigation/FooterMobile.js +4 -3
- package/dist/components/navigation/HeaderMobile.js +5 -2
- package/dist/components/navigation/MobileMenuItem.d.ts +3 -1
- package/dist/components/navigation/MobileMenuItem.js +7 -2
- package/dist/components/navigation/NavWithTooltip.d.ts +9 -0
- package/dist/components/navigation/NavWithTooltip.js +4 -0
- package/dist/components/navigation/index.d.ts +2 -0
- package/dist/components/navigation/index.js +1 -0
- package/dist/components/navigation/sideBarNavLinkClass.d.ts +6 -4
- package/dist/components/navigation/sideBarNavLinkClass.js +6 -2
- package/dist/components/post/CompactReplyParent.js +5 -6
- package/dist/components/post/TruncatedMarkdown.d.ts +27 -0
- package/dist/components/post/TruncatedMarkdown.js +37 -0
- package/dist/components/post/helpers.d.ts +2 -2
- package/dist/components/post/helpers.js +3 -16
- package/dist/components/post/index.d.ts +2 -0
- package/dist/components/post/index.js +1 -0
- package/dist/components/post/pieces/EventLocation.js +14 -0
- package/dist/components/post/pieces/EventRsvpButton.js +3 -1
- package/dist/components/post/pieces/PollContent.js +8 -2
- package/dist/components/post/post-form/ArticleForm.js +1 -1
- package/dist/components/post/post-form/ComposeAttachments.d.ts +5 -1
- package/dist/components/post/post-form/ComposeAttachments.js +20 -6
- package/dist/components/post/post-form/ComposeAttachments.test.d.ts +1 -0
- package/dist/components/post/post-form/ComposeAttachments.test.js +131 -0
- package/dist/components/post/post-form/EventForm.js +23 -3
- package/dist/components/post/post-form/ResourceForm.d.ts +3 -1
- package/dist/components/post/post-form/ResourceForm.js +51 -7
- package/dist/components/post/post-form/VisibilitySelector.js +9 -3
- package/dist/components/post/types/Article.js +2 -3
- package/dist/components/post/types/Event.js +10 -1
- package/dist/components/post/types/resource/FullResource.js +3 -3
- package/dist/components/preview-link/local/WelcomePreview.js +4 -2
- package/dist/components/resources/ResourceCard.d.ts +5 -1
- package/dist/components/resources/ResourceCard.js +94 -37
- package/dist/components/resources/ResourceCard.test.d.ts +1 -0
- package/dist/components/resources/ResourceCard.test.js +75 -0
- package/dist/components/resources/ResourceLibrary.js +1 -1
- package/dist/hooks/events/useEventRsvp.d.ts +1 -0
- package/dist/hooks/events/useEventRsvp.js +15 -7
- package/dist/hooks/posts/useResourceComposer.d.ts +2 -0
- package/dist/hooks/posts/useResourceComposer.js +131 -25
- package/dist/hooks/resources/useResourceLibrary.d.ts +1 -1
- package/dist/hooks/resources/useResourceLibrary.js +6 -2
- package/dist/hooks/useWelcomePreview.d.ts +3 -0
- package/dist/hooks/useWelcomePreview.js +1 -0
- package/dist/navigation/menuItems.js +15 -0
- package/dist/navigation/targets.d.ts +2 -0
- package/dist/pages/admin/community/CommunityMarkdownPage.js +2 -1
- package/dist/pages/auth/Register.js +3 -1
- package/dist/pages/resources/Edit.js +3 -3
- package/dist/pages/resources/New.js +2 -2
- package/dist/pages/settings/Account.js +30 -2
- package/package.json +2 -2
- package/src/components/markdown/compileMarkdown.ts +1 -0
- package/src/components/navigation/FooterMobile.tsx +41 -33
- package/src/components/navigation/HeaderMobile.tsx +55 -41
- package/src/components/navigation/MobileMenuItem.tsx +15 -2
- package/src/components/navigation/NavWithTooltip.tsx +26 -0
- package/src/components/navigation/index.ts +2 -0
- package/src/components/navigation/sideBarNavLinkClass.ts +9 -6
- package/src/components/post/CompactReplyParent.tsx +17 -10
- package/src/components/post/TruncatedMarkdown.tsx +91 -0
- package/src/components/post/helpers.ts +4 -18
- package/src/components/post/index.ts +2 -0
- package/src/components/post/pieces/EventLocation.tsx +27 -0
- package/src/components/post/pieces/EventRsvpButton.tsx +3 -0
- package/src/components/post/pieces/PollContent.tsx +8 -2
- package/src/components/post/post-form/ArticleForm.tsx +1 -1
- package/src/components/post/post-form/ComposeAttachments.tsx +24 -3
- package/src/components/post/post-form/EventForm.tsx +43 -15
- package/src/components/post/post-form/ResourceForm.tsx +135 -4
- package/src/components/post/post-form/VisibilitySelector.tsx +11 -3
- package/src/components/post/types/Article.tsx +5 -5
- package/src/components/post/types/Event.tsx +68 -7
- package/src/components/post/types/resource/FullResource.tsx +9 -1
- package/src/components/preview-link/local/WelcomePreview.tsx +11 -2
- package/src/components/resources/ResourceCard.tsx +184 -62
- package/src/components/resources/ResourceLibrary.tsx +2 -2
- package/src/hooks/events/useEventRsvp.ts +19 -7
- package/src/hooks/posts/useResourceComposer.ts +157 -33
- package/src/hooks/resources/useResourceLibrary.ts +6 -2
- package/src/hooks/useWelcomePreview.ts +4 -0
- package/src/navigation/menuItems.ts +16 -0
- package/src/navigation/targets.ts +2 -0
- package/src/pages/admin/community/CommunityMarkdownPage.tsx +5 -1
- package/src/pages/auth/Register.tsx +12 -0
- package/src/pages/resources/Edit.tsx +3 -2
- package/src/pages/resources/New.tsx +6 -1
- package/src/pages/settings/Account.tsx +51 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { X } from 'lucide-react';
|
|
4
4
|
import { EVENT_HEADER_ASPECT_RATIO, parseEventMaxAttendeesInput, parseEventWaitlistOfferMinutesInput, utcIsoToZonedDateTime, zonedDateTimeToUtcIso, } from '@openpeepshq/common/lib';
|
|
@@ -19,6 +19,7 @@ const TIMEZONES = typeof Intl !== 'undefined' && 'supportedValuesOf' in Intl
|
|
|
19
19
|
export const EventForm = ({ postData, onChange, isEdit = false, occurrenceEdit = false, }) => {
|
|
20
20
|
const t = useT();
|
|
21
21
|
const [audienceOpen, setAudienceOpen] = useState(false);
|
|
22
|
+
const [endBeforeStart, setEndBeforeStart] = useState(false);
|
|
22
23
|
const { event, eventTimeZone, showEndDate, repeatFreq, repeatEnd, preview, patchEvent, setEvent, setAudience, applyFreq, toggleWeekday, applyRepeatEnd, setRepeatUntil, setRepeatCount, toggleEndDate, setTimeZone, } = useEventForm(postData, onChange);
|
|
23
24
|
return (_jsxs("div", { "data-testid": "events-form-basic-details", children: [_jsx(ImageInput, { usage: "event-header-image", url: event.image, onChange: (image) => patchEvent({ image }), aspectRatio: EVENT_HEADER_ASPECT_RATIO, className: "aspect-video !h-auto", text: t('events.form.imageDescription', {
|
|
24
25
|
defaultValue: 'Upload an image for your event',
|
|
@@ -32,11 +33,30 @@ export const EventForm = ({ postData, onChange, isEdit = false, occurrenceEdit =
|
|
|
32
33
|
defaultValue: 'Date and Time',
|
|
33
34
|
}) }), _jsx(Label, { title: t('events.form.startDate', { defaultValue: 'Start Date' }), htmlFor: "event-start", children: _jsx(Input, { id: "event-start", type: "datetime-local", step: 60, value: dateToInputValue(event.start, eventTimeZone), onChange: (e) => {
|
|
34
35
|
const start = toIso(e.target.value, eventTimeZone);
|
|
35
|
-
if (start)
|
|
36
|
+
if (start) {
|
|
37
|
+
if (event.end && new Date(event.end) <= new Date(start)) {
|
|
38
|
+
setEndBeforeStart(true);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
setEndBeforeStart(false);
|
|
42
|
+
}
|
|
36
43
|
patchEvent({ start });
|
|
44
|
+
}
|
|
37
45
|
}, "data-testid": "events-start-input" }) }), _jsx(Label, { description: t('events.form.addEndDate', {
|
|
38
46
|
defaultValue: 'Add end date and time',
|
|
39
|
-
}), forCheckbox: true, children: _jsx("input", { type: "checkbox", checked: showEndDate, onChange: (e) => toggleEndDate(e.target.checked) }) }), showEndDate ? (_jsx(Label, { title: t('events.form.endDate', { defaultValue: 'End Date' }), htmlFor: "event-end", children: _jsx(Input, { id: "event-end", type: "datetime-local", step: 60, value: dateToInputValue(event.end, eventTimeZone), onChange: (e) =>
|
|
47
|
+
}), forCheckbox: true, children: _jsx("input", { type: "checkbox", checked: showEndDate, onChange: (e) => toggleEndDate(e.target.checked) }) }), showEndDate ? (_jsxs(_Fragment, { children: [_jsx(Label, { title: t('events.form.endDate', { defaultValue: 'End Date' }), htmlFor: "event-end", children: _jsx(Input, { id: "event-end", type: "datetime-local", step: 60, value: dateToInputValue(event.end, eventTimeZone), onChange: (e) => {
|
|
48
|
+
const newEnd = toIso(e.target.value, eventTimeZone);
|
|
49
|
+
if (newEnd &&
|
|
50
|
+
event.start &&
|
|
51
|
+
new Date(newEnd) <= new Date(event.start)) {
|
|
52
|
+
setEndBeforeStart(true);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
setEndBeforeStart(false);
|
|
56
|
+
patchEvent({ end: newEnd });
|
|
57
|
+
} }) }), endBeforeStart ? (_jsx("p", { className: "text-destructive text-sm", children: t('events.form.endBeforeStart', {
|
|
58
|
+
defaultValue: 'The end date and time must be after the start date and time.',
|
|
59
|
+
}) })) : null] })) : null, _jsx(Label, { title: t('events.form.timezone', { defaultValue: 'Timezone' }), htmlFor: "event-timezone", children: _jsx("select", { id: "event-timezone", className: "bg-background w-full rounded-md border px-3 py-2 text-sm", value: eventTimeZone, onChange: (e) => setTimeZone(e.target.value), children: TIMEZONES.map((tz) => (_jsx("option", { value: tz, children: tz }, tz))) }) }), !occurrenceEdit ? (_jsxs(_Fragment, { children: [_jsx(Label, { title: t('events.form.repeat.title', { defaultValue: 'Repeat' }), htmlFor: "event-repeat", children: _jsxs("select", { id: "event-repeat", className: "bg-background w-full rounded-md border px-3 py-2 text-sm", value: repeatFreq, onChange: (e) => applyFreq(e.target.value), "data-testid": "events-repeat-input", children: [_jsx("option", { value: "none", children: t('events.form.repeat.none', {
|
|
40
60
|
defaultValue: 'Does not repeat',
|
|
41
61
|
}) }), _jsx("option", { value: "DAILY", children: t('events.form.repeat.daily', { defaultValue: 'Daily' }) }), _jsx("option", { value: "WEEKLY", children: t('events.form.repeat.weekly', { defaultValue: 'Weekly' }) }), _jsx("option", { value: "MONTHLY", children: t('events.form.repeat.monthly', { defaultValue: 'Monthly' }) })] }) }), event.recurrence?.freq === 'WEEKLY' ? (_jsxs("div", { children: [_jsx("p", { className: "mb-2 text-sm", children: t('events.form.repeat.weekdays', {
|
|
42
62
|
defaultValue: 'Repeat on',
|
|
@@ -3,5 +3,7 @@ export interface ResourceFormProps {
|
|
|
3
3
|
postData: PostCreationData;
|
|
4
4
|
onChange: (data: PostCreationData) => void;
|
|
5
5
|
isEdit?: boolean;
|
|
6
|
+
/** Member can post this resource only to a group. */
|
|
7
|
+
groupOnly?: boolean;
|
|
6
8
|
}
|
|
7
|
-
export declare const ResourceForm: ({ postData, onChange, isEdit, }: ResourceFormProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare const ResourceForm: ({ postData, onChange, isEdit, groupOnly, }: ResourceFormProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo, useState } from 'react';
|
|
3
|
-
import { RESOURCE_KINDS, normalizeResourceTags } from '@openpeepshq/common/lib';
|
|
3
|
+
import { RESOURCE_KINDS, RESOURCE_TITLE_MAX_LENGTH, normalizeResourceTags, resourceFormIssues, } from '@openpeepshq/common/lib';
|
|
4
4
|
import { Button, Input, Label } from '@openpeepshq/react-ui';
|
|
5
5
|
import { useT } from '../../../i18n/index.js';
|
|
6
6
|
import { useCurrentProfile } from '../../layout/IdentityContext.js';
|
|
@@ -11,16 +11,19 @@ import { OpenpeepsMarkdownInput } from './OpenpeepsMarkdownInput.js';
|
|
|
11
11
|
import { PostAudienceSelector } from './PostAudienceSelector.js';
|
|
12
12
|
import { VisibilitySelector } from './VisibilitySelector.js';
|
|
13
13
|
import { useComposeAttachments } from './ComposeAttachments.js';
|
|
14
|
-
export const ResourceForm = ({ postData, onChange, isEdit = false, }) => {
|
|
14
|
+
export const ResourceForm = ({ postData, onChange, isEdit = false, groupOnly = false, }) => {
|
|
15
15
|
const t = useT();
|
|
16
16
|
const me = useCurrentProfile();
|
|
17
17
|
const resource = postData.data;
|
|
18
18
|
const [audienceOpen, setAudienceOpen] = useState(false);
|
|
19
19
|
const [tagDraft, setTagDraft] = useState('');
|
|
20
|
-
const library = useResourceLibrary(postData.groupId ?? undefined);
|
|
20
|
+
const library = useResourceLibrary(postData.groupId ?? undefined, !postData.groupId);
|
|
21
21
|
const attachments = useComposeAttachments({
|
|
22
22
|
attachments: resource.attachments ?? [],
|
|
23
23
|
onChange: (next) => patchResource({ attachments: next }),
|
|
24
|
+
// Only galleries take more than one file; other kinds pick one at a time.
|
|
25
|
+
multipleImages: resource.resourceKind === 'gallery',
|
|
26
|
+
multipleAudio: false,
|
|
24
27
|
});
|
|
25
28
|
const patchResource = (patch) => {
|
|
26
29
|
onChange({
|
|
@@ -43,6 +46,25 @@ export const ResourceForm = ({ postData, onChange, isEdit = false, }) => {
|
|
|
43
46
|
addTag();
|
|
44
47
|
}
|
|
45
48
|
};
|
|
49
|
+
const issues = resourceFormIssues({
|
|
50
|
+
title: resource.title,
|
|
51
|
+
resourceKind: resource.resourceKind,
|
|
52
|
+
url: resource.url,
|
|
53
|
+
attachments: resource.attachments,
|
|
54
|
+
visibility: postData.visibility,
|
|
55
|
+
audience: postData.audience,
|
|
56
|
+
groupId: postData.groupId,
|
|
57
|
+
});
|
|
58
|
+
const titleMissing = issues.includes('title');
|
|
59
|
+
const titleTooLong = issues.includes('titleLength');
|
|
60
|
+
const urlIssue = issues.includes('url');
|
|
61
|
+
const urlInvalid = urlIssue && Boolean(resource.url?.trim());
|
|
62
|
+
const mediaMissing = issues.includes('media');
|
|
63
|
+
const audienceMissing = issues.includes('audience');
|
|
64
|
+
const groupMissing = issues.includes('group');
|
|
65
|
+
const urlMessage = t('resources.validation.url', {
|
|
66
|
+
defaultValue: 'Enter a real link, like https://example.com',
|
|
67
|
+
});
|
|
46
68
|
const kindActions = useMemo(() => ({
|
|
47
69
|
gallery: attachments.openImagePicker,
|
|
48
70
|
video: attachments.openImagePicker,
|
|
@@ -50,9 +72,25 @@ export const ResourceForm = ({ postData, onChange, isEdit = false, }) => {
|
|
|
50
72
|
file: attachments.openDocumentPicker,
|
|
51
73
|
link: undefined,
|
|
52
74
|
}), [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' }) }),
|
|
75
|
+
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' }) }), _jsxs(Label, { title: t('resources.form.nameRequired', {
|
|
76
|
+
defaultValue: 'Title (Required)',
|
|
77
|
+
}), htmlFor: "resource-title", children: [_jsx(Input, { id: "resource-title", "data-testid": "resources-title", value: resource.title, maxLength: RESOURCE_TITLE_MAX_LENGTH, "aria-invalid": titleMissing || titleTooLong, "aria-describedby": titleMissing
|
|
78
|
+
? 'resource-title-error resource-title-count'
|
|
79
|
+
: 'resource-title-count', onChange: (event) => patchResource({ title: event.target.value }) }), titleMissing ? (_jsx("span", { id: "resource-title-error", role: "status", className: "text-muted-foreground mt-1 text-sm", children: t('resources.validation.titleRequired', {
|
|
80
|
+
defaultValue: 'Title is required',
|
|
81
|
+
}) })) : null, titleTooLong ? (_jsx("span", { role: "alert", className: "text-destructive mt-1 text-sm", children: t('resources.validation.titleTooLong', {
|
|
82
|
+
defaultValue: 'Title must be 200 characters or fewer',
|
|
83
|
+
}) })) : null, _jsxs("span", { id: "resource-title-count", className: "block w-full px-2 text-right text-sm", children: [_jsx("span", { className: titleTooLong ? 'text-error' : undefined, children: resource.title.length }), ' ', "/ ", RESOURCE_TITLE_MAX_LENGTH] })] }), _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' ? (_jsxs(Label, { title: t('resources.form.urlRequired', {
|
|
84
|
+
defaultValue: 'URL (Required)',
|
|
85
|
+
}), htmlFor: "resource-url", children: [_jsx(Input, { id: "resource-url", "data-testid": "resources-url", value: resource.url ?? '', placeholder: t('resources.form.urlPlaceholder', {
|
|
86
|
+
defaultValue: 'https://example.com',
|
|
87
|
+
}), inputMode: "url", spellCheck: false, error: urlInvalid, "aria-invalid": urlIssue, "aria-describedby": urlIssue ? 'resource-url-error' : undefined, onChange: (event) => patchResource({ url: event.target.value }) }), urlIssue ? (_jsx("span", { id: "resource-url-error", role: urlInvalid ? 'alert' : 'status', "data-testid": "resources-url-error", className: urlInvalid
|
|
88
|
+
? 'text-destructive mt-1 text-sm'
|
|
89
|
+
: 'text-muted-foreground mt-1 text-sm', children: urlMessage })) : null] })) : (_jsxs("div", { className: "space-y-2", children: [_jsx(Button, { variant: "outline", action: kindActions[resource.resourceKind], children: t('resources.form.addMedia', {
|
|
54
90
|
defaultValue: 'Add files',
|
|
55
|
-
}) }), attachments.previews, attachments.inputs
|
|
91
|
+
}) }), attachments.previews, attachments.inputs, mediaMissing ? (_jsx("p", { role: "status", className: "text-muted-foreground text-sm", children: t('resources.validation.mediaRequired', {
|
|
92
|
+
defaultValue: 'Add the media or link this resource needs',
|
|
93
|
+
}) })) : null] })), _jsx(OpenpeepsMarkdownInput, { rows: 8, maxLength: 4000, value: resource.content ?? '', onChange: (content) => patchResource({ content }), placeholder: t('resources.form.descriptionPlaceholder', {
|
|
56
94
|
defaultValue: 'Describe this resource',
|
|
57
95
|
}) }), _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
96
|
defaultValue: 'Add tags, then press Enter',
|
|
@@ -60,9 +98,15 @@ export const ResourceForm = ({ postData, onChange, isEdit = false, }) => {
|
|
|
60
98
|
tags: (resource.tags ?? []).filter((value) => value.toLowerCase() !== tag),
|
|
61
99
|
}), children: ["#", tag] }, tag))) })) : null, _jsxs("div", { children: [_jsx("p", { className: "mb-2 text-sm font-medium", children: t('resources.form.hierarchy', {
|
|
62
100
|
defaultValue: 'Place in the library',
|
|
63
|
-
}) }), _jsx(CategoryPathPicker, { path: resource.categoryPath ?? [], tree: library.tree, onChange: (categoryPath) => patchResource({ categoryPath }) })] }),
|
|
101
|
+
}) }), _jsx(CategoryPathPicker, { path: resource.categoryPath ?? [], tree: library.tree, onChange: (categoryPath) => patchResource({ categoryPath }) })] }), _jsxs(Label, { title: t('resources.form.visibility', {
|
|
64
102
|
defaultValue: 'Who can see this (Required)',
|
|
65
103
|
}), description: t('resources.form.visibilityNotChangeable', {
|
|
66
104
|
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 })
|
|
105
|
+
}), children: [_jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }), !isEdit && groupOnly ? (_jsx("span", { role: "status", className: "text-muted-foreground mt-1 text-sm", children: t('resources.form.groupOnly', {
|
|
106
|
+
defaultValue: 'You can only share resources with a group.',
|
|
107
|
+
}) })) : null, groupMissing ? (_jsx("span", { id: "resource-group-error", role: "status", className: "text-muted-foreground mt-1 text-sm", children: t('resources.validation.groupRequired', {
|
|
108
|
+
defaultValue: 'Choose a group before creating this resource.',
|
|
109
|
+
}) })) : null, audienceMissing ? (_jsx("span", { id: "resource-audience-error", role: "status", className: "text-muted-foreground mt-1 text-sm", children: t('resources.validation.directAudience', {
|
|
110
|
+
defaultValue: 'Choose at least one recipient for a direct resource.',
|
|
111
|
+
}) })) : null] })] }), !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
112
|
};
|
|
@@ -19,15 +19,21 @@ export const VisibilitySelector = ({ postData, onClick, disabled = false, showDi
|
|
|
19
19
|
}), [postData.type, authData, t, serverInfo.publicContent, showDirect]);
|
|
20
20
|
const selectedGroup = useMemo(() => me?.memberships?.find((m) => m.group.id === postData.groupId)?.group, [me?.memberships, postData.groupId]);
|
|
21
21
|
const description = (visibility) => audienceChoices.find((c) => c.value === visibility)?.description ?? '';
|
|
22
|
+
const choiceLabel = (visibility) => description(visibility) ||
|
|
23
|
+
(audienceChoices.length > 0
|
|
24
|
+
? t('posts.form.chooseAudience', {
|
|
25
|
+
defaultValue: 'Choose who can see this',
|
|
26
|
+
})
|
|
27
|
+
: '');
|
|
22
28
|
const content = () => {
|
|
23
29
|
if (postData.visibility === 'group') {
|
|
24
|
-
return (_jsxs("span", { className: "flex min-w-0 items-center gap-1 text-sm font-normal", children: [_jsx("span", { className: "shrink-0 pr-2", children:
|
|
30
|
+
return (_jsxs("span", { className: "flex min-w-0 items-center gap-1 text-sm font-normal", children: [_jsx("span", { className: "shrink-0 pr-2", children: choiceLabel('group') }), selectedGroup ? (_jsxs("span", { className: "flex min-w-0 items-center gap-1 truncate", children: [_jsx(GroupAvatar, { group: selectedGroup, size: 1.5, borderless: true }), _jsx("span", { className: "truncate", children: groupName(selectedGroup) })] })) : null] }));
|
|
25
31
|
}
|
|
26
32
|
if (postData.visibility === 'direct') {
|
|
27
33
|
const audience = postData.audience ?? [];
|
|
28
|
-
return (_jsxs("span", { className: "flex min-w-0 items-center gap-1 text-sm font-light", children: [_jsx("span", { className: "shrink-0 pr-2", children:
|
|
34
|
+
return (_jsxs("span", { className: "flex min-w-0 items-center gap-1 text-sm font-light", children: [_jsx("span", { className: "shrink-0 pr-2", children: choiceLabel('direct') }), audience.length ? (_jsx("span", { className: "flex min-w-0 flex-wrap items-center gap-1", children: audience.map((profile) => (_jsx(ProfileBadge, { profile: profile }, profile.id))) })) : null] }));
|
|
29
35
|
}
|
|
30
|
-
return (_jsx("span", { className: "text-sm font-light", children:
|
|
36
|
+
return (_jsx("span", { className: "text-sm font-light", children: choiceLabel(postData.visibility) }));
|
|
31
37
|
};
|
|
32
38
|
return (_jsxs("div", { className: "op-input-group grid grid-cols-[auto_1fr_auto]", children: [_jsx("div", { className: "op-input-group-shim", children: _jsx(Eye, { className: "size-4" }) }), _jsx("button", { type: "button", title: t('posts.form.changeAudience', {
|
|
33
39
|
defaultValue: 'Change audience',
|
|
@@ -2,8 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { ArrowRight } from 'lucide-react';
|
|
3
3
|
import { useT } from '../../../i18n/index.js';
|
|
4
4
|
import { resolveStaticUrl, useStaticRender } from '../../markdown/staticRender.js';
|
|
5
|
-
import {
|
|
6
|
-
import { OPENPEEPS_POST_CAPTION_CLASS } from '../../markdown/classes.js';
|
|
5
|
+
import { TruncatedMarkdown } from '../TruncatedMarkdown.js';
|
|
7
6
|
import { firstNWords } from '../helpers.js';
|
|
8
7
|
import { minutesToRead } from '@openpeepshq/common/lib';
|
|
9
8
|
export function FeedArticle({ post }) {
|
|
@@ -13,5 +12,5 @@ export function FeedArticle({ post }) {
|
|
|
13
12
|
const previewContent = firstNWords(article.content, 50);
|
|
14
13
|
const minutes = minutesToRead(article.content);
|
|
15
14
|
const showReadMore = !!article.content && previewContent.length < article.content.length;
|
|
16
|
-
return (_jsxs("div", { className: "flex w-full min-w-0 flex-col gap-2", children: [article.image && (_jsx("img", { src: article.image, className: "w-full object-cover", alt: `image for ${article.title ?? 'article'}` })), _jsxs("div", { className: "prose-sm", children: [_jsx("h3", { className: "text-foreground", children: article.title }), minutes > 0 && (_jsx("p", { className: "text-muted-foreground text-xs", children: t('posts.article.minutesToRead', { count: minutes }) }))] }), _jsx(
|
|
15
|
+
return (_jsxs("div", { className: "flex w-full min-w-0 flex-col gap-2", children: [article.image && (_jsx("img", { src: article.image, className: "w-full object-cover", alt: `image for ${article.title ?? 'article'}` })), _jsxs("div", { className: "prose-sm", children: [_jsx("h3", { className: "text-foreground", children: article.title }), minutes > 0 && (_jsx("p", { className: "text-muted-foreground text-xs", children: t('posts.article.minutesToRead', { count: minutes }) }))] }), _jsx(TruncatedMarkdown, { source: article.content ?? '', snippet: previewContent, interactive: false }), showReadMore && (_jsx("div", { className: "flex justify-end", children: _jsxs("a", { href: resolveStaticUrl(`/posts/${post.id}`, staticRender ? baseUrl : undefined), className: "text-primary inline-flex items-center gap-1 text-sm hover:underline", children: [t('posts.article.readMore', { defaultValue: 'Read more' }), _jsx(ArrowRight, { className: "inline-block size-4" })] }) }))] }));
|
|
17
16
|
}
|
|
@@ -26,5 +26,14 @@ export function FeedEvent({ post }) {
|
|
|
26
26
|
allDay: event.wholeDay,
|
|
27
27
|
})
|
|
28
28
|
: fmtRange(start, end);
|
|
29
|
-
|
|
29
|
+
const viewEventHref = resolveStaticUrl(`/posts/${post.id}`, staticRender ? baseUrl : undefined);
|
|
30
|
+
if (staticRender) {
|
|
31
|
+
return (_jsx("table", { role: "presentation", width: "100%", cellPadding: 0, cellSpacing: 0, style: { width: '100%', borderCollapse: 'collapse' }, children: _jsxs("tbody", { children: [event.image ? (_jsx("tr", { children: _jsx("td", { style: { paddingBottom: '8px' }, children: _jsx("img", { src: event.image, alt: `image for ${event.name ?? 'event'}`, width: "100%", style: {
|
|
32
|
+
display: 'block',
|
|
33
|
+
width: '100%',
|
|
34
|
+
maxWidth: '100%',
|
|
35
|
+
height: 'auto',
|
|
36
|
+
} }) }) })) : null, _jsx("tr", { children: _jsx("td", { className: "text-destructive pb-2 text-sm", children: when }) }), _jsx("tr", { children: _jsx("td", { className: "pb-2 text-lg font-medium", children: event.name }) }), event.recurrence ? (_jsx("tr", { children: _jsx("td", { className: "text-muted-foreground pb-2 text-sm", children: formatEventRecurrence(event.recurrence, t, event.start) }) })) : null, event.physicalLocation || event.jam || event.url ? (_jsx("tr", { children: _jsx("td", { className: "pb-2", children: _jsx(EventLocation, { post: post }) }) })) : null, _jsx("tr", { children: _jsx("td", { children: _jsx("a", { href: viewEventHref, className: "text-primary text-sm underline", children: t('posts.event.viewEvent', { defaultValue: 'View Event' }) }) }) })] }) }));
|
|
37
|
+
}
|
|
38
|
+
return (_jsxs("div", { className: "flex w-full flex-col gap-2", children: [event.image && (_jsx("span", { className: "aspect-video w-full overflow-hidden", children: _jsx("img", { src: event.image, className: "h-full w-full object-cover", alt: `image for ${event.name ?? 'event'}` }) })), _jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsxs("span", { className: "text-destructive text-sm", children: [when, ' ', _jsx("span", { className: "text-muted-foreground", children: "(your local time)" })] }), _jsx(Button, { action: viewEventHref, variant: "outline", compact: true, className: "shrink-0", children: t('posts.event.viewEvent', { defaultValue: 'View Event' }) })] }), _jsx("div", { className: "text-lg font-medium", children: event.name }), event.recurrence ? (_jsx("p", { className: "text-muted-foreground text-sm", children: formatEventRecurrence(event.recurrence, t, event.start) })) : null, _jsx(EventLocation, { post: post })] }));
|
|
30
39
|
}
|
|
@@ -83,17 +83,17 @@ export const FullResource = ({ post }) => {
|
|
|
83
83
|
if (resource.resourceKind === 'video' && playerVisible) {
|
|
84
84
|
const videoAtt = resource.attachments?.find((a) => attachmentMediaKind(a) === 'video');
|
|
85
85
|
if (videoAtt) {
|
|
86
|
-
return (_jsx(ResourceCard, { post: post, preview: _jsx(VideoPlayer, { attachment: videoAtt, className: "max-h-[600px] w-full" }) }));
|
|
86
|
+
return (_jsx(ResourceCard, { post: post, showDescription: false, inGroup: !!post.group, preview: _jsx(VideoPlayer, { attachment: videoAtt, className: "max-h-[600px] w-full" }) }));
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
if (resource.resourceKind === 'audio' && playerVisible) {
|
|
90
90
|
const audioAtt = resource.attachments?.find((a) => attachmentMediaKind(a) === 'audio');
|
|
91
91
|
if (audioAtt?.url) {
|
|
92
|
-
return (_jsx(ResourceCard, { post: post, preview: _jsx(AudioAttachment, { src: audioAtt.url, label: audioAtt.filename ?? audioAtt.description, size: audioAtt.meta?.size }) }));
|
|
92
|
+
return (_jsx(ResourceCard, { post: post, showDescription: false, inGroup: !!post.group, preview: _jsx(AudioAttachment, { src: audioAtt.url, label: audioAtt.filename ?? audioAtt.description, size: audioAtt.meta?.size }) }));
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
// All kinds: ResourceCard with click overlay
|
|
96
|
-
return (_jsxs("div", { className: "relative", children: [_jsx(ResourceCard, { post: post }), _jsx("div", { className: "pointer-events-none absolute left-0 right-0 top-0 flex h-48 items-center justify-center", children: _jsx("div", { className: "pointer-events-auto flex size-20 cursor-pointer items-center justify-center rounded-full bg-black/60 text-white", onClick: handlePreviewClick, role: "button", "aria-label": previewLabel(), children: previewIcon() }) })] }));
|
|
96
|
+
return (_jsxs("div", { className: "relative", children: [_jsx(ResourceCard, { post: post, showDescription: false, inGroup: !!post.group }), _jsx("div", { className: "pointer-events-none absolute left-0 right-0 top-0 flex h-48 items-center justify-center", children: _jsx("div", { className: "pointer-events-auto flex size-20 cursor-pointer items-center justify-center rounded-full bg-black/60 text-white", onClick: handlePreviewClick, role: "button", "aria-label": previewLabel(), children: previewIcon() }) })] }));
|
|
97
97
|
};
|
|
98
98
|
return (_jsx(FullPostLayout, { post: post, deleteCallback: () => window.history.back(), children: _jsxs("article", { className: "bg-background border-border relative min-w-0 border-b p-4", children: [_jsx(PostInfoHeader, { post: post, showMenu: true, deleteCallback: () => window.history.back() }), _jsxs("div", { className: "flex w-full min-w-0 flex-col gap-3", children: [renderMedia(), galleryIndex !== null ? (_jsx(GalleryModal, { attachments: resource.attachments ?? [], initialIndex: galleryIndex, onClose: () => setGalleryIndex(null) })) : null, resource?.content ? (_jsx(PostMarkdown, { source: resource.content })) : null] })] }) }));
|
|
99
99
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useWelcomePreview } from '../../../hooks/useWelcomePreview.js';
|
|
3
|
+
import { truncateMarkdown, stripMarkdownImages } from '@openpeepshq/common/lib';
|
|
4
|
+
import { TruncatedMarkdown } from '../../post/TruncatedMarkdown.js';
|
|
3
5
|
export const WelcomePreview = () => {
|
|
4
|
-
const { eyebrow, title, description, imageUrl, imageFit } = useWelcomePreview();
|
|
5
|
-
return (_jsxs("div", { "data-testid": "welcome-preview-card", className: "flex w-full min-w-0 flex-row items-center gap-4", children: [imageUrl ? (_jsx("div", { className: "flex h-24 w-24 shrink-0 items-center justify-center overflow-hidden rounded-md", children: _jsx("img", { src: imageUrl, alt: "", className: `h-full w-full ${imageFit === 'cover' ? 'object-cover' : 'object-contain'}` }) })) : null, _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [eyebrow ? (_jsx("p", { className: "text-muted-foreground truncate text-xs", children: eyebrow })) : null, _jsx("p", { className: "line-clamp-2 font-semibold", children: title }), description ? (_jsx("p", { className: "text-muted-foreground line-clamp-3 break-words text-sm", children: description })) : null] })] }));
|
|
6
|
+
const { eyebrow, title, description, markdown, imageUrl, imageFit } = useWelcomePreview();
|
|
7
|
+
return (_jsxs("div", { "data-testid": "welcome-preview-card", className: "flex w-full min-w-0 flex-row items-center gap-4", children: [imageUrl ? (_jsx("div", { className: "flex h-24 w-24 shrink-0 items-center justify-center overflow-hidden rounded-md", children: _jsx("img", { src: imageUrl, alt: "", className: `h-full w-full ${imageFit === 'cover' ? 'object-cover' : 'object-contain'}` }) })) : null, _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [eyebrow ? (_jsx("p", { className: "text-muted-foreground truncate text-xs", children: eyebrow })) : null, _jsx("p", { className: "line-clamp-2 font-semibold", children: title }), markdown ? (_jsx(TruncatedMarkdown, { source: markdown, snippet: truncateMarkdown(stripMarkdownImages(markdown), 2, 240), maxLines: 2, className: "break-words text-sm text-muted-foreground" })) : description ? (_jsx("p", { className: "text-muted-foreground line-clamp-3 break-words text-sm", children: description })) : null] })] }));
|
|
6
8
|
};
|
|
@@ -4,5 +4,9 @@ export interface ResourceCardProps {
|
|
|
4
4
|
post: PublicPost;
|
|
5
5
|
layout?: 'card' | 'list';
|
|
6
6
|
preview?: ReactNode;
|
|
7
|
+
/** Set false when the full description is rendered by the surrounding layout (e.g. the post detail page). */
|
|
8
|
+
showDescription?: boolean;
|
|
9
|
+
/** When true, hides the group label (already shown by the group context). */
|
|
10
|
+
inGroup?: boolean;
|
|
7
11
|
}
|
|
8
|
-
export declare const ResourceCard: ({ post, layout, preview, }: ResourceCardProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
+
export declare const ResourceCard: ({ post, layout, preview, showDescription, inGroup, }: ResourceCardProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo, useState } from 'react';
|
|
3
3
|
import { BookmarkCheck, BookmarkPlus, Link as LinkIcon, ImageOff, } from 'lucide-react';
|
|
4
|
-
import { attachmentMediaKind,
|
|
4
|
+
import { attachmentMediaKind, formatSize, groupName, normalizeResourceTags, } from '@openpeepshq/common/lib';
|
|
5
|
+
import { useHrefOf, useNavigate } from '../../contexts/router/index.js';
|
|
5
6
|
import { useT } from '../../i18n/index.js';
|
|
7
|
+
import { useStaticRender } from '../markdown/staticRender.js';
|
|
6
8
|
import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
|
|
7
9
|
import { useCurrentProfile } from '../layout/IdentityContext.js';
|
|
8
10
|
import { VideoPlayOverlay } from '../post/VideoPlayOverlay.js';
|
|
11
|
+
import { TruncatedMarkdown } from '../post/TruncatedMarkdown.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. */
|
|
@@ -25,6 +28,64 @@ const primaryActionLabel = (kind, t) => {
|
|
|
25
28
|
return null;
|
|
26
29
|
}
|
|
27
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Bookmark toggle. Lives in its own component so ResourceCard itself stays
|
|
33
|
+
* free of app providers (OpenpeepsProvider, IdentityContext, RouterProvider)
|
|
34
|
+
* and can render in provider-less static contexts such as notification emails.
|
|
35
|
+
*/
|
|
36
|
+
const ResourceSaveButton = ({ postId, className, }) => {
|
|
37
|
+
const t = useT();
|
|
38
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
39
|
+
const me = useCurrentProfile();
|
|
40
|
+
const bookmarkedIdsQuery = openpeepsApi.useCurrentProfileBookmarkedIds();
|
|
41
|
+
const bookmarkPost = openpeepsApi.bookmarkPostAction({ id: postId });
|
|
42
|
+
const unbookmarkPost = openpeepsApi.unbookmarkPostAction({ id: postId });
|
|
43
|
+
const isBookmarked = bookmarkedIdsQuery.data?.includes(postId) ?? false;
|
|
44
|
+
const toggleBookmark = () => {
|
|
45
|
+
if (!me)
|
|
46
|
+
return;
|
|
47
|
+
if (isBookmarked) {
|
|
48
|
+
unbookmarkPost(undefined);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
bookmarkPost(undefined);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return (_jsx("button", { type: "button", onClick: (e) => {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
e.stopPropagation();
|
|
57
|
+
toggleBookmark();
|
|
58
|
+
}, disabled: !me, className: className, title: isBookmarked
|
|
59
|
+
? t('resources.actions.saved', { defaultValue: 'Saved' })
|
|
60
|
+
: t('resources.actions.save', { defaultValue: 'Save' }), children: isBookmarked ? (_jsx(BookmarkCheck, { className: "text-primary size-4" })) : (_jsx(BookmarkPlus, { className: "size-4" })) }));
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Clickable hashtag chip. Child component like ResourceSaveButton so the
|
|
64
|
+
* router hook stays out of ResourceCard's static (email) render path.
|
|
65
|
+
*/
|
|
66
|
+
const ResourceTagChip = ({ value }) => {
|
|
67
|
+
const navigate = useNavigate();
|
|
68
|
+
return (_jsxs("button", { type: "button", className: "bg-muted text-muted-foreground hover:text-foreground rounded-full px-2 py-0.5 text-xs", onClick: (e) => {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
e.stopPropagation();
|
|
71
|
+
navigate({ type: 'tags', hashtag: value });
|
|
72
|
+
}, children: ["#", value] }));
|
|
73
|
+
};
|
|
74
|
+
/** Clickable group label. Child component so the router hook stays out of the static render path. */
|
|
75
|
+
const ResourceGroupLabel = ({ group }) => {
|
|
76
|
+
const t = useT();
|
|
77
|
+
const hrefOf = useHrefOf();
|
|
78
|
+
const groupLabel = groupName(group);
|
|
79
|
+
return (_jsx("a", { href: hrefOf({ type: 'group', handle: group.handle }), onClick: (e) => {
|
|
80
|
+
e.stopPropagation();
|
|
81
|
+
}, className: "text-muted-foreground hover:text-foreground inline-flex items-center gap-1 text-xs", title: t('resources.group.inGroup', {
|
|
82
|
+
defaultValue: 'in {{groupName}}',
|
|
83
|
+
groupName: groupLabel,
|
|
84
|
+
}), children: _jsx("span", { className: "bg-muted rounded-full px-2 py-0.5 text-xs", children: t('resources.group.inGroup', {
|
|
85
|
+
defaultValue: 'in {{groupName}}',
|
|
86
|
+
groupName: groupLabel,
|
|
87
|
+
}) }) }));
|
|
88
|
+
};
|
|
28
89
|
const MediaPreview = ({ src, alt, className, isVideo, isLast, extra, }) => {
|
|
29
90
|
const [errored, setErrored] = useState(false);
|
|
30
91
|
if (!src) {
|
|
@@ -35,24 +96,26 @@ const MediaPreview = ({ src, alt, className, isVideo, isLast, extra, }) => {
|
|
|
35
96
|
}
|
|
36
97
|
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
98
|
};
|
|
38
|
-
export const ResourceCard = ({ post, layout = 'card', preview, }) => {
|
|
99
|
+
export const ResourceCard = ({ post, layout = 'card', preview, showDescription = true, inGroup = false, }) => {
|
|
39
100
|
const t = useT();
|
|
40
|
-
const {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
return null;
|
|
44
|
-
const resource = post.data;
|
|
45
|
-
const attachments = resource.attachments ?? [];
|
|
101
|
+
const { enabled: staticRender } = useStaticRender();
|
|
102
|
+
const resource = post.data?.type === 'resource' ? post.data : undefined;
|
|
103
|
+
const attachments = resource?.attachments ?? [];
|
|
46
104
|
const visuals = visualAttachments(attachments);
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const isGallery = resource.resourceKind === 'gallery' && visuals.length > 1;
|
|
105
|
+
const tags = normalizeResourceTags(resource?.tags);
|
|
106
|
+
const isGallery = resource?.resourceKind === 'gallery' && visuals.length > 1;
|
|
50
107
|
const tiles = isGallery ? visuals.slice(0, 4) : visuals.slice(0, 1);
|
|
51
108
|
const extra = isGallery ? Math.max(0, visuals.length - 4) : 0;
|
|
52
|
-
const actionLabel =
|
|
109
|
+
const actionLabel = resource
|
|
110
|
+
? primaryActionLabel(resource.resourceKind, t)
|
|
111
|
+
: null;
|
|
53
112
|
const thumbnail = visuals[0];
|
|
54
113
|
const thumbSrc = thumbnail ? previewSrc(thumbnail) : null;
|
|
114
|
+
const group = post.group;
|
|
115
|
+
const groupLabel = group ? groupName(group) : null;
|
|
55
116
|
const metaText = useMemo(() => {
|
|
117
|
+
if (!resource)
|
|
118
|
+
return null;
|
|
56
119
|
if (resource.resourceKind === 'gallery' && visuals.length > 1) {
|
|
57
120
|
return t('resources.meta.imagesCount', {
|
|
58
121
|
defaultValue: '{{count}} images',
|
|
@@ -66,31 +129,25 @@ export const ResourceCard = ({ post, layout = 'card', preview, }) => {
|
|
|
66
129
|
if (size)
|
|
67
130
|
return formatSize(size);
|
|
68
131
|
return null;
|
|
69
|
-
}, [resource
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
};
|
|
132
|
+
}, [resource, visuals, attachments, t]);
|
|
133
|
+
if (!resource)
|
|
134
|
+
return null;
|
|
84
135
|
const downloadUrl = resource.resourceKind === 'file'
|
|
85
136
|
? attachments.find((att) => attachmentMediaKind(att) === 'file')?.url
|
|
86
137
|
: null;
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
:
|
|
138
|
+
const renderSaveButton = (className) => staticRender ? null : (_jsx(ResourceSaveButton, { postId: post.id, className: className }));
|
|
139
|
+
const renderGroupLabel = () => {
|
|
140
|
+
if (!group || !groupLabel || inGroup)
|
|
141
|
+
return null;
|
|
142
|
+
const label = t('resources.group.inGroup', {
|
|
143
|
+
defaultValue: 'in {{groupName}}',
|
|
144
|
+
groupName: groupLabel,
|
|
145
|
+
});
|
|
146
|
+
if (staticRender) {
|
|
147
|
+
return (_jsx("span", { className: "text-muted-foreground inline-flex items-center gap-1 text-xs", children: _jsx("span", { className: "bg-muted rounded-full px-2 py-0.5 text-xs", children: label }) }));
|
|
148
|
+
}
|
|
149
|
+
return _jsx(ResourceGroupLabel, { group: group });
|
|
150
|
+
};
|
|
94
151
|
const renderThumbnail = () => {
|
|
95
152
|
if (thumbSrc) {
|
|
96
153
|
return (_jsx("img", { src: thumbSrc, alt: thumbnail?.description ?? resource.title, className: THUMB_CLASS, onError: (e) => {
|
|
@@ -103,8 +160,8 @@ export const ResourceCard = ({ post, layout = 'card', preview, }) => {
|
|
|
103
160
|
return null;
|
|
104
161
|
};
|
|
105
162
|
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,
|
|
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,
|
|
163
|
+
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, interactive: !staticRender, 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' &&
|
|
164
|
+
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, renderSaveButton('text-muted-foreground hover:text-foreground disabled:opacity-50')] })] }));
|
|
108
165
|
}
|
|
109
166
|
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
167
|
? 'grid h-48 grid-cols-2 grid-rows-2 gap-1'
|
|
@@ -115,7 +172,7 @@ export const ResourceCard = ({ post, layout = 'card', preview, }) => {
|
|
|
115
172
|
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
173
|
? 'h-full w-full object-cover'
|
|
117
174
|
: 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,
|
|
175
|
+
}) })) : 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, renderSaveButton('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, interactive: !staticRender, 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) => staticRender ? (_jsxs("span", { className: "bg-muted text-muted-foreground rounded-full px-2 py-0.5 text-xs", children: ["#", value] }, value)) : (_jsx(ResourceTagChip, { value: value }, value))) })) : null, _jsx("p", { className: "text-muted-foreground text-xs uppercase", children: t(`resources.kinds.${resource.resourceKind}`, {
|
|
119
176
|
defaultValue: resource.resourceKind,
|
|
120
177
|
}) })] }));
|
|
121
178
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
import { act, createElement } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { ResourceCard } from './ResourceCard.js';
|
|
6
|
+
const navigate = vi.fn();
|
|
7
|
+
vi.mock('../../i18n', () => ({
|
|
8
|
+
useT: () => (key, opts) => opts?.defaultValue ?? key,
|
|
9
|
+
}));
|
|
10
|
+
vi.mock('../../contexts/openpeeps', () => ({
|
|
11
|
+
useOpenpeeps: () => ({
|
|
12
|
+
openpeepsApi: {
|
|
13
|
+
useCurrentProfileBookmarkedIds: () => ({ data: [] }),
|
|
14
|
+
bookmarkPostAction: () => async () => undefined,
|
|
15
|
+
unbookmarkPostAction: () => async () => undefined,
|
|
16
|
+
},
|
|
17
|
+
}),
|
|
18
|
+
}));
|
|
19
|
+
vi.mock('../layout/IdentityContext', () => ({
|
|
20
|
+
useCurrentProfile: () => undefined,
|
|
21
|
+
}));
|
|
22
|
+
vi.mock('../../contexts/router', () => ({
|
|
23
|
+
useNavigate: () => navigate,
|
|
24
|
+
useHrefOf: () => () => '#',
|
|
25
|
+
}));
|
|
26
|
+
vi.mock('../post/TruncatedMarkdown', () => ({
|
|
27
|
+
TruncatedMarkdown: () => null,
|
|
28
|
+
}));
|
|
29
|
+
vi.mock('../post/VideoPlayOverlay', () => ({
|
|
30
|
+
VideoPlayOverlay: () => null,
|
|
31
|
+
}));
|
|
32
|
+
const resourcePost = (tags) => ({
|
|
33
|
+
id: 'post-1',
|
|
34
|
+
type: 'resource',
|
|
35
|
+
data: {
|
|
36
|
+
type: 'resource',
|
|
37
|
+
title: 'Guide',
|
|
38
|
+
resourceKind: 'link',
|
|
39
|
+
url: 'https://example.com',
|
|
40
|
+
tags,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
describe('ResourceCard', () => {
|
|
44
|
+
let root;
|
|
45
|
+
let container;
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
48
|
+
navigate.mockClear();
|
|
49
|
+
});
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
act(() => {
|
|
52
|
+
root?.unmount();
|
|
53
|
+
});
|
|
54
|
+
container?.remove();
|
|
55
|
+
root = undefined;
|
|
56
|
+
container = undefined;
|
|
57
|
+
});
|
|
58
|
+
it('navigates to the tag page when a hashtag chip is clicked', async () => {
|
|
59
|
+
container = document.createElement('div');
|
|
60
|
+
document.body.appendChild(container);
|
|
61
|
+
root = createRoot(container);
|
|
62
|
+
await act(async () => {
|
|
63
|
+
root?.render(createElement(ResourceCard, { post: resourcePost(['Juneteenth']) }));
|
|
64
|
+
});
|
|
65
|
+
const chip = [...container.querySelectorAll('button')].find((button) => button.textContent === '#juneteenth');
|
|
66
|
+
expect(chip).toBeTruthy();
|
|
67
|
+
await act(async () => {
|
|
68
|
+
chip?.click();
|
|
69
|
+
});
|
|
70
|
+
expect(navigate).toHaveBeenCalledWith({
|
|
71
|
+
type: 'tags',
|
|
72
|
+
hashtag: 'juneteenth',
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -102,5 +102,5 @@ export const ResourceLibrary = ({ groupId }) => {
|
|
|
102
102
|
})
|
|
103
103
|
: t('resources.library.empty', {
|
|
104
104
|
defaultValue: 'No resources yet.',
|
|
105
|
-
}) })) : library.view === 'list' ? (_jsx("div", { className: "divide-border flex flex-col divide-y", children: library.posts.map((post) => (_jsx("a", { href: hrefOf({ type: 'post', id: post.id }), className: "block", children: _jsx(ResourceCard, { post: post, layout: "list" }) }, post.id))) })) : (_jsx("div", { className: "grid grid-cols-1 gap-4 p-4 sm:grid-cols-2 lg:grid-cols-3", children: library.posts.map((post) => (_jsx("a", { href: hrefOf({ type: 'post', id: post.id }), className: "block", children: _jsx(ResourceCard, { post: post, layout: "card" }) }, post.id))) }))] }));
|
|
105
|
+
}) })) : library.view === 'list' ? (_jsx("div", { className: "divide-border flex flex-col divide-y", children: library.posts.map((post) => (_jsx("a", { href: hrefOf({ type: 'post', id: post.id }), className: "block", children: _jsx(ResourceCard, { post: post, layout: "list", inGroup: !!groupId }) }, post.id))) })) : (_jsx("div", { className: "grid grid-cols-1 gap-4 p-4 sm:grid-cols-2 lg:grid-cols-3", children: library.posts.map((post) => (_jsx("a", { href: hrefOf({ type: 'post', id: post.id }), className: "block", children: _jsx(ResourceCard, { post: post, layout: "card", inGroup: !!groupId }) }, post.id))) }))] }));
|
|
106
106
|
};
|
|
@@ -88,6 +88,7 @@ export declare const useEventRsvp: ({ post, recurrenceId, lockToOccurrence, onSu
|
|
|
88
88
|
} | undefined;
|
|
89
89
|
canRsvp: boolean;
|
|
90
90
|
rsvpClosed: boolean;
|
|
91
|
+
hideRsvpButton: boolean;
|
|
91
92
|
recurring: boolean;
|
|
92
93
|
defaultId: string | undefined;
|
|
93
94
|
occurrences: ExpandedOccurrence[];
|