@openpeepshq/react 0.6.0 → 0.6.2
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/event/FullEvent.js +3 -1
- 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/event/FullEvent.tsx +11 -3
- 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
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { LayoutList, LayoutGrid, BookmarkIcon, ChevronDown, ChevronRight, } from 'lucide-react';
|
|
3
|
+
import { RESOURCE_KINDS } from '@openpeepshq/common/lib';
|
|
4
|
+
import { Button, Input, LoadingSpinner } from '@openpeepshq/react-ui';
|
|
5
|
+
import { useMemo, useState } from 'react';
|
|
6
|
+
import { useT } from '../../i18n/index.js';
|
|
7
|
+
import { useHrefOf } from '../../contexts/router/index.js';
|
|
8
|
+
import { useResourceLibrary } from '../../hooks/index.js';
|
|
9
|
+
import { ResourceCard } from './ResourceCard.js';
|
|
10
|
+
const COLLECTION_LIMIT = 5;
|
|
11
|
+
const Tree = ({ nodes, selected, onSelect, counts, expanded, onToggle, }) => (_jsx("ul", { className: "space-y-1", children: nodes.map((node) => {
|
|
12
|
+
const nodeKey = node.path.join('/');
|
|
13
|
+
const nodeCount = counts.get(nodeKey) ?? 0;
|
|
14
|
+
const isExpanded = expanded.has(nodeKey);
|
|
15
|
+
const isSelected = selected.join('/') === nodeKey;
|
|
16
|
+
const hasChildren = node.children.length > 0;
|
|
17
|
+
return (_jsxs("li", { children: [_jsxs("div", { className: "flex items-center gap-1", children: [_jsx("button", { type: "button", className: `text-muted-foreground hover:text-foreground ${hasChildren ? '' : 'invisible'}`, onClick: hasChildren ? () => onToggle(nodeKey) : undefined, children: _jsx(ChevronRight, { className: `size-3 transition-transform ${isExpanded ? 'rotate-90' : ''}` }) }), _jsxs("button", { type: "button", className: `text-sm ${isSelected
|
|
18
|
+
? 'font-semibold'
|
|
19
|
+
: 'text-muted-foreground hover:text-foreground'}`, onClick: () => onSelect(node.path), children: [node.name, nodeCount > 0 ? (_jsxs("span", { className: "text-xs opacity-60", children: ["(", nodeCount, ")"] })) : null] })] }), hasChildren && isExpanded ? (_jsx("div", { className: "ml-4", children: _jsx(Tree, { nodes: node.children, selected: selected, onSelect: onSelect, counts: counts, expanded: expanded, onToggle: onToggle }) })) : null] }, nodeKey));
|
|
20
|
+
}) }));
|
|
21
|
+
export const ResourceLibrary = ({ groupId }) => {
|
|
22
|
+
const t = useT();
|
|
23
|
+
const hrefOf = useHrefOf();
|
|
24
|
+
const library = useResourceLibrary(groupId);
|
|
25
|
+
const [expanded, setExpanded] = useState(new Set());
|
|
26
|
+
const toggleNode = (nodeKey) => {
|
|
27
|
+
setExpanded((prev) => {
|
|
28
|
+
const next = new Set(prev);
|
|
29
|
+
if (next.has(nodeKey))
|
|
30
|
+
next.delete(nodeKey);
|
|
31
|
+
else
|
|
32
|
+
next.add(nodeKey);
|
|
33
|
+
return next;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const collectionCounts = useMemo(() => {
|
|
37
|
+
const counts = new Map();
|
|
38
|
+
let rootCount = 0;
|
|
39
|
+
for (const post of library.posts) {
|
|
40
|
+
if (post.data?.type !== 'resource')
|
|
41
|
+
continue;
|
|
42
|
+
const path = post.data.categoryPath;
|
|
43
|
+
if (!path?.length)
|
|
44
|
+
continue;
|
|
45
|
+
rootCount++;
|
|
46
|
+
for (let i = 1; i <= path.length; i++) {
|
|
47
|
+
const key = path.slice(0, i).join('/');
|
|
48
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
counts.set('', rootCount);
|
|
52
|
+
return counts;
|
|
53
|
+
}, [library.posts]);
|
|
54
|
+
const treeNodes = useMemo(() => {
|
|
55
|
+
if (library.tree.length === 0)
|
|
56
|
+
return [];
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
name: t('resources.library.allFolders', {
|
|
60
|
+
defaultValue: 'All folders',
|
|
61
|
+
}),
|
|
62
|
+
path: [],
|
|
63
|
+
children: library.tree,
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
}, [library.tree, t]);
|
|
67
|
+
const sortedTags = useMemo(() => library.tags
|
|
68
|
+
.filter((entry) => library.selectedTags.includes(entry.name))
|
|
69
|
+
.concat(library.tags.filter((entry) => !library.selectedTags.includes(entry.name))), [library.tags, library.selectedTags]);
|
|
70
|
+
const visibleTags = library.tagsOpen
|
|
71
|
+
? sortedTags
|
|
72
|
+
: sortedTags.slice(0, COLLECTION_LIMIT);
|
|
73
|
+
const hasMoreTags = sortedTags.length > COLLECTION_LIMIT;
|
|
74
|
+
return (_jsxs("div", { children: [_jsxs("div", { className: "flex flex-col gap-3 p-4", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(Input, { className: "flex-1", value: library.search, onChange: (event) => library.setSearch(event.target.value), placeholder: t('resources.library.search', {
|
|
75
|
+
defaultValue: 'Search resources',
|
|
76
|
+
}), "data-testid": "resources-search" }), _jsxs("div", { className: "ml-auto flex gap-1", children: [_jsx(Button, { compact: true, size: "sm", variant: library.view === 'list' ? 'default' : 'outline', action: () => library.setView('list'), "data-testid": "resources-view-list", title: t('resources.library.viewList', {
|
|
77
|
+
defaultValue: 'List view',
|
|
78
|
+
}), children: _jsx(LayoutList, { className: "size-4" }) }), _jsx(Button, { compact: true, size: "sm", variant: library.view === 'cards' ? 'default' : 'outline', action: () => library.setView('cards'), "data-testid": "resources-view-cards", title: t('resources.library.viewCards', {
|
|
79
|
+
defaultValue: 'Cards view',
|
|
80
|
+
}), children: _jsx(LayoutGrid, { className: "size-4" }) }), _jsxs(Button, { compact: true, size: "sm", variant: library.saved ? 'default' : 'outline', action: () => library.setSaved(!library.saved), "data-testid": "resources-saved", title: t('resources.library.saved', { defaultValue: 'Saved' }), children: [_jsx(BookmarkIcon, { className: "size-4" }), t('resources.library.saved', { defaultValue: 'Saved' })] })] })] }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { compact: true, variant: library.kind === 'all' ? 'default' : 'outline', action: () => library.setKind('all'), children: t('resources.library.allKinds', { defaultValue: 'All' }) }), RESOURCE_KINDS.map((kind) => (_jsx(Button, { compact: true, variant: library.kind === kind ? 'default' : 'outline', action: () => library.setKind(kind), children: t(`resources.kinds.${kind}`, { defaultValue: kind }) }, kind)))] }), _jsxs("div", { children: [_jsxs("div", { className: "flex items-center gap-2 text-sm", children: [_jsx("button", { type: "button", className: "text-muted-foreground hover:text-foreground", onClick: () => library.setPathPrefix([]), children: "All" }), library.pathPrefix.length > 0 ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-muted-foreground", children: "/" }), _jsx("span", { className: "text-muted-foreground", children: library.pathPrefix.join(' / ') })] })) : null, _jsx("button", { type: "button", className: "text-muted-foreground hover:text-foreground ml-auto", onClick: () => library.setHierarchy(!library.hierarchy), children: library.hierarchy ? (_jsx(ChevronDown, { className: "size-4" })) : (_jsx(ChevronRight, { className: "size-4" })) })] }), library.hierarchy ? (_jsx("div", { className: "border-border mt-2 rounded-md border p-3", children: treeNodes.length ? (_jsx(Tree, { nodes: treeNodes, selected: library.pathPrefix, onSelect: library.setPathPrefix, counts: collectionCounts, expanded: expanded, onToggle: toggleNode })) : null })) : null] }), library.tags.length ? (_jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("div", { className: "flex flex-wrap gap-1", children: visibleTags.map((entry) => {
|
|
81
|
+
const isSelected = library.selectedTags.includes(entry.name);
|
|
82
|
+
return (_jsxs("button", { type: "button", className: `rounded-full px-2 py-0.5 text-xs ${isSelected
|
|
83
|
+
? 'bg-primary text-primary-foreground'
|
|
84
|
+
: 'bg-muted text-muted-foreground'}`, onClick: () => library.toggleTag(entry.name), children: ["#", entry.name, " ", entry.count] }, entry.name));
|
|
85
|
+
}) }), hasMoreTags ? (_jsx("button", { type: "button", className: "bg-muted text-muted-foreground rounded-full px-2 py-0.5 text-xs", onClick: () => library.setTagsOpen(!library.tagsOpen), children: library.tagsOpen
|
|
86
|
+
? t('resources.library.hideTags', {
|
|
87
|
+
defaultValue: 'Hide',
|
|
88
|
+
})
|
|
89
|
+
: t('resources.library.showHiddenTags', {
|
|
90
|
+
defaultValue: '+ {{count}}',
|
|
91
|
+
count: sortedTags.length - COLLECTION_LIMIT,
|
|
92
|
+
}) })) : null] })) : null, library.posts.length > 0 ? (_jsx("p", { className: "text-muted-foreground text-xs", children: t('resources.library.resourceCount', {
|
|
93
|
+
defaultValue: 'Showing {{count}} resources',
|
|
94
|
+
count: library.posts.length,
|
|
95
|
+
}) })) : null] }), library.query.isLoading ? (_jsx("div", { className: "flex h-32 items-center justify-center", children: _jsx(LoadingSpinner, {}) })) : library.posts.length === 0 ? (_jsx("p", { className: "text-muted-foreground p-8 text-center text-sm", children: library.activeFilterCount > 0
|
|
96
|
+
? t('resources.library.noResults', {
|
|
97
|
+
defaultValue: 'No resources match your current filters.',
|
|
98
|
+
})
|
|
99
|
+
: library.pathPrefix.length
|
|
100
|
+
? t('resources.library.emptyCollection', {
|
|
101
|
+
defaultValue: 'This collection has no resources yet.',
|
|
102
|
+
})
|
|
103
|
+
: t('resources.library.empty', {
|
|
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))) }))] }));
|
|
106
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ResourceLibrary } from './ResourceLibrary';
|
|
2
|
+
export type { ResourceLibraryProps } from './ResourceLibrary';
|
|
3
|
+
export { ResourceCard } from './ResourceCard';
|
|
4
|
+
export type { ResourceCardProps } from './ResourceCard';
|
|
5
|
+
export { CategoryPathPicker } from './CategoryPathPicker';
|
|
6
|
+
export type { CategoryPathPickerProps } from './CategoryPathPicker';
|