@openpeepshq/react 0.7.0 → 0.7.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/configuration/ConfigurationCategory.js +3 -2
- package/dist/components/configuration/ConfigurationList.js +1 -1
- package/dist/components/form/LocationInput.js +1 -1
- package/dist/components/jams/JamCapacityGate.js +1 -1
- package/dist/components/jams/JamConference.js +2 -0
- package/dist/components/jams/JamParticipantConference.js +2 -0
- package/dist/components/jams/JamRoom.js +2 -3
- package/dist/components/jams/LiveJamsSection.js +8 -2
- package/dist/components/jams/LivekitUnavailableNotice.d.ts +9 -0
- package/dist/components/jams/LivekitUnavailableNotice.js +19 -0
- package/dist/components/jams/dropLateAudio.d.ts +22 -0
- package/dist/components/jams/dropLateAudio.js +115 -0
- package/dist/components/jams/index.d.ts +1 -0
- package/dist/components/jams/index.js +1 -0
- package/dist/components/notifications/TypedNotification.js +46 -4
- package/dist/components/post/Markdown.d.ts +2 -2
- package/dist/components/post/Markdown.js +1 -1
- package/dist/components/post/attachmentPreview.js +1 -1
- package/dist/components/post/pieces/Attachments.js +23 -17
- package/dist/components/post/pieces/EventRsvpButton.js +37 -7
- package/dist/components/post/pieces/EventRsvpList.js +23 -3
- package/dist/components/post/pieces/EventRsvpScopeDialog.d.ts +1 -1
- package/dist/components/post/pieces/EventRsvpScopeDialog.js +34 -22
- package/dist/components/post/pieces/EventWaitlistJoinDialog.d.ts +10 -0
- package/dist/components/post/pieces/EventWaitlistJoinDialog.js +26 -0
- package/dist/components/post/pieces/ParticipantsCard.d.ts +1 -1
- package/dist/components/post/pieces/ParticipantsCard.js +1 -1
- package/dist/components/post/pieces/PostActions.d.ts +1 -1
- package/dist/components/post/pieces/PostActions.js +20 -12
- package/dist/components/post/pieces/ShareMenu.d.ts +6 -1
- package/dist/components/post/pieces/ShareMenu.js +40 -7
- package/dist/components/post/post-form/EventForm.js +10 -2
- package/dist/components/post/types/Article.js +1 -1
- package/dist/components/post/types/article/FullArticle.js +1 -1
- package/dist/components/post/types/event/CardEvent.js +2 -1
- package/dist/components/post/types/event/FullEvent.js +22 -13
- package/dist/components/post/types/event/ProfileEventRelationship.js +8 -0
- package/dist/components/preview-link/LocalPreviewLink.js +4 -2
- package/dist/components/preview-link/PreviewLink.js +1 -1
- package/dist/components/preview-link/helpers.d.ts +5 -0
- package/dist/components/preview-link/helpers.js +27 -1
- package/dist/components/preview-link/local/WelcomePreview.d.ts +1 -0
- package/dist/components/preview-link/local/WelcomePreview.js +6 -0
- package/dist/components/profile/Avatar.js +2 -2
- package/dist/components/profile/ProfileFromId.js +1 -1
- package/dist/components/server-data/context.d.ts +1 -0
- package/dist/contexts/openpeeps/hooks/accounts.d.ts +5 -5
- package/dist/contexts/openpeeps/hooks/accounts.js +1 -3
- package/dist/contexts/openpeeps/hooks/admin.d.ts +165 -66
- package/dist/contexts/openpeeps/hooks/admin.js +11 -3
- package/dist/contexts/openpeeps/hooks/auth.d.ts +2 -2
- package/dist/contexts/openpeeps/hooks/groups.d.ts +8 -8
- package/dist/contexts/openpeeps/hooks/jams.d.ts +73 -24
- package/dist/contexts/openpeeps/hooks/other.d.ts +7 -6
- package/dist/contexts/openpeeps/hooks/payments.d.ts +2 -2
- package/dist/contexts/openpeeps/hooks/posts.d.ts +368 -170
- package/dist/contexts/openpeeps/hooks/streaming.d.ts +1 -1
- package/dist/hooks/admin/useCanAccessAdminSection.d.ts +13 -0
- package/dist/hooks/admin/useCanAccessAdminSection.js +21 -0
- package/dist/hooks/events/useEventComposer.d.ts +94 -41
- package/dist/hooks/events/useEventForm.d.ts +1 -0
- package/dist/hooks/events/useEventRsvp.d.ts +11 -2
- package/dist/hooks/events/useEventRsvp.js +46 -5
- package/dist/hooks/events/useEventsCalendar.d.ts +174 -76
- package/dist/hooks/groups/useNewGroup.js +22 -2
- package/dist/hooks/index.d.ts +5 -1
- package/dist/hooks/index.js +4 -1
- package/dist/hooks/jams/useCanDiagnoseLivekit.d.ts +2 -0
- package/dist/hooks/jams/useCanDiagnoseLivekit.js +3 -0
- package/dist/hooks/jams/useCreateNewJamForm.d.ts +3 -1
- package/dist/hooks/jams/useJamDetails.d.ts +87 -38
- package/dist/hooks/jams/useJamLobby.d.ts +1 -0
- package/dist/hooks/jams/useJamRoom.d.ts +175 -76
- package/dist/hooks/posts/useArticleComposer.d.ts +93 -41
- package/dist/hooks/posts/useFeedPostPresentation.d.ts +174 -76
- package/dist/hooks/posts/usePostDetailTitle.d.ts +87 -38
- package/dist/hooks/posts/useResourceComposer.d.ts +93 -41
- package/dist/hooks/posts/useResourceComposer.js +4 -2
- package/dist/hooks/posts/useShareMenu.d.ts +2 -0
- package/dist/hooks/posts/useShareMenu.js +7 -0
- package/dist/hooks/resources/useResourceLibrary.d.ts +176 -78
- package/dist/hooks/settings/useNotificationPreferences.d.ts +1 -1
- package/dist/hooks/useWelcomePreview.d.ts +13 -0
- package/dist/hooks/useWelcomePreview.js +39 -0
- package/dist/lib/groupFormErrors.d.ts +1 -0
- package/dist/lib/groupFormErrors.js +5 -2
- package/dist/lib/threadHelpers.js +1 -5
- package/dist/pages/admin/ConfigurationCommunity.js +1 -1
- package/dist/pages/admin/Diagnostics.js +1 -1
- package/dist/pages/admin/DiagnosticsLivekit.d.ts +1 -0
- package/dist/pages/admin/DiagnosticsLivekit.js +50 -0
- package/dist/pages/admin/Invites.js +5 -3
- package/dist/pages/admin/Media.d.ts +1 -0
- package/dist/pages/admin/Media.js +135 -0
- package/dist/pages/admin/community/CommunityForbiddenUsernames.d.ts +1 -0
- package/dist/pages/admin/community/CommunityForbiddenUsernames.js +106 -0
- package/dist/pages/admin/community/CommunityRoles.js +1 -1
- package/dist/pages/admin/community/useCommunityConfig.d.ts +2 -0
- package/dist/pages/admin/components/EditInviteLinkModal.d.ts +5 -0
- package/dist/pages/admin/components/EditInviteLinkModal.js +131 -0
- package/dist/pages/auth/Register.js +30 -8
- package/dist/pages/conversations/Show.js +11 -0
- package/dist/pages/index.d.ts +3 -0
- package/dist/pages/index.js +3 -0
- package/dist/pages/jams/Index.js +2 -4
- package/dist/pages/settings/PublicProfile.js +15 -3
- package/dist/pwa/sw.d.ts +0 -1
- package/dist/react-native.d.ts +1 -0
- package/dist/react-native.js +1 -0
- package/dist/stores/newPosts.d.ts +4 -2
- package/dist/stores/newPosts.js +6 -1
- package/package.json +12 -7
- package/src/components/configuration/ConfigurationCategory.tsx +23 -10
- package/src/components/configuration/ConfigurationList.tsx +6 -1
- package/src/components/form/LocationInput.tsx +7 -1
- package/src/components/jams/JamCapacityGate.tsx +1 -1
- package/src/components/jams/JamConference.tsx +2 -0
- package/src/components/jams/JamParticipantConference.tsx +2 -0
- package/src/components/jams/JamRoom.tsx +2 -6
- package/src/components/jams/LiveJamsSection.tsx +16 -2
- package/src/components/jams/LivekitUnavailableNotice.tsx +40 -0
- package/src/components/jams/dropLateAudio.ts +153 -0
- package/src/components/jams/index.ts +1 -0
- package/src/components/notifications/TypedNotification.tsx +81 -9
- package/src/components/post/Markdown.tsx +8 -2
- package/src/components/post/attachmentPreview.ts +1 -3
- package/src/components/post/pieces/Attachments.tsx +93 -78
- package/src/components/post/pieces/EventRsvpButton.tsx +107 -7
- package/src/components/post/pieces/EventRsvpList.tsx +64 -0
- package/src/components/post/pieces/EventRsvpScopeDialog.tsx +39 -27
- package/src/components/post/pieces/EventWaitlistJoinDialog.tsx +77 -0
- package/src/components/post/pieces/ParticipantsCard.tsx +4 -1
- package/src/components/post/pieces/PostActions.tsx +73 -42
- package/src/components/post/pieces/ShareMenu.tsx +67 -9
- package/src/components/post/post-form/EventForm.tsx +26 -0
- package/src/components/post/post-form/VisibilitySelector.tsx +1 -2
- package/src/components/post/types/Article.tsx +1 -1
- package/src/components/post/types/article/FullArticle.tsx +2 -2
- package/src/components/post/types/event/CardEvent.tsx +26 -14
- package/src/components/post/types/event/FullEvent.tsx +48 -35
- package/src/components/post/types/event/ProfileEventRelationship.tsx +8 -0
- package/src/components/post/types/note/FullNote.tsx +1 -4
- package/src/components/post/types/poll/FullPoll.tsx +1 -4
- package/src/components/preview-link/LocalPreviewLink.tsx +4 -1
- package/src/components/preview-link/PreviewLink.tsx +2 -7
- package/src/components/preview-link/helpers.ts +32 -1
- package/src/components/preview-link/local/GroupPreview.tsx +1 -1
- package/src/components/preview-link/local/JamPreview.tsx +1 -1
- package/src/components/preview-link/local/WelcomePreview.tsx +36 -0
- package/src/components/profile/Avatar.tsx +6 -2
- package/src/components/profile/ProfileFromId.tsx +1 -5
- package/src/components/resources/ResourceCard.tsx +0 -1
- package/src/contexts/openpeeps/hooks/accounts.ts +1 -3
- package/src/contexts/openpeeps/hooks/admin.ts +11 -3
- package/src/contexts/openpeeps/hooks/other.ts +9 -12
- package/src/contexts/openpeeps/hooks/streaming.ts +3 -3
- package/src/css.d.ts +4 -0
- package/src/hooks/admin/useCanAccessAdminSection.ts +27 -0
- package/src/hooks/events/useEventRsvp.ts +51 -7
- package/src/hooks/groups/useNewGroup.ts +28 -3
- package/src/hooks/index.ts +8 -1
- package/src/hooks/jams/useCanDiagnoseLivekit.ts +5 -0
- package/src/hooks/posts/useResourceComposer.ts +8 -6
- package/src/hooks/posts/useShareMenu.ts +9 -0
- package/src/hooks/useWelcomePreview.ts +57 -0
- package/src/i18n/I18nProvider.tsx +1 -4
- package/src/lib/groupFormErrors.ts +9 -2
- package/src/lib/threadHelpers.ts +1 -5
- package/src/pages/admin/ConfigurationCommunity.tsx +5 -0
- package/src/pages/admin/Diagnostics.tsx +4 -0
- package/src/pages/admin/DiagnosticsLivekit.tsx +147 -0
- package/src/pages/admin/Invites.tsx +23 -1
- package/src/pages/admin/Media.tsx +290 -0
- package/src/pages/admin/community/CommunityForbiddenUsernames.tsx +223 -0
- package/src/pages/admin/community/CommunityRoles.tsx +2 -2
- package/src/pages/admin/components/EditInviteLinkModal.tsx +263 -0
- package/src/pages/auth/Register.tsx +33 -4
- package/src/pages/conversations/Show.tsx +11 -0
- package/src/pages/index.ts +3 -0
- package/src/pages/jams/Index.tsx +2 -6
- package/src/pages/settings/PublicProfile.tsx +20 -2
- package/src/pwa/sw.ts +6 -3
- package/src/pwa/useNotificationBadgeSync.ts +3 -1
- package/src/react-native.ts +1 -0
- package/src/stores/newPosts.ts +6 -1
- package/src/streaming.ts +3 -3
- package/dist/setupTests.d.ts +0 -1
- package/dist/setupTests.js +0 -5
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { useT, useOpenpeeps, useSetPageHeader } from '../../index';
|
|
2
|
+
import { Button } from '@openpeepshq/react-ui';
|
|
3
|
+
import type { LivekitDiagnosis } from '@openpeepshq/common/types';
|
|
4
|
+
|
|
5
|
+
const checkLabelKey = {
|
|
6
|
+
url: 'diagnostics.livekit.url',
|
|
7
|
+
apiKey: 'diagnostics.livekit.apiKey',
|
|
8
|
+
apiSecret: 'diagnostics.livekit.apiSecret',
|
|
9
|
+
reachable: 'diagnostics.livekit.reachable',
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
export const AdminDiagnosticsLivekit = () => {
|
|
13
|
+
const t = useT();
|
|
14
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
15
|
+
const diagnosisQuery = openpeepsApi.admin.useLivekitDiagnosis();
|
|
16
|
+
|
|
17
|
+
useSetPageHeader(t('diagnostics.livekit.title', { defaultValue: 'LiveKit' }));
|
|
18
|
+
|
|
19
|
+
const diagnosis = diagnosisQuery.data;
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className="space-y-4 p-4">
|
|
23
|
+
<p className="text-muted-foreground text-sm">
|
|
24
|
+
{t('diagnostics.livekit.description', {
|
|
25
|
+
defaultValue:
|
|
26
|
+
'Check whether jams can reach the LiveKit server. Missing or invalid credentials disable live jams.',
|
|
27
|
+
})}
|
|
28
|
+
</p>
|
|
29
|
+
|
|
30
|
+
<Button
|
|
31
|
+
variant="outline"
|
|
32
|
+
title={t('diagnostics.livekit.refresh', { defaultValue: 'Refresh' })}
|
|
33
|
+
action={() => void diagnosisQuery.refetch()}
|
|
34
|
+
>
|
|
35
|
+
{t('diagnostics.livekit.refresh', { defaultValue: 'Refresh' })}
|
|
36
|
+
</Button>
|
|
37
|
+
|
|
38
|
+
{diagnosisQuery.isPending ? (
|
|
39
|
+
<p className="text-muted-foreground text-sm">
|
|
40
|
+
{t('common.form.loading', { defaultValue: 'Loading…' })}
|
|
41
|
+
</p>
|
|
42
|
+
) : null}
|
|
43
|
+
|
|
44
|
+
{diagnosisQuery.isError ? (
|
|
45
|
+
<p className="text-error text-sm">
|
|
46
|
+
{t('diagnostics.livekit.loadError', {
|
|
47
|
+
defaultValue: 'Could not load the LiveKit diagnosis.',
|
|
48
|
+
})}
|
|
49
|
+
</p>
|
|
50
|
+
) : null}
|
|
51
|
+
|
|
52
|
+
{diagnosis ? <DiagnosisReport diagnosis={diagnosis} /> : null}
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const DiagnosisReport = ({ diagnosis }: { diagnosis: LivekitDiagnosis }) => {
|
|
58
|
+
const t = useT();
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div className="space-y-4">
|
|
62
|
+
<p
|
|
63
|
+
className={`font-medium ${diagnosis.connected ? 'text-success' : 'text-error'}`}
|
|
64
|
+
role="status"
|
|
65
|
+
>
|
|
66
|
+
{diagnosis.connected
|
|
67
|
+
? t('diagnostics.livekit.connected', { defaultValue: 'Connected' })
|
|
68
|
+
: t('diagnostics.livekit.notConnected', {
|
|
69
|
+
defaultValue: 'Not connected',
|
|
70
|
+
})}
|
|
71
|
+
</p>
|
|
72
|
+
|
|
73
|
+
<ul className="border-border divide-border divide-y rounded-md border">
|
|
74
|
+
{diagnosis.checks.map((check) => {
|
|
75
|
+
const status =
|
|
76
|
+
check.id === 'reachable'
|
|
77
|
+
? check.ok
|
|
78
|
+
? t('diagnostics.livekit.ok', { defaultValue: 'OK' })
|
|
79
|
+
: t('diagnostics.livekit.failed', { defaultValue: 'Failed' })
|
|
80
|
+
: check.ok
|
|
81
|
+
? t('diagnostics.livekit.set', { defaultValue: 'Set' })
|
|
82
|
+
: t('diagnostics.livekit.missing', {
|
|
83
|
+
defaultValue: 'Missing',
|
|
84
|
+
});
|
|
85
|
+
return (
|
|
86
|
+
<li
|
|
87
|
+
key={check.id}
|
|
88
|
+
className="flex items-start justify-between gap-4 p-3 text-sm"
|
|
89
|
+
>
|
|
90
|
+
<div>
|
|
91
|
+
<p className="font-medium">
|
|
92
|
+
{t(checkLabelKey[check.id], {
|
|
93
|
+
defaultValue: check.id,
|
|
94
|
+
})}
|
|
95
|
+
</p>
|
|
96
|
+
{check.id === 'url' && diagnosis.url ? (
|
|
97
|
+
<p className="text-muted-foreground font-mono text-xs">
|
|
98
|
+
{diagnosis.url}
|
|
99
|
+
</p>
|
|
100
|
+
) : null}
|
|
101
|
+
</div>
|
|
102
|
+
<span
|
|
103
|
+
className={`rounded px-2 py-0.5 text-xs font-medium ${check.ok ? 'bg-success/20 text-success' : 'bg-error/20 text-error'}`}
|
|
104
|
+
>
|
|
105
|
+
{status}
|
|
106
|
+
</span>
|
|
107
|
+
</li>
|
|
108
|
+
);
|
|
109
|
+
})}
|
|
110
|
+
</ul>
|
|
111
|
+
|
|
112
|
+
<p className="text-sm">
|
|
113
|
+
{t('diagnostics.livekit.recording', { defaultValue: 'Recording' })}
|
|
114
|
+
{': '}
|
|
115
|
+
<strong>
|
|
116
|
+
{diagnosis.recordingEnabled
|
|
117
|
+
? t('diagnostics.livekit.recordingOn', {
|
|
118
|
+
defaultValue: 'Enabled',
|
|
119
|
+
})
|
|
120
|
+
: t('diagnostics.livekit.recordingOff', {
|
|
121
|
+
defaultValue: 'Disabled',
|
|
122
|
+
})}
|
|
123
|
+
</strong>
|
|
124
|
+
</p>
|
|
125
|
+
|
|
126
|
+
{diagnosis.error ? (
|
|
127
|
+
<div>
|
|
128
|
+
<p className="font-medium">
|
|
129
|
+
{t('diagnostics.livekit.error', { defaultValue: 'Last error' })}
|
|
130
|
+
</p>
|
|
131
|
+
<pre className="bg-surface mt-2 overflow-x-auto whitespace-pre-wrap break-words rounded-md p-3 font-mono text-xs">
|
|
132
|
+
{diagnosis.error}
|
|
133
|
+
</pre>
|
|
134
|
+
</div>
|
|
135
|
+
) : null}
|
|
136
|
+
|
|
137
|
+
{!diagnosis.connected ? (
|
|
138
|
+
<p className="text-muted-foreground text-sm">
|
|
139
|
+
{t('diagnostics.livekit.envHint', {
|
|
140
|
+
defaultValue:
|
|
141
|
+
'Set JAMS_LIVEKIT_URL, JAMS_LIVEKIT_API_KEY, and JAMS_LIVEKIT_API_SECRET on the server, then refresh.',
|
|
142
|
+
})}
|
|
143
|
+
</p>
|
|
144
|
+
) : null}
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
};
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { useMemo, useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
CheckCheck,
|
|
4
|
+
Copy,
|
|
5
|
+
MoreVertical,
|
|
6
|
+
Pencil,
|
|
7
|
+
QrCode,
|
|
8
|
+
Users,
|
|
9
|
+
X,
|
|
10
|
+
} from 'lucide-react';
|
|
3
11
|
import { inviteLinkMatchesQuery } from '@openpeepshq/common/lib';
|
|
4
12
|
import type { InviteLinkWithMeta } from '@openpeepshq/common/types';
|
|
5
13
|
import {
|
|
@@ -20,6 +28,7 @@ import {
|
|
|
20
28
|
PopupMenuButton,
|
|
21
29
|
} from '@openpeepshq/react-ui';
|
|
22
30
|
import { AdminInviteActions } from './components/AdminInviteActions';
|
|
31
|
+
import { EditInviteLinkModal } from './components/EditInviteLinkModal';
|
|
23
32
|
import {
|
|
24
33
|
communityQrLogoSrc,
|
|
25
34
|
downloadInviteQr,
|
|
@@ -153,6 +162,7 @@ function InvitesTablePopup({ invite }: { invite: InviteLinkWithMeta }) {
|
|
|
153
162
|
const activate = openpeepsApi.admin.activateInviteAction();
|
|
154
163
|
const deactivate = openpeepsApi.admin.deactivateInviteAction();
|
|
155
164
|
const [showInvited, setShowInvited] = useState(false);
|
|
165
|
+
const [showEdit, setShowEdit] = useState(false);
|
|
156
166
|
|
|
157
167
|
const active = invite.active && new Date(invite.expiresAt) > new Date();
|
|
158
168
|
const expired = new Date(invite.expiresAt) <= new Date();
|
|
@@ -170,6 +180,12 @@ function InvitesTablePopup({ invite }: { invite: InviteLinkWithMeta }) {
|
|
|
170
180
|
})}
|
|
171
181
|
action={() => setShowInvited(true)}
|
|
172
182
|
/>
|
|
183
|
+
<PopupMenuButton
|
|
184
|
+
icon={Pencil}
|
|
185
|
+
title={t('admin.invites.edit', { defaultValue: 'Edit' })}
|
|
186
|
+
text={t('admin.invites.edit', { defaultValue: 'Edit' })}
|
|
187
|
+
action={() => setShowEdit(true)}
|
|
188
|
+
/>
|
|
173
189
|
{active ? (
|
|
174
190
|
<>
|
|
175
191
|
<PopupMenuButton
|
|
@@ -219,6 +235,12 @@ function InvitesTablePopup({ invite }: { invite: InviteLinkWithMeta }) {
|
|
|
219
235
|
onClose={() => setShowInvited(false)}
|
|
220
236
|
/>
|
|
221
237
|
) : null}
|
|
238
|
+
{showEdit ? (
|
|
239
|
+
<EditInviteLinkModal
|
|
240
|
+
invite={invite}
|
|
241
|
+
onClose={() => setShowEdit(false)}
|
|
242
|
+
/>
|
|
243
|
+
) : null}
|
|
222
244
|
</>
|
|
223
245
|
);
|
|
224
246
|
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
import { Images } from 'lucide-react';
|
|
3
|
+
import type {
|
|
4
|
+
StoredMediaFile,
|
|
5
|
+
StoredMediaStatus,
|
|
6
|
+
} from '@openpeepshq/common/types';
|
|
7
|
+
import { checkRoleCapabilities } from '@openpeepshq/common';
|
|
8
|
+
import {
|
|
9
|
+
Button,
|
|
10
|
+
Dialog,
|
|
11
|
+
DialogActions,
|
|
12
|
+
DialogContent,
|
|
13
|
+
DialogHeader,
|
|
14
|
+
DialogTitle,
|
|
15
|
+
} from '@openpeepshq/react-ui';
|
|
16
|
+
import { useOpenpeeps, useSetPageHeader, useT } from '../../index';
|
|
17
|
+
import { useCurrentProfile } from '../../components';
|
|
18
|
+
|
|
19
|
+
type MediaFilter = 'all' | 'unused' | 'referenced';
|
|
20
|
+
|
|
21
|
+
const formatBytes = (size: number): string => {
|
|
22
|
+
if (size < 1024) return `${size} B`;
|
|
23
|
+
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`;
|
|
24
|
+
if (size < 1024 * 1024 * 1024) {
|
|
25
|
+
return `${(size / (1024 * 1024)).toFixed(1)} MB`;
|
|
26
|
+
}
|
|
27
|
+
return `${(size / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const formatWhen = (iso: string | null): string =>
|
|
31
|
+
iso ? new Date(iso).toLocaleString() : '';
|
|
32
|
+
|
|
33
|
+
export const AdminMedia = () => {
|
|
34
|
+
const t = useT();
|
|
35
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
36
|
+
const me = useCurrentProfile();
|
|
37
|
+
const canDeleteMedia = checkRoleCapabilities(me?.roles ?? [], [
|
|
38
|
+
'core-media-delete',
|
|
39
|
+
]).success;
|
|
40
|
+
const mediaQuery = openpeepsApi.admin.useMediaList();
|
|
41
|
+
const deleteMedia = openpeepsApi.admin.deleteMediaAction();
|
|
42
|
+
|
|
43
|
+
const [filter, setFilter] = useState<MediaFilter>('all');
|
|
44
|
+
const [query, setQuery] = useState('');
|
|
45
|
+
const [pending, setPending] = useState<StoredMediaFile | null>(null);
|
|
46
|
+
const [deleting, setDeleting] = useState(false);
|
|
47
|
+
const [deleteError, setDeleteError] = useState<string | null>(null);
|
|
48
|
+
|
|
49
|
+
const files = mediaQuery.data?.files ?? [];
|
|
50
|
+
const graceDays = Math.round((mediaQuery.data?.graceMs ?? 0) / 86_400_000);
|
|
51
|
+
const needle = query.trim().toLowerCase();
|
|
52
|
+
|
|
53
|
+
const visible = useMemo(
|
|
54
|
+
() =>
|
|
55
|
+
files.filter((file) => {
|
|
56
|
+
if (filter === 'unused' && file.status === 'referenced') return false;
|
|
57
|
+
if (filter === 'referenced' && file.status !== 'referenced') {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return (
|
|
61
|
+
needle.length === 0 || file.storageId.toLowerCase().includes(needle)
|
|
62
|
+
);
|
|
63
|
+
}),
|
|
64
|
+
[files, filter, needle],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const unusedCount = files.filter(
|
|
68
|
+
(file) => file.status !== 'referenced',
|
|
69
|
+
).length;
|
|
70
|
+
|
|
71
|
+
useSetPageHeader(t('admin.media.title', { defaultValue: 'Media' }));
|
|
72
|
+
|
|
73
|
+
const statusLabel = (status: StoredMediaStatus) =>
|
|
74
|
+
t(`admin.media.status.${status}`, {
|
|
75
|
+
defaultValue:
|
|
76
|
+
status === 'referenced'
|
|
77
|
+
? 'In use'
|
|
78
|
+
: status === 'due'
|
|
79
|
+
? 'Ready to collect'
|
|
80
|
+
: 'Unused',
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const collectionLabel = (file: StoredMediaFile) => {
|
|
84
|
+
if (file.status === 'referenced') {
|
|
85
|
+
return t('admin.media.collects.referenced', {
|
|
86
|
+
defaultValue: 'Kept — still linked',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (file.status === 'pending') {
|
|
90
|
+
return t('admin.media.collects.pending', {
|
|
91
|
+
defaultValue: 'Deletes {{date}}',
|
|
92
|
+
date: formatWhen(file.deletesAt),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (file.status === 'due') {
|
|
96
|
+
return t('admin.media.collects.due', {
|
|
97
|
+
defaultValue: 'Deletes on the next run',
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return t('admin.media.collects.unseen', {
|
|
101
|
+
defaultValue: 'Recorded on the next run',
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const confirmDelete = async () => {
|
|
106
|
+
if (!pending) return;
|
|
107
|
+
setDeleting(true);
|
|
108
|
+
setDeleteError(null);
|
|
109
|
+
try {
|
|
110
|
+
await deleteMedia({ storageId: pending.storageId });
|
|
111
|
+
setPending(null);
|
|
112
|
+
void mediaQuery.refetch();
|
|
113
|
+
} catch (error) {
|
|
114
|
+
setDeleteError((error as Error).message);
|
|
115
|
+
} finally {
|
|
116
|
+
setDeleting(false);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const filters: { id: MediaFilter; label: string }[] = [
|
|
121
|
+
{ id: 'all', label: t('admin.media.filter.all', { defaultValue: 'All' }) },
|
|
122
|
+
{
|
|
123
|
+
id: 'unused',
|
|
124
|
+
label: t('admin.media.filter.unused', { defaultValue: 'Unused' }),
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: 'referenced',
|
|
128
|
+
label: t('admin.media.filter.inUse', { defaultValue: 'In use' }),
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<div className="space-y-4 p-4">
|
|
134
|
+
<div className="rounded-md border p-4 text-sm">
|
|
135
|
+
{t('admin.media.description', {
|
|
136
|
+
defaultValue:
|
|
137
|
+
'Removing a post or jam recording leaves the file on the server, because another post, the welcome page, the about page, the code of conduct, a profile, or a custom field may still link to it. Garbage collection deletes a file {{days}} days after it first has no live link. Delete now removes a file immediately.',
|
|
138
|
+
days: graceDays || 7,
|
|
139
|
+
})}
|
|
140
|
+
</div>
|
|
141
|
+
<p className="text-muted-foreground text-sm">
|
|
142
|
+
{t('admin.media.counts', {
|
|
143
|
+
defaultValue:
|
|
144
|
+
'{{total}} files · {{unused}} unused · {{inUse}} in use',
|
|
145
|
+
total: files.length,
|
|
146
|
+
unused: unusedCount,
|
|
147
|
+
inUse: files.length - unusedCount,
|
|
148
|
+
})}
|
|
149
|
+
</p>
|
|
150
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
151
|
+
{filters.map((item) => (
|
|
152
|
+
<Button
|
|
153
|
+
key={item.id}
|
|
154
|
+
title={item.label}
|
|
155
|
+
variant={filter === item.id ? 'default' : 'outline'}
|
|
156
|
+
action={() => setFilter(item.id)}
|
|
157
|
+
>
|
|
158
|
+
{item.label}
|
|
159
|
+
</Button>
|
|
160
|
+
))}
|
|
161
|
+
<input
|
|
162
|
+
value={query}
|
|
163
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
164
|
+
placeholder={t('admin.media.search', {
|
|
165
|
+
defaultValue: 'Search by file id',
|
|
166
|
+
})}
|
|
167
|
+
className="border-border bg-background min-w-48 flex-1 rounded-md border px-3 py-2 text-sm"
|
|
168
|
+
/>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
{mediaQuery.isLoading ? (
|
|
172
|
+
<p className="text-muted-foreground text-sm">
|
|
173
|
+
{t('admin.media.loading', { defaultValue: 'Loading…' })}
|
|
174
|
+
</p>
|
|
175
|
+
) : null}
|
|
176
|
+
{mediaQuery.isError ? (
|
|
177
|
+
<p className="text-error text-sm">
|
|
178
|
+
{t('admin.media.error', {
|
|
179
|
+
defaultValue: 'Could not load media files',
|
|
180
|
+
})}
|
|
181
|
+
</p>
|
|
182
|
+
) : null}
|
|
183
|
+
{!mediaQuery.isLoading && !mediaQuery.isError && visible.length === 0 ? (
|
|
184
|
+
<div className="text-muted-foreground flex flex-col items-center pt-16">
|
|
185
|
+
<Images size={48} />
|
|
186
|
+
<p className="mt-2 text-sm">
|
|
187
|
+
{t('admin.media.empty', { defaultValue: 'No media files' })}
|
|
188
|
+
</p>
|
|
189
|
+
</div>
|
|
190
|
+
) : null}
|
|
191
|
+
{visible.length > 0 ? (
|
|
192
|
+
<ul className="space-y-2">
|
|
193
|
+
{visible.map((file) => (
|
|
194
|
+
<li key={file.storageId} className="rounded-md border p-3">
|
|
195
|
+
<div className="flex flex-wrap items-start justify-between gap-3">
|
|
196
|
+
<div className="min-w-0">
|
|
197
|
+
<p className="break-all font-mono text-xs">
|
|
198
|
+
{file.storageId}
|
|
199
|
+
</p>
|
|
200
|
+
<p className="text-muted-foreground mt-1 text-sm">
|
|
201
|
+
{formatBytes(file.size)} · {formatWhen(file.modifiedAt)}
|
|
202
|
+
</p>
|
|
203
|
+
<p className="mt-1 text-sm">
|
|
204
|
+
<span className="font-medium">
|
|
205
|
+
{statusLabel(file.status)}
|
|
206
|
+
</span>
|
|
207
|
+
<span className="text-muted-foreground">
|
|
208
|
+
{' '}
|
|
209
|
+
· {collectionLabel(file)}
|
|
210
|
+
</span>
|
|
211
|
+
</p>
|
|
212
|
+
</div>
|
|
213
|
+
<div className="flex items-center gap-2">
|
|
214
|
+
<a
|
|
215
|
+
href={file.url}
|
|
216
|
+
target="_blank"
|
|
217
|
+
rel="noreferrer"
|
|
218
|
+
className="text-primary text-sm"
|
|
219
|
+
>
|
|
220
|
+
{t('admin.media.open', { defaultValue: 'Open' })}
|
|
221
|
+
</a>
|
|
222
|
+
{canDeleteMedia ? (
|
|
223
|
+
<Button
|
|
224
|
+
title={t('admin.media.delete', {
|
|
225
|
+
defaultValue: 'Delete now',
|
|
226
|
+
})}
|
|
227
|
+
variant="outline"
|
|
228
|
+
action={() => {
|
|
229
|
+
setDeleteError(null);
|
|
230
|
+
setPending(file);
|
|
231
|
+
}}
|
|
232
|
+
>
|
|
233
|
+
{t('admin.media.delete', { defaultValue: 'Delete now' })}
|
|
234
|
+
</Button>
|
|
235
|
+
) : null}
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
</li>
|
|
239
|
+
))}
|
|
240
|
+
</ul>
|
|
241
|
+
) : null}
|
|
242
|
+
|
|
243
|
+
{pending ? (
|
|
244
|
+
<Dialog
|
|
245
|
+
open
|
|
246
|
+
onOpenChange={(open) => {
|
|
247
|
+
if (!open && !deleting) setPending(null);
|
|
248
|
+
}}
|
|
249
|
+
>
|
|
250
|
+
<DialogContent className="max-w-md">
|
|
251
|
+
<DialogHeader>
|
|
252
|
+
<DialogTitle>
|
|
253
|
+
{t('admin.media.confirm.title', {
|
|
254
|
+
defaultValue: 'Delete this file?',
|
|
255
|
+
})}
|
|
256
|
+
</DialogTitle>
|
|
257
|
+
</DialogHeader>
|
|
258
|
+
<p className="px-1 text-sm">
|
|
259
|
+
{pending.status === 'referenced'
|
|
260
|
+
? t('admin.media.confirm.referenced', {
|
|
261
|
+
defaultValue:
|
|
262
|
+
'This file is still linked from a post, page, or profile. Deleting it now removes it from the server, and those links will stop working.',
|
|
263
|
+
})
|
|
264
|
+
: t('admin.media.confirm.unused', {
|
|
265
|
+
defaultValue:
|
|
266
|
+
'This file is unused. Deleting it now removes it from the server instead of waiting for garbage collection.',
|
|
267
|
+
})}
|
|
268
|
+
</p>
|
|
269
|
+
{deleteError ? (
|
|
270
|
+
<p className="border-error/40 text-error rounded-md border p-2 text-sm">
|
|
271
|
+
{deleteError}
|
|
272
|
+
</p>
|
|
273
|
+
) : null}
|
|
274
|
+
<DialogActions
|
|
275
|
+
cancelLabel={t('admin.media.confirm.cancel', {
|
|
276
|
+
defaultValue: 'Cancel',
|
|
277
|
+
})}
|
|
278
|
+
onCancel={() => setPending(null)}
|
|
279
|
+
actionLabel={t('admin.media.confirm.action', {
|
|
280
|
+
defaultValue: 'Delete file',
|
|
281
|
+
})}
|
|
282
|
+
onAction={confirmDelete}
|
|
283
|
+
disabled={deleting}
|
|
284
|
+
/>
|
|
285
|
+
</DialogContent>
|
|
286
|
+
</Dialog>
|
|
287
|
+
) : null}
|
|
288
|
+
</div>
|
|
289
|
+
);
|
|
290
|
+
};
|