@openpeepshq/react 0.10.0 → 0.11.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/RelationCapabilitiesEditor.js +3 -3
- package/dist/components/RoleCapabilityMatrix.js +2 -2
- package/dist/components/accounts/SignUpLoginModal.js +1 -1
- package/dist/components/configuration/ConfigurationList.js +2 -2
- package/dist/components/conversations/ConversationMessageBubble.js +8 -1
- package/dist/components/conversations/CreateNewConversation.js +34 -17
- package/dist/components/form/ImageEditModal.js +2 -2
- package/dist/components/groups/ChangeGroupRolesModal.js +1 -1
- package/dist/components/groups/ConfirmGroupExitModal.js +1 -1
- package/dist/components/groups/ConfirmMemberRemovalModal.js +1 -1
- package/dist/components/groups/DeleteGroupModal.js +1 -1
- package/dist/components/groups/GroupForm.js +2 -2
- package/dist/components/groups/GroupNotificationSettingsModal.js +2 -2
- package/dist/components/jams/JamCallParticipant.js +4 -3
- package/dist/components/jams/JamGuestForm.js +1 -1
- package/dist/components/jams/jamEventActions.d.ts +10 -0
- package/dist/components/jams/jamEventActions.js +13 -0
- package/dist/components/navigation/ContentHeader.js +1 -1
- package/dist/components/navigation/FooterMobile.js +1 -1
- package/dist/components/navigation/SideBar.js +1 -1
- package/dist/components/post/FullPostLayout.js +1 -1
- package/dist/components/post/index.d.ts +1 -0
- package/dist/components/post/index.js +1 -0
- package/dist/components/post/pieces/EventRsvpList.js +1 -1
- package/dist/components/post/pieces/EventRsvpScopeDialog.js +2 -2
- package/dist/components/post/pieces/EventWaitlistJoinDialog.js +1 -1
- package/dist/components/post/pieces/GalleryModal.js +1 -1
- package/dist/components/post/pieces/modals/DeletePostModal.js +2 -2
- package/dist/components/post/post-form/ComposeAttachments.d.ts +2 -0
- package/dist/components/post/post-form/ComposeAttachments.js +8 -0
- package/dist/components/post/post-form/DescriptionEditModal.js +1 -1
- package/dist/components/post/post-form/EditPostModal.js +2 -2
- package/dist/components/post/post-form/EventForm.js +4 -26
- package/dist/components/post/post-form/PostAudienceSelector.js +2 -2
- package/dist/components/post/post-form/ReplyModal.js +1 -1
- package/dist/components/post/types/event/FullEvent.js +3 -3
- package/dist/components/post/types/resource/FullResource.js +2 -1
- package/dist/components/preview-link/RemotePreviewLink.js +32 -4
- package/dist/components/preview-link/RemotePreviewLink.test.d.ts +1 -0
- package/dist/components/preview-link/RemotePreviewLink.test.js +118 -0
- package/dist/components/profile/ProfileActivitySummary.js +4 -4
- package/dist/components/profile/ProfileBadge.js +1 -1
- package/dist/components/profile/ProfilePageAction.js +1 -1
- package/dist/components/profile/ProfilePostsAndReplies.js +1 -1
- package/dist/components/profile/ProfileSelector.js +1 -1
- package/dist/components/profile/ReportProfileOrPostModal.js +4 -2
- package/dist/components/resources/CategoryPathPicker.js +1 -1
- package/dist/components/resources/ResourceCard.js +5 -3
- package/dist/components/resources/ResourceLibrary.js +61 -8
- package/dist/components/resources/ResourceLibrary.test.d.ts +1 -0
- package/dist/components/resources/ResourceLibrary.test.js +122 -0
- package/dist/components/server-data/context.d.ts +24 -16
- package/dist/contexts/openpeeps/hooks/admin.d.ts +2 -2
- package/dist/contexts/openpeeps/hooks/auth.d.ts +1 -1
- package/dist/contexts/router/index.d.ts +8 -0
- package/dist/contexts/router/index.js +27 -2
- package/dist/hooks/conversations/dmMessage.d.ts +15 -0
- package/dist/hooks/conversations/dmMessage.js +12 -0
- package/dist/hooks/conversations/useCreateConversation.d.ts +40 -0
- package/dist/hooks/conversations/useCreateConversation.js +6 -0
- package/dist/hooks/events/useEventForm.d.ts +3 -0
- package/dist/hooks/events/useEventForm.js +31 -2
- package/dist/hooks/events/useEventForm.test.d.ts +1 -0
- package/dist/hooks/events/useEventForm.test.js +107 -0
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/index.js +3 -1
- package/dist/hooks/posts/useFeedPostActions.js +4 -15
- package/dist/hooks/posts/usePostReactionToggle.d.ts +14 -0
- package/dist/hooks/posts/usePostReactionToggle.js +46 -0
- package/dist/hooks/resources/useResourceLibrary.d.ts +8 -1
- package/dist/hooks/resources/useResourceLibrary.js +5 -5
- package/dist/hooks/settings/useAccessTokens.d.ts +3 -3
- package/dist/hooks/settings/useAccessTokens.js +1 -0
- package/dist/hooks/settings/useNotificationPreferences.d.ts +1 -0
- package/dist/hooks/settings/useNotificationPreferences.js +7 -2
- package/dist/lib/downloadUrl.d.ts +6 -0
- package/dist/lib/downloadUrl.js +6 -0
- package/dist/navigation/menuItems.js +4 -4
- package/dist/pages/Explore.js +1 -1
- package/dist/pages/admin/ApiKeys.js +17 -9
- package/dist/pages/admin/ConfigEditor.js +1 -1
- package/dist/pages/admin/ConfigurationCommunityFeed.js +2 -2
- package/dist/pages/admin/ConfigurationCommunityLanguage.js +2 -2
- package/dist/pages/admin/ConfigurationCommunityTimezone.js +2 -2
- package/dist/pages/admin/ConfigurationEmail.js +4 -4
- package/dist/pages/admin/ConfigurationI18n.js +1 -1
- package/dist/pages/admin/ConfigurationSso.js +2 -2
- package/dist/pages/admin/ConfigurationSsoNew.js +1 -1
- package/dist/pages/admin/Dashboard.js +1 -1
- package/dist/pages/admin/Db.js +4 -4
- package/dist/pages/admin/DiagnosticsEmail.js +3 -3
- package/dist/pages/admin/DiagnosticsJob.js +2 -2
- package/dist/pages/admin/DiagnosticsLivekit.js +1 -1
- package/dist/pages/admin/DiagnosticsLogs.js +2 -2
- package/dist/pages/admin/DiagnosticsPerformance.js +1 -1
- package/dist/pages/admin/GroupMembers.js +5 -5
- package/dist/pages/admin/Groups.js +2 -2
- package/dist/pages/admin/Invites.js +3 -3
- package/dist/pages/admin/Media.js +2 -2
- package/dist/pages/admin/MemberDetail.js +7 -7
- package/dist/pages/admin/Members.js +2 -2
- package/dist/pages/admin/analytics/AnalyticsLayout.js +3 -1
- package/dist/pages/admin/analytics/Content.js +1 -1
- package/dist/pages/admin/analytics/Engagement.js +1 -1
- package/dist/pages/admin/analytics/Groups.js +1 -1
- package/dist/pages/admin/analytics/ReportSettings.js +1 -1
- package/dist/pages/admin/community/CommunityAccess.js +1 -1
- package/dist/pages/admin/community/CommunityFavicons.js +1 -1
- package/dist/pages/admin/community/CommunityForbiddenUsernames.js +2 -2
- package/dist/pages/admin/community/CommunityInfo.js +1 -1
- package/dist/pages/admin/community/CommunityLinks.js +1 -1
- package/dist/pages/admin/community/CommunityMarkdownPage.js +1 -1
- package/dist/pages/admin/community/CommunityProfileFields.js +2 -2
- package/dist/pages/admin/community/CommunityRoles.js +7 -7
- package/dist/pages/admin/community/CommunityTheme.js +3 -2
- package/dist/pages/admin/community/ThemeColorPreview.d.ts +8 -0
- package/dist/pages/admin/community/ThemeColorPreview.js +46 -0
- package/dist/pages/admin/community/ThemeColorPreview.test.d.ts +1 -0
- package/dist/pages/admin/community/ThemeColorPreview.test.js +49 -0
- package/dist/pages/admin/components/AdminGroupCard.js +1 -1
- package/dist/pages/admin/components/EditInviteLinkModal.js +1 -1
- package/dist/pages/admin/components/InviteWithEmailModal.js +2 -2
- package/dist/pages/admin/components/InviteWithLinkModal.js +3 -3
- package/dist/pages/admin/components/ProfileRowActions.js +4 -4
- package/dist/pages/admin/components/RestoreBackupModal.js +2 -2
- package/dist/pages/admin/components/RestoreTestBackupModal.js +1 -1
- package/dist/pages/auth/Login.js +1 -1
- package/dist/pages/auth/Register.js +3 -3
- package/dist/pages/auth/RequestResetPassword.js +2 -2
- package/dist/pages/conversations/Info.js +1 -1
- package/dist/pages/conversations/Show.js +45 -15
- package/dist/pages/events/Index.js +1 -1
- package/dist/pages/feeds/Bookmarks.js +1 -1
- package/dist/pages/groups/EditInfo.js +1 -1
- package/dist/pages/groups/EditRoles.js +1 -1
- package/dist/pages/groups/Index.js +1 -1
- package/dist/pages/groups/Members.js +2 -2
- package/dist/pages/groups/New.js +1 -1
- package/dist/pages/groups/Show.js +2 -2
- package/dist/pages/settings/AccessTokens.js +4 -4
- package/dist/pages/settings/Account.js +1 -1
- package/dist/pages/settings/Feed.js +1 -1
- package/dist/pages/settings/Language.js +1 -1
- package/dist/pages/settings/NotificationPreferences.js +7 -3
- package/dist/pages/settings/NotificationPreferences.test.d.ts +1 -0
- package/dist/pages/settings/NotificationPreferences.test.js +119 -0
- package/dist/pages/settings/PublicProfile.js +3 -3
- package/dist/pages/settings/PushEnabledDevices.js +1 -1
- package/dist/pages/settings/Theme.js +1 -1
- package/dist/pages/settings/Timezone.js +1 -1
- package/dist/react-native.d.ts +1 -1
- package/dist/react-native.js +1 -1
- package/package.json +9 -9
- package/src/components/RelationCapabilitiesEditor.tsx +3 -3
- package/src/components/RoleCapabilityMatrix.tsx +2 -2
- package/src/components/accounts/SignUpLoginModal.tsx +1 -1
- package/src/components/configuration/ConfigurationList.tsx +2 -2
- package/src/components/conversations/ConversationMessageBubble.tsx +24 -0
- package/src/components/conversations/CreateNewConversation.tsx +114 -78
- package/src/components/form/ImageEditModal.tsx +2 -2
- package/src/components/groups/ChangeGroupRolesModal.tsx +1 -1
- package/src/components/groups/ConfirmGroupExitModal.tsx +1 -1
- package/src/components/groups/ConfirmMemberRemovalModal.tsx +2 -2
- package/src/components/groups/DeleteGroupModal.tsx +2 -2
- package/src/components/groups/GroupForm.tsx +2 -2
- package/src/components/groups/GroupNotificationSettingsModal.tsx +2 -2
- package/src/components/jams/JamCallParticipant.tsx +4 -3
- package/src/components/jams/JamGuestForm.tsx +1 -1
- package/src/components/jams/jamEventActions.ts +21 -0
- package/src/components/navigation/ContentHeader.tsx +3 -3
- package/src/components/navigation/FooterMobile.tsx +1 -1
- package/src/components/navigation/SideBar.tsx +3 -3
- package/src/components/post/FullPostLayout.tsx +1 -1
- package/src/components/post/index.ts +1 -0
- package/src/components/post/pieces/EventRsvpList.tsx +1 -1
- package/src/components/post/pieces/EventRsvpScopeDialog.tsx +2 -2
- package/src/components/post/pieces/EventWaitlistJoinDialog.tsx +1 -1
- package/src/components/post/pieces/GalleryModal.tsx +1 -1
- package/src/components/post/pieces/modals/DeletePostModal.tsx +2 -2
- package/src/components/post/post-form/ComposeAttachments.tsx +10 -0
- package/src/components/post/post-form/DescriptionEditModal.tsx +1 -1
- package/src/components/post/post-form/EditPostModal.tsx +2 -2
- package/src/components/post/post-form/EventForm.tsx +10 -28
- package/src/components/post/post-form/PostAudienceSelector.tsx +2 -2
- package/src/components/post/post-form/ReplyModal.tsx +1 -1
- package/src/components/post/types/event/FullEvent.tsx +3 -3
- package/src/components/post/types/resource/FullResource.tsx +2 -1
- package/src/components/preview-link/RemotePreviewLink.tsx +92 -25
- package/src/components/profile/ProfileActivitySummary.tsx +4 -4
- package/src/components/profile/ProfileBadge.tsx +1 -1
- package/src/components/profile/ProfilePageAction.tsx +1 -1
- package/src/components/profile/ProfilePostsAndReplies.tsx +2 -2
- package/src/components/profile/ProfileSelector.tsx +1 -1
- package/src/components/profile/ReportProfileOrPostModal.tsx +4 -2
- package/src/components/resources/CategoryPathPicker.tsx +1 -1
- package/src/components/resources/ResourceCard.tsx +5 -3
- package/src/components/resources/ResourceLibrary.tsx +79 -4
- package/src/contexts/router/index.tsx +40 -1
- package/src/hooks/conversations/dmMessage.ts +26 -0
- package/src/hooks/conversations/useCreateConversation.ts +7 -0
- package/src/hooks/events/useEventForm.ts +32 -1
- package/src/hooks/index.ts +10 -1
- package/src/hooks/posts/useFeedPostActions.ts +4 -18
- package/src/hooks/posts/usePostReactionToggle.ts +60 -0
- package/src/hooks/resources/useResourceLibrary.ts +20 -5
- package/src/hooks/settings/useAccessTokens.ts +1 -0
- package/src/hooks/settings/useNotificationPreferences.ts +12 -1
- package/src/lib/downloadUrl.ts +7 -0
- package/src/navigation/menuItems.ts +4 -4
- package/src/pages/Explore.tsx +4 -4
- package/src/pages/admin/ApiKeys.tsx +24 -13
- package/src/pages/admin/ConfigEditor.tsx +1 -1
- package/src/pages/admin/ConfigurationCommunityFeed.tsx +2 -2
- package/src/pages/admin/ConfigurationCommunityLanguage.tsx +2 -2
- package/src/pages/admin/ConfigurationCommunityTimezone.tsx +2 -2
- package/src/pages/admin/ConfigurationEmail.tsx +4 -4
- package/src/pages/admin/ConfigurationI18n.tsx +1 -1
- package/src/pages/admin/ConfigurationSso.tsx +3 -2
- package/src/pages/admin/ConfigurationSsoNew.tsx +1 -1
- package/src/pages/admin/Dashboard.tsx +1 -1
- package/src/pages/admin/Db.tsx +6 -6
- package/src/pages/admin/DiagnosticsEmail.tsx +5 -5
- package/src/pages/admin/DiagnosticsJob.tsx +2 -2
- package/src/pages/admin/DiagnosticsLivekit.tsx +3 -3
- package/src/pages/admin/DiagnosticsLogs.tsx +4 -4
- package/src/pages/admin/DiagnosticsPerformance.tsx +1 -1
- package/src/pages/admin/GroupMembers.tsx +6 -6
- package/src/pages/admin/Groups.tsx +2 -2
- package/src/pages/admin/Invites.tsx +4 -4
- package/src/pages/admin/Media.tsx +2 -2
- package/src/pages/admin/MemberDetail.tsx +7 -7
- package/src/pages/admin/Members.tsx +2 -2
- package/src/pages/admin/analytics/AnalyticsLayout.tsx +5 -1
- package/src/pages/admin/analytics/Content.tsx +1 -1
- package/src/pages/admin/analytics/Engagement.tsx +1 -1
- package/src/pages/admin/analytics/Groups.tsx +1 -1
- package/src/pages/admin/analytics/ReportSettings.tsx +1 -1
- package/src/pages/admin/community/CommunityAccess.tsx +1 -1
- package/src/pages/admin/community/CommunityFavicons.tsx +1 -1
- package/src/pages/admin/community/CommunityForbiddenUsernames.tsx +2 -2
- package/src/pages/admin/community/CommunityInfo.tsx +1 -1
- package/src/pages/admin/community/CommunityLinks.tsx +1 -1
- package/src/pages/admin/community/CommunityMarkdownPage.tsx +1 -1
- package/src/pages/admin/community/CommunityProfileFields.tsx +5 -5
- package/src/pages/admin/community/CommunityRoles.tsx +9 -9
- package/src/pages/admin/community/CommunityTheme.tsx +26 -23
- package/src/pages/admin/community/ThemeColorPreview.tsx +141 -0
- package/src/pages/admin/components/AdminGroupCard.tsx +2 -2
- package/src/pages/admin/components/EditInviteLinkModal.tsx +2 -2
- package/src/pages/admin/components/InviteWithEmailModal.tsx +2 -2
- package/src/pages/admin/components/InviteWithLinkModal.tsx +3 -3
- package/src/pages/admin/components/ProfileRowActions.tsx +6 -6
- package/src/pages/admin/components/RestoreBackupModal.tsx +2 -2
- package/src/pages/admin/components/RestoreTestBackupModal.tsx +1 -1
- package/src/pages/auth/Login.tsx +1 -1
- package/src/pages/auth/Register.tsx +3 -3
- package/src/pages/auth/RequestResetPassword.tsx +2 -2
- package/src/pages/conversations/Info.tsx +1 -1
- package/src/pages/conversations/Show.tsx +94 -33
- package/src/pages/events/Index.tsx +1 -1
- package/src/pages/feeds/Bookmarks.tsx +3 -1
- package/src/pages/groups/EditInfo.tsx +1 -1
- package/src/pages/groups/EditRoles.tsx +1 -1
- package/src/pages/groups/Index.tsx +1 -1
- package/src/pages/groups/Members.tsx +2 -2
- package/src/pages/groups/New.tsx +1 -1
- package/src/pages/groups/Show.tsx +4 -4
- package/src/pages/settings/AccessTokens.tsx +4 -4
- package/src/pages/settings/Account.tsx +1 -1
- package/src/pages/settings/Feed.tsx +1 -1
- package/src/pages/settings/Language.tsx +1 -1
- package/src/pages/settings/NotificationPreferences.tsx +38 -12
- package/src/pages/settings/PublicProfile.tsx +3 -3
- package/src/pages/settings/PushEnabledDevices.tsx +3 -6
- package/src/pages/settings/Theme.tsx +1 -1
- package/src/pages/settings/Timezone.tsx +1 -1
- package/src/react-native.ts +1 -0
|
@@ -49,7 +49,7 @@ export function ProfilePostsAndReplies({
|
|
|
49
49
|
className={`flex-1 px-4 py-3 text-sm font-medium ${activeTab === 'posts' ? 'border-primary border-b-2' : 'text-muted-foreground'}`}
|
|
50
50
|
onClick={() => setTab('posts')}
|
|
51
51
|
>
|
|
52
|
-
{t('
|
|
52
|
+
{t('common.entities.posts', { defaultValue: 'Posts' })}
|
|
53
53
|
</button>
|
|
54
54
|
{isCurrentProfile ? (
|
|
55
55
|
<button
|
|
@@ -66,7 +66,7 @@ export function ProfilePostsAndReplies({
|
|
|
66
66
|
className={`flex-1 px-4 py-3 text-sm font-medium ${activeTab === 'groups' ? 'border-primary border-b-2' : 'text-muted-foreground'}`}
|
|
67
67
|
onClick={() => setTab('groups')}
|
|
68
68
|
>
|
|
69
|
-
{t('
|
|
69
|
+
{t('common.entities.groups', { defaultValue: 'Groups' })}
|
|
70
70
|
</button>
|
|
71
71
|
</nav>
|
|
72
72
|
|
|
@@ -194,7 +194,7 @@ export const ProfileSelector = ({
|
|
|
194
194
|
|
|
195
195
|
{mode === 'multiple' ? (
|
|
196
196
|
<DialogActions
|
|
197
|
-
cancelLabel={t('common.cancel', { defaultValue: 'Cancel' })}
|
|
197
|
+
cancelLabel={t('common.actions.cancel', { defaultValue: 'Cancel' })}
|
|
198
198
|
onCancel={() => onOpenChange(false)}
|
|
199
199
|
actionLabel={t('profile.selector.confirm', { defaultValue: 'OK' })}
|
|
200
200
|
onAction={confirmMultiple}
|
|
@@ -129,7 +129,9 @@ export function ReportProfileOrPostModal({
|
|
|
129
129
|
})}
|
|
130
130
|
/>
|
|
131
131
|
<DialogActions
|
|
132
|
-
cancelLabel={t('common.cancel', {
|
|
132
|
+
cancelLabel={t('common.actions.cancel', {
|
|
133
|
+
defaultValue: 'Cancel',
|
|
134
|
+
})}
|
|
133
135
|
onCancel={onClose}
|
|
134
136
|
actionLabel={t(`reports.create.${reportType}.continue`, {
|
|
135
137
|
defaultValue: 'Continue',
|
|
@@ -156,7 +158,7 @@ export function ReportProfileOrPostModal({
|
|
|
156
158
|
</p>
|
|
157
159
|
) : null}
|
|
158
160
|
<DialogActions
|
|
159
|
-
cancelLabel={t('
|
|
161
|
+
cancelLabel={t('common.actions.back', { defaultValue: 'Back' })}
|
|
160
162
|
onCancel={() => setStep(1)}
|
|
161
163
|
actionLabel={t('reports.create.sendReport', {
|
|
162
164
|
defaultValue: 'Send report',
|
|
@@ -82,7 +82,7 @@ export const CategoryPathPicker = ({
|
|
|
82
82
|
setLevel('');
|
|
83
83
|
}}
|
|
84
84
|
>
|
|
85
|
-
{t('
|
|
85
|
+
{t('common.actions.add', { defaultValue: 'Add' })}
|
|
86
86
|
</Button>
|
|
87
87
|
{path.length ? (
|
|
88
88
|
<Button variant="ghost" action={() => onChange([])}>
|
|
@@ -26,6 +26,7 @@ import { useOpenpeeps } from '../../contexts/openpeeps';
|
|
|
26
26
|
import { useCurrentProfile } from '../layout/IdentityContext';
|
|
27
27
|
import { VideoPlayOverlay } from '../post/VideoPlayOverlay';
|
|
28
28
|
import { TruncatedMarkdown } from '../post/TruncatedMarkdown';
|
|
29
|
+
import { asDownloadUrl } from '../../lib/downloadUrl';
|
|
29
30
|
|
|
30
31
|
export interface ResourceCardProps {
|
|
31
32
|
post: PublicPost;
|
|
@@ -107,7 +108,7 @@ const ResourceSaveButton = ({
|
|
|
107
108
|
title={
|
|
108
109
|
isBookmarked
|
|
109
110
|
? t('resources.actions.saved', { defaultValue: 'Saved' })
|
|
110
|
-
: t('
|
|
111
|
+
: t('common.actions.save', { defaultValue: 'Save' })
|
|
111
112
|
}
|
|
112
113
|
>
|
|
113
114
|
{isBookmarked ? (
|
|
@@ -272,10 +273,11 @@ export const ResourceCard = ({
|
|
|
272
273
|
|
|
273
274
|
if (!resource) return null;
|
|
274
275
|
|
|
275
|
-
const
|
|
276
|
+
const fileUrl =
|
|
276
277
|
resource.resourceKind === 'file'
|
|
277
278
|
? attachments.find((att) => attachmentMediaKind(att) === 'file')?.url
|
|
278
|
-
:
|
|
279
|
+
: undefined;
|
|
280
|
+
const downloadUrl = fileUrl ? asDownloadUrl(fileUrl) : null;
|
|
279
281
|
|
|
280
282
|
const renderSaveButton = (className: string) =>
|
|
281
283
|
staticRender ? null : (
|
|
@@ -8,10 +8,13 @@ import {
|
|
|
8
8
|
import type { ResourceKind } from '@openpeepshq/common/types';
|
|
9
9
|
import { RESOURCE_KINDS } from '@openpeepshq/common/lib';
|
|
10
10
|
import { Button, Input, LoadingSpinner } from '@openpeepshq/react-ui';
|
|
11
|
-
import { useMemo, useState } from 'react';
|
|
11
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
12
12
|
import { useT } from '../../i18n';
|
|
13
|
-
import { useHrefOf } from '../../contexts/router';
|
|
14
|
-
import {
|
|
13
|
+
import { useHrefOf, useRouter, useSearchParams } from '../../contexts/router';
|
|
14
|
+
import {
|
|
15
|
+
useResourceLibrary,
|
|
16
|
+
type ResourceLibraryInitialFilters,
|
|
17
|
+
} from '../../hooks';
|
|
15
18
|
import { ResourceCard } from './ResourceCard';
|
|
16
19
|
import type { CategoryNode } from '@openpeepshq/common/lib';
|
|
17
20
|
|
|
@@ -21,6 +24,11 @@ export interface ResourceLibraryProps {
|
|
|
21
24
|
|
|
22
25
|
const COLLECTION_LIMIT = 5;
|
|
23
26
|
|
|
27
|
+
const parseKindFilter = (value: string | null): ResourceKind | 'all' =>
|
|
28
|
+
value && (RESOURCE_KINDS as readonly string[]).includes(value)
|
|
29
|
+
? (value as ResourceKind)
|
|
30
|
+
: 'all';
|
|
31
|
+
|
|
24
32
|
const Tree = ({
|
|
25
33
|
nodes,
|
|
26
34
|
selected,
|
|
@@ -28,6 +36,7 @@ const Tree = ({
|
|
|
28
36
|
counts,
|
|
29
37
|
expanded,
|
|
30
38
|
onToggle,
|
|
39
|
+
t,
|
|
31
40
|
}: {
|
|
32
41
|
nodes: CategoryNode[];
|
|
33
42
|
selected: string[];
|
|
@@ -35,6 +44,7 @@ const Tree = ({
|
|
|
35
44
|
counts: Map<string, number>;
|
|
36
45
|
expanded: Set<string>;
|
|
37
46
|
onToggle: (nodeKey: string) => void;
|
|
47
|
+
t: ReturnType<typeof useT>;
|
|
38
48
|
}) => (
|
|
39
49
|
<ul className="space-y-1">
|
|
40
50
|
{nodes.map((node) => {
|
|
@@ -52,6 +62,15 @@ const Tree = ({
|
|
|
52
62
|
hasChildren ? '' : 'invisible'
|
|
53
63
|
}`}
|
|
54
64
|
onClick={hasChildren ? () => onToggle(nodeKey) : undefined}
|
|
65
|
+
aria-label={
|
|
66
|
+
isExpanded
|
|
67
|
+
? t('resources.library.collapseFolder', {
|
|
68
|
+
defaultValue: 'Collapse folder',
|
|
69
|
+
})
|
|
70
|
+
: t('resources.library.expandFolder', {
|
|
71
|
+
defaultValue: 'Expand folder',
|
|
72
|
+
})
|
|
73
|
+
}
|
|
55
74
|
>
|
|
56
75
|
<ChevronRight
|
|
57
76
|
className={`size-3 transition-transform ${
|
|
@@ -83,6 +102,7 @@ const Tree = ({
|
|
|
83
102
|
counts={counts}
|
|
84
103
|
expanded={expanded}
|
|
85
104
|
onToggle={onToggle}
|
|
105
|
+
t={t}
|
|
86
106
|
/>
|
|
87
107
|
</div>
|
|
88
108
|
) : null}
|
|
@@ -95,7 +115,50 @@ const Tree = ({
|
|
|
95
115
|
export const ResourceLibrary = ({ groupId }: ResourceLibraryProps) => {
|
|
96
116
|
const t = useT();
|
|
97
117
|
const hrefOf = useHrefOf();
|
|
98
|
-
const
|
|
118
|
+
const router = useRouter();
|
|
119
|
+
const searchParams = useSearchParams();
|
|
120
|
+
|
|
121
|
+
// Read the URL once on mount: it seeds the filter state, after which the
|
|
122
|
+
// hook state is the source of truth and the URL a shareable mirror of it.
|
|
123
|
+
const initialFilters = useMemo<ResourceLibraryInitialFilters>(
|
|
124
|
+
() => ({
|
|
125
|
+
kind: parseKindFilter(searchParams.get('kind')),
|
|
126
|
+
tags: searchParams.get('tags')?.split(',').filter(Boolean),
|
|
127
|
+
search: searchParams.get('q') ?? undefined,
|
|
128
|
+
}),
|
|
129
|
+
[],
|
|
130
|
+
);
|
|
131
|
+
const library = useResourceLibrary(groupId, undefined, initialFilters);
|
|
132
|
+
|
|
133
|
+
// Keep a fresh view of the URL so the write-back below can skip no-ops.
|
|
134
|
+
const latestSearch = useRef(searchParams);
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
latestSearch.current = searchParams;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Shareable filters (?kind= &tags=a,b &q=): merged into the existing params
|
|
140
|
+
// so unrelated ones (e.g. ?category=) and the tab hash survive, written
|
|
141
|
+
// with replace so filter changes don't spam the history stack, and
|
|
142
|
+
// debounced so typing a search doesn't re-route on every keystroke.
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
const timer = setTimeout(() => {
|
|
145
|
+
const prev = latestSearch.current;
|
|
146
|
+
const next = new URLSearchParams(prev);
|
|
147
|
+
next.delete('kind');
|
|
148
|
+
next.delete('tags');
|
|
149
|
+
next.delete('q');
|
|
150
|
+
if (library.kind !== 'all') next.set('kind', library.kind);
|
|
151
|
+
if (library.selectedTags.length > 0) {
|
|
152
|
+
next.set('tags', library.selectedTags.join(','));
|
|
153
|
+
}
|
|
154
|
+
const q = library.search.trim();
|
|
155
|
+
if (q) next.set('q', q);
|
|
156
|
+
if (next.toString() === prev.toString()) return;
|
|
157
|
+
router.setSearchParams(next, { replace: true });
|
|
158
|
+
}, 250);
|
|
159
|
+
return () => clearTimeout(timer);
|
|
160
|
+
}, [library.kind, library.selectedTags, library.search, router]);
|
|
161
|
+
|
|
99
162
|
const [expanded, setExpanded] = useState<Set<string>>(new Set());
|
|
100
163
|
|
|
101
164
|
const toggleNode = (nodeKey: string) => {
|
|
@@ -154,6 +217,15 @@ export const ResourceLibrary = ({ groupId }: ResourceLibraryProps) => {
|
|
|
154
217
|
: sortedTags.slice(0, COLLECTION_LIMIT);
|
|
155
218
|
const hasMoreTags = sortedTags.length > COLLECTION_LIMIT;
|
|
156
219
|
|
|
220
|
+
const folderTreeLabel = t(
|
|
221
|
+
library.hierarchy
|
|
222
|
+
? 'resources.library.hideFolderTree'
|
|
223
|
+
: 'resources.library.showFolderTree',
|
|
224
|
+
{
|
|
225
|
+
defaultValue: library.hierarchy ? 'Hide folder tree' : 'Show folder tree',
|
|
226
|
+
},
|
|
227
|
+
);
|
|
228
|
+
|
|
157
229
|
return (
|
|
158
230
|
<div>
|
|
159
231
|
<div className="flex flex-col gap-3 p-4">
|
|
@@ -250,6 +322,8 @@ export const ResourceLibrary = ({ groupId }: ResourceLibraryProps) => {
|
|
|
250
322
|
type="button"
|
|
251
323
|
className="text-muted-foreground hover:text-foreground ml-auto"
|
|
252
324
|
onClick={() => library.setHierarchy(!library.hierarchy)}
|
|
325
|
+
title={folderTreeLabel}
|
|
326
|
+
aria-label={folderTreeLabel}
|
|
253
327
|
>
|
|
254
328
|
{library.hierarchy ? (
|
|
255
329
|
<ChevronDown className="size-4" />
|
|
@@ -268,6 +342,7 @@ export const ResourceLibrary = ({ groupId }: ResourceLibraryProps) => {
|
|
|
268
342
|
counts={collectionCounts}
|
|
269
343
|
expanded={expanded}
|
|
270
344
|
onToggle={toggleNode}
|
|
345
|
+
t={t}
|
|
271
346
|
/>
|
|
272
347
|
) : null}
|
|
273
348
|
</div>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createContext,
|
|
3
|
+
useCallback,
|
|
3
4
|
useContext,
|
|
4
5
|
useEffect,
|
|
5
6
|
useMemo,
|
|
@@ -11,6 +12,15 @@ import type { Navigator, NavTarget } from '../../navigation';
|
|
|
11
12
|
export interface RouterAdapter {
|
|
12
13
|
pathname: string;
|
|
13
14
|
searchParams: URLSearchParams;
|
|
15
|
+
/**
|
|
16
|
+
* Replace the query string, keeping the pathname and hash. `next` is the
|
|
17
|
+
* full new params or a function of the current ones; pass
|
|
18
|
+
* `{ replace: true }` to avoid adding a history entry.
|
|
19
|
+
*/
|
|
20
|
+
setSearchParams: (
|
|
21
|
+
next: URLSearchParams | ((prev: URLSearchParams) => URLSearchParams),
|
|
22
|
+
opts?: { replace?: boolean },
|
|
23
|
+
) => void;
|
|
14
24
|
/** Navigate to an abstract target (preferred) or a raw path string. */
|
|
15
25
|
navigate: (target: NavTarget | string) => void;
|
|
16
26
|
hrefOf: (target: NavTarget) => string;
|
|
@@ -81,10 +91,39 @@ export function useBrowserRouter(navigator: Navigator): RouterAdapter {
|
|
|
81
91
|
return () => window.removeEventListener('popstate', update);
|
|
82
92
|
}, []);
|
|
83
93
|
|
|
94
|
+
const setSearchParams = useCallback<RouterAdapter['setSearchParams']>(
|
|
95
|
+
(next, opts) => {
|
|
96
|
+
if (typeof window === 'undefined') return;
|
|
97
|
+
const prev = new URLSearchParams(window.location.search);
|
|
98
|
+
const resolved = typeof next === 'function' ? next(prev) : next;
|
|
99
|
+
const query = resolved.toString();
|
|
100
|
+
const url = `${window.location.pathname}${query ? `?${query}` : ''}${window.location.hash}`;
|
|
101
|
+
// The URL bar is the source of truth here; skip no-op writes so the
|
|
102
|
+
// state (and any subscribers) only change when the query actually does.
|
|
103
|
+
if (
|
|
104
|
+
url ===
|
|
105
|
+
`${window.location.pathname}${window.location.search}${window.location.hash}`
|
|
106
|
+
) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (opts?.replace) {
|
|
110
|
+
window.history.replaceState(window.history.state, '', url);
|
|
111
|
+
} else {
|
|
112
|
+
window.history.pushState(window.history.state, '', url);
|
|
113
|
+
}
|
|
114
|
+
setState({
|
|
115
|
+
pathname: window.location.pathname,
|
|
116
|
+
searchParams: new URLSearchParams(window.location.search),
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
[],
|
|
120
|
+
);
|
|
121
|
+
|
|
84
122
|
return useMemo<RouterAdapter>(
|
|
85
123
|
() => ({
|
|
86
124
|
pathname: state.pathname,
|
|
87
125
|
searchParams: state.searchParams,
|
|
126
|
+
setSearchParams,
|
|
88
127
|
hrefOf: navigator.hrefOf,
|
|
89
128
|
match: navigator.match,
|
|
90
129
|
navigate: (target) => {
|
|
@@ -102,6 +141,6 @@ export function useBrowserRouter(navigator: Navigator): RouterAdapter {
|
|
|
102
141
|
history.back();
|
|
103
142
|
},
|
|
104
143
|
}),
|
|
105
|
-
[state, navigator],
|
|
144
|
+
[state, navigator, setSearchParams],
|
|
106
145
|
);
|
|
107
146
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MediaAttachmentData } from '@openpeepshq/common/types';
|
|
2
|
+
|
|
3
|
+
/** DM messages are note posts, so their text carries the note budget. */
|
|
4
|
+
export const DM_MESSAGE_MAX_LENGTH = 500;
|
|
5
|
+
/** Client-side cap on attachments per DM message (applied on both platforms). */
|
|
6
|
+
export const DM_MAX_ATTACHMENTS = 4;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Send gate for DM messages: nothing in flight, no pending uploads, within
|
|
10
|
+
* the text budget, and something to send (text or attachments).
|
|
11
|
+
*/
|
|
12
|
+
export const canSendDmMessage = ({
|
|
13
|
+
sending,
|
|
14
|
+
uploadsPending,
|
|
15
|
+
text,
|
|
16
|
+
attachments,
|
|
17
|
+
}: {
|
|
18
|
+
sending: boolean;
|
|
19
|
+
uploadsPending: boolean;
|
|
20
|
+
text: string;
|
|
21
|
+
attachments: MediaAttachmentData[];
|
|
22
|
+
}) =>
|
|
23
|
+
!sending &&
|
|
24
|
+
!uploadsPending &&
|
|
25
|
+
text.length <= DM_MESSAGE_MAX_LENGTH &&
|
|
26
|
+
(text.trim().length > 0 || attachments.length > 0);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import type {
|
|
3
|
+
MediaAttachmentData,
|
|
3
4
|
PostCreationData,
|
|
4
5
|
PublicProfile,
|
|
5
6
|
} from '@openpeepshq/common/types';
|
|
@@ -32,6 +33,7 @@ export const useCreateConversation = ({
|
|
|
32
33
|
const [selectedProfiles, setSelectedProfiles] =
|
|
33
34
|
useState<PublicProfile[]>(initialProfiles);
|
|
34
35
|
const [message, setMessage] = useState(initialMessage);
|
|
36
|
+
const [attachments, setAttachments] = useState<MediaAttachmentData[]>([]);
|
|
35
37
|
const [submitting, setSubmitting] = useState(false);
|
|
36
38
|
const [error, setError] = useState<string | null>(null);
|
|
37
39
|
|
|
@@ -47,9 +49,12 @@ export const useCreateConversation = ({
|
|
|
47
49
|
data: {
|
|
48
50
|
type: 'note',
|
|
49
51
|
content: message.trim(),
|
|
52
|
+
attachments: attachments.length ? attachments : undefined,
|
|
50
53
|
},
|
|
51
54
|
};
|
|
52
55
|
const created = (await createPost(payload)) as { id: string };
|
|
56
|
+
setMessage('');
|
|
57
|
+
setAttachments([]);
|
|
53
58
|
onClose();
|
|
54
59
|
navigate({ type: 'conversation', id: created.id });
|
|
55
60
|
} catch (err) {
|
|
@@ -67,6 +72,8 @@ export const useCreateConversation = ({
|
|
|
67
72
|
setSelectedProfiles,
|
|
68
73
|
message,
|
|
69
74
|
setMessage,
|
|
75
|
+
attachments,
|
|
76
|
+
setAttachments,
|
|
70
77
|
submitting,
|
|
71
78
|
error,
|
|
72
79
|
send,
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
RecurrenceWeekday,
|
|
9
9
|
} from '@openpeepshq/common/types';
|
|
10
10
|
import {
|
|
11
|
+
isEndBeforeStart,
|
|
11
12
|
previewUpcomingOccurrences,
|
|
12
13
|
reinterpretIsoInTimeZone,
|
|
13
14
|
weekdayFromDate,
|
|
@@ -39,16 +40,43 @@ export const useEventForm = (
|
|
|
39
40
|
const eventTimeZone =
|
|
40
41
|
event.timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
41
42
|
const [showEndDate, setShowEndDate] = useState(event.end !== undefined);
|
|
43
|
+
// Transient until the next successful patch; the persisted range itself is
|
|
44
|
+
// derived from start/end, which also covers events saved before the guard.
|
|
45
|
+
const [rejectedTimes, setRejectedTimes] = useState(false);
|
|
42
46
|
|
|
43
47
|
const patchEvent = (patch: Partial<Event>) => {
|
|
44
48
|
let next: Event = { ...event, ...patch };
|
|
45
49
|
if ('maxAttendees' in patch && patch.maxAttendees === undefined) {
|
|
46
50
|
next = withoutEventMaxAttendees(next);
|
|
47
51
|
}
|
|
52
|
+
setRejectedTimes(false);
|
|
48
53
|
onChange({ ...postData, data: next });
|
|
49
54
|
};
|
|
50
55
|
|
|
51
|
-
const
|
|
56
|
+
const changeStart = (start: string | undefined) => {
|
|
57
|
+
if (!start) return;
|
|
58
|
+
// Moving the start past the end keeps the duration by shifting the end.
|
|
59
|
+
if (isEndBeforeStart(start, event.end) && event.start && event.end) {
|
|
60
|
+
const delta = new Date(start).getTime() - new Date(event.start).getTime();
|
|
61
|
+
const end = new Date(new Date(event.end).getTime() + delta);
|
|
62
|
+
patchEvent({ start, end: end.toISOString() });
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
patchEvent({ start });
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const changeEnd = (end: string | undefined) => {
|
|
69
|
+
if (isEndBeforeStart(event.start, end)) {
|
|
70
|
+
setRejectedTimes(true);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
patchEvent({ end });
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const setEvent = (next: Event) => {
|
|
77
|
+
setRejectedTimes(false);
|
|
78
|
+
onChange({ ...postData, data: next });
|
|
79
|
+
};
|
|
52
80
|
|
|
53
81
|
const setAudience = (settings: AudienceSetting) =>
|
|
54
82
|
onChange(applyAudienceSetting(postData, settings, me));
|
|
@@ -176,6 +204,9 @@ export const useEventForm = (
|
|
|
176
204
|
repeatFreq,
|
|
177
205
|
repeatEnd,
|
|
178
206
|
preview,
|
|
207
|
+
endBeforeStart: rejectedTimes || isEndBeforeStart(event.start, event.end),
|
|
208
|
+
changeStart,
|
|
209
|
+
changeEnd,
|
|
179
210
|
patchEvent,
|
|
180
211
|
setEvent,
|
|
181
212
|
setAudience,
|
package/src/hooks/index.ts
CHANGED
|
@@ -2,6 +2,11 @@ export { useJoinGroup } from './groups/useJoinGroup';
|
|
|
2
2
|
export { useGroupNotificationLevel } from './groups/useGroupNotificationLevel';
|
|
3
3
|
export { useCreateConversation } from './conversations/useCreateConversation';
|
|
4
4
|
export type { UseCreateConversationArgs } from './conversations/useCreateConversation';
|
|
5
|
+
export {
|
|
6
|
+
canSendDmMessage,
|
|
7
|
+
DM_MAX_ATTACHMENTS,
|
|
8
|
+
DM_MESSAGE_MAX_LENGTH,
|
|
9
|
+
} from './conversations/dmMessage';
|
|
5
10
|
export { useCanDiagnoseLivekit } from './jams/useCanDiagnoseLivekit';
|
|
6
11
|
export { useLeaveCloseJam } from './jams/useLeaveCloseJam';
|
|
7
12
|
export type { UseLeaveCloseJamArgs } from './jams/useLeaveCloseJam';
|
|
@@ -35,6 +40,7 @@ export {
|
|
|
35
40
|
} from './jams/useJamParticipant';
|
|
36
41
|
export type { UseJamParticipantMuteArgs } from './jams/useJamParticipant';
|
|
37
42
|
export { useFeedPostActions } from './posts/useFeedPostActions';
|
|
43
|
+
export { usePostReactionToggle } from './posts/usePostReactionToggle';
|
|
38
44
|
export {
|
|
39
45
|
feedPostPresentation,
|
|
40
46
|
useFeedPostPresentation,
|
|
@@ -83,7 +89,10 @@ export { useGroupTemplateSelection } from './groups/useGroupTemplateSelection';
|
|
|
83
89
|
export type { UseGroupTemplateSelectionArgs } from './groups/useGroupTemplateSelection';
|
|
84
90
|
export { useNewArticle, useEditArticle } from './posts/useArticleComposer';
|
|
85
91
|
export { useNewResource, useEditResource } from './posts/useResourceComposer';
|
|
86
|
-
export {
|
|
92
|
+
export {
|
|
93
|
+
useResourceLibrary,
|
|
94
|
+
type ResourceLibraryInitialFilters,
|
|
95
|
+
} from './resources/useResourceLibrary';
|
|
87
96
|
export {
|
|
88
97
|
useEventsCalendar,
|
|
89
98
|
eventName as calendarEventName,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '../../components/layout/IdentityContext';
|
|
9
9
|
import { useCapabilities } from '../../components/server-data';
|
|
10
10
|
import { useReplyOpener } from './replyOpener';
|
|
11
|
+
import { usePostReactionToggle } from './usePostReactionToggle';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Non-DOM post footer actions (reply / repost / react) for FeedPost and RN.
|
|
@@ -19,11 +20,8 @@ export const useFeedPostActions = (post: PublicPost) => {
|
|
|
19
20
|
const { openpeepsApi } = useOpenpeeps();
|
|
20
21
|
const openReply = useReplyOpener();
|
|
21
22
|
const repostsQuery = openpeepsApi.useCurrentProfileReposts();
|
|
23
|
+
const { iReacted, canReact, toggleReaction } = usePostReactionToggle(post);
|
|
22
24
|
|
|
23
|
-
const reactToPost = openpeepsApi.reactToPostAction({ id: post.id } as never);
|
|
24
|
-
const retractReaction = openpeepsApi.retractPostReactionAction({
|
|
25
|
-
id: post.id,
|
|
26
|
-
} as never);
|
|
27
25
|
const repostPost = openpeepsApi.repostPostAction({ id: post.id } as never);
|
|
28
26
|
const deletePost = openpeepsApi.deletePostAction({ id: post.id } as never);
|
|
29
27
|
|
|
@@ -36,12 +34,8 @@ export const useFeedPostActions = (post: PublicPost) => {
|
|
|
36
34
|
)?.find((p) => p.repost?.id === post.id),
|
|
37
35
|
[repostsQuery.data, post.id],
|
|
38
36
|
);
|
|
39
|
-
const iReacted = useMemo(
|
|
40
|
-
() => !!post.reactions?.some((r) => r.profile.id === me?.id),
|
|
41
|
-
[post.reactions, me?.id],
|
|
42
|
-
);
|
|
43
37
|
|
|
44
|
-
const { canReply, canRepost
|
|
38
|
+
const { canReply, canRepost } = useMemo(
|
|
45
39
|
() => getPostActionAvailability(authData, post, capabilities),
|
|
46
40
|
[authData, post, capabilities],
|
|
47
41
|
);
|
|
@@ -62,21 +56,13 @@ export const useFeedPostActions = (post: PublicPost) => {
|
|
|
62
56
|
await repostsQuery.refetch();
|
|
63
57
|
};
|
|
64
58
|
|
|
65
|
-
const toggleReaction = async () => {
|
|
66
|
-
if (iReacted) {
|
|
67
|
-
await retractReaction(undefined);
|
|
68
|
-
} else if (canReact) {
|
|
69
|
-
await reactToPost({ reaction: '👍' });
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
59
|
return {
|
|
74
60
|
me,
|
|
75
61
|
myRepost,
|
|
76
62
|
iReacted,
|
|
77
63
|
canReply,
|
|
78
64
|
canRepost: canRepost || !!myRepost,
|
|
79
|
-
canReact
|
|
65
|
+
canReact,
|
|
80
66
|
reply,
|
|
81
67
|
toggleRepost,
|
|
82
68
|
toggleReaction,
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
|
+
import { QueryClientContext } from '@tanstack/react-query';
|
|
3
|
+
import type { PublicPost } from '@openpeepshq/common/types';
|
|
4
|
+
import { getPostActionAvailability } from '@openpeepshq/common';
|
|
5
|
+
import { useOpenpeeps } from '../../contexts/openpeeps';
|
|
6
|
+
import {
|
|
7
|
+
useAuthData,
|
|
8
|
+
useCurrentProfile,
|
|
9
|
+
} from '../../components/layout/IdentityContext';
|
|
10
|
+
import { useCapabilities } from '../../components/server-data';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Reaction toggle for a single post, shared by the feed footer (via
|
|
14
|
+
* useFeedPostActions) and DM message bubbles.
|
|
15
|
+
*
|
|
16
|
+
* `conversations` queries are only invalidated for direct posts so a
|
|
17
|
+
* reaction on a feed post does not refetch every open thread.
|
|
18
|
+
*/
|
|
19
|
+
export const usePostReactionToggle = (post: PublicPost) => {
|
|
20
|
+
const me = useCurrentProfile();
|
|
21
|
+
const authData = useAuthData();
|
|
22
|
+
const capabilities = useCapabilities();
|
|
23
|
+
const queryClient = useContext(QueryClientContext);
|
|
24
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
25
|
+
|
|
26
|
+
const reactToPost = openpeepsApi.reactToPostAction({ id: post.id } as never);
|
|
27
|
+
const retractReaction = openpeepsApi.retractPostReactionAction({
|
|
28
|
+
id: post.id,
|
|
29
|
+
} as never);
|
|
30
|
+
|
|
31
|
+
const iReacted = useMemo(
|
|
32
|
+
() => !!post.reactions?.some((r) => r.profile.id === me?.id),
|
|
33
|
+
[post.reactions, me?.id],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const { canReact } = useMemo(
|
|
37
|
+
() => getPostActionAvailability(authData, post, capabilities),
|
|
38
|
+
[authData, post, capabilities],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const toggleReaction = async () => {
|
|
42
|
+
if (iReacted) {
|
|
43
|
+
await retractReaction(undefined);
|
|
44
|
+
} else if (canReact) {
|
|
45
|
+
await reactToPost({ reaction: '👍' });
|
|
46
|
+
} else {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (post.visibility === 'direct' && queryClient) {
|
|
50
|
+
await queryClient.invalidateQueries({ queryKey: ['conversations'] });
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
me,
|
|
56
|
+
iReacted,
|
|
57
|
+
canReact: canReact || iReacted,
|
|
58
|
+
toggleReaction,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -8,7 +8,18 @@ import {
|
|
|
8
8
|
import { useOpenpeeps } from '../../contexts/openpeeps';
|
|
9
9
|
import { useFeedListParams } from '../useResolvedFeedFormat';
|
|
10
10
|
|
|
11
|
-
export
|
|
11
|
+
export interface ResourceLibraryInitialFilters {
|
|
12
|
+
kind?: ResourceKind | 'all';
|
|
13
|
+
tags?: string[];
|
|
14
|
+
search?: string;
|
|
15
|
+
pathPrefix?: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const useResourceLibrary = (
|
|
19
|
+
groupId?: string,
|
|
20
|
+
ungrouped?: boolean,
|
|
21
|
+
initial: ResourceLibraryInitialFilters = {},
|
|
22
|
+
) => {
|
|
12
23
|
const { openpeepsApi } = useOpenpeeps();
|
|
13
24
|
const params = useFeedListParams({ format: 'linear' });
|
|
14
25
|
const query = openpeepsApi.usePostsByType('resource', {
|
|
@@ -21,10 +32,14 @@ export const useResourceLibrary = (groupId?: string, ungrouped?: boolean) => {
|
|
|
21
32
|
});
|
|
22
33
|
const bookmarkedIds = openpeepsApi.useCurrentProfileBookmarkedIds();
|
|
23
34
|
|
|
24
|
-
const [search, setSearch] = useState('');
|
|
25
|
-
const [kind, setKind] = useState<ResourceKind | 'all'>('all');
|
|
26
|
-
const [selectedTags, setSelectedTags] = useState<string[]>(
|
|
27
|
-
|
|
35
|
+
const [search, setSearch] = useState(initial.search ?? '');
|
|
36
|
+
const [kind, setKind] = useState<ResourceKind | 'all'>(initial.kind ?? 'all');
|
|
37
|
+
const [selectedTags, setSelectedTags] = useState<string[]>(
|
|
38
|
+
initial.tags ?? [],
|
|
39
|
+
);
|
|
40
|
+
const [pathPrefix, setPathPrefix] = useState<string[]>(
|
|
41
|
+
initial.pathPrefix ?? [],
|
|
42
|
+
);
|
|
28
43
|
const [hierarchy, setHierarchy] = useState(false);
|
|
29
44
|
const [view, setView] = useState<'list' | 'cards'>('cards');
|
|
30
45
|
const [saved, setSaved] = useState(false);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
deepEqual,
|
|
3
4
|
deepSet,
|
|
4
5
|
type ProfileNotificationSettings,
|
|
5
6
|
type ProfileSettings,
|
|
@@ -40,6 +41,15 @@ export const useNotificationPreferences = ({
|
|
|
40
41
|
if (settingsQuery.data) setSettings(settingsQuery.data);
|
|
41
42
|
}, [settingsQuery.data]);
|
|
42
43
|
|
|
44
|
+
// Unsaved local edits. Clears once the post-save refetch lands the
|
|
45
|
+
// server copy; stays set when a save fails.
|
|
46
|
+
const dirty = useMemo(
|
|
47
|
+
() =>
|
|
48
|
+
!!settingsQuery.data &&
|
|
49
|
+
!deepEqual(settings.notifications, settingsQuery.data.notifications),
|
|
50
|
+
[settings, settingsQuery.data],
|
|
51
|
+
);
|
|
52
|
+
|
|
43
53
|
const setTypeSettings = (type: string, next: ProfileNotificationSettings) => {
|
|
44
54
|
setSettings((current) => {
|
|
45
55
|
const copy = { ...current };
|
|
@@ -93,6 +103,7 @@ export const useNotificationPreferences = ({
|
|
|
93
103
|
me,
|
|
94
104
|
types: notificationTypesQuery.data ?? [],
|
|
95
105
|
settings,
|
|
106
|
+
dirty,
|
|
96
107
|
setTypeSettings,
|
|
97
108
|
save,
|
|
98
109
|
saving,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Appends `download=1` so the media endpoint answers with
|
|
3
|
+
* `Content-Disposition: attachment`. The `download` attribute on `<a>` is
|
|
4
|
+
* ignored for cross-origin URLs; the response header works for both.
|
|
5
|
+
*/
|
|
6
|
+
export const asDownloadUrl = (url: string) =>
|
|
7
|
+
`${url}${url.includes('?') ? '&' : '?'}download=1`;
|