@openpeepshq/rn-components 0.12.5 → 0.13.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/rn-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "React Native community screens and shared UI (extracted from the Black Ambition app) for the OpenPeeps stack.",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -142,8 +142,8 @@
|
|
|
142
142
|
"timezones-list": "^3.1.0",
|
|
143
143
|
"validator": "^13.15.23",
|
|
144
144
|
"zustand": "^5.0.3",
|
|
145
|
-
"@openpeepshq/common": "^0.
|
|
146
|
-
"@openpeepshq/react": "^0.
|
|
145
|
+
"@openpeepshq/common": "^0.7.0",
|
|
146
|
+
"@openpeepshq/react": "^0.13.0"
|
|
147
147
|
},
|
|
148
148
|
"devDependencies": {
|
|
149
149
|
"@babel/core": "^7.26.7",
|
|
@@ -57,6 +57,7 @@ import {
|
|
|
57
57
|
VolumeOff,
|
|
58
58
|
Share,
|
|
59
59
|
Hand,
|
|
60
|
+
History,
|
|
60
61
|
Copy,
|
|
61
62
|
Clock,
|
|
62
63
|
Pencil,
|
|
@@ -206,6 +207,7 @@ export const VolumeOffIcon = iconWithClassName(VolumeOff);
|
|
|
206
207
|
export const InfoIcon = iconWithClassName(Info);
|
|
207
208
|
export const ShareIcon = iconWithClassName(Share);
|
|
208
209
|
export const HandIcon = iconWithClassName(Hand);
|
|
210
|
+
export const HistoryIcon = iconWithClassName(History);
|
|
209
211
|
export const CopyIcon = iconWithClassName(Copy);
|
|
210
212
|
export const ClockIcon = iconWithClassName(Clock);
|
|
211
213
|
export const PencilIcon = iconWithClassName(Pencil);
|
|
@@ -11,11 +11,15 @@ import {
|
|
|
11
11
|
BookmarkMinusIcon,
|
|
12
12
|
Repeat2Icon,
|
|
13
13
|
ThumbsUpIcon,
|
|
14
|
+
HistoryIcon,
|
|
14
15
|
} from '../../icons/index';
|
|
15
16
|
import { PopupMenu, PopupMenuButton, PopupSeparator } from '../../ui';
|
|
16
17
|
import { useOpenpeeps } from '@openpeepshq/react';
|
|
17
18
|
import { checkGroupCapabilities } from '@openpeepshq/common';
|
|
18
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
checkRoleCapabilities,
|
|
21
|
+
postHasEditHistory,
|
|
22
|
+
} from '@openpeepshq/common/lib';
|
|
19
23
|
import type { PublicPost } from '@openpeepshq/common/types';
|
|
20
24
|
import { useNavigation } from '@react-navigation/native';
|
|
21
25
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
@@ -26,6 +30,7 @@ import { BottomSheetModal } from '@gorhom/bottom-sheet';
|
|
|
26
30
|
import { DeletePostModal } from './modals/DeletePostModal';
|
|
27
31
|
import { ReportProfileOrPostModal } from '../../profile/ReportProfileOrPostModal';
|
|
28
32
|
import { RepostModal } from './modals/RepostModal';
|
|
33
|
+
import { PostEditHistoryModal } from './modals/PostEditHistoryModal';
|
|
29
34
|
import { ReactionsModal } from './modals/ReactionsModal';
|
|
30
35
|
import Toast from 'react-native-toast-message';
|
|
31
36
|
|
|
@@ -51,6 +56,12 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
51
56
|
const [isFollowing, setIsFollowing] = React.useState(false);
|
|
52
57
|
const [repostsModalOpen, setRepostsModalOpen] = React.useState(false);
|
|
53
58
|
const [reactionsModalOpen, setReactionsModalOpen] = React.useState(false);
|
|
59
|
+
const [historyModalOpen, setHistoryModalOpen] = React.useState(false);
|
|
60
|
+
|
|
61
|
+
// Hidden (blocked-author tombstone) posts have their entry snapshots
|
|
62
|
+
// stripped server-side; never offer history for them or deleted posts.
|
|
63
|
+
const showEditHistory =
|
|
64
|
+
!post.hidden && !post.deletedAt && postHasEditHistory(post.entries);
|
|
54
65
|
|
|
55
66
|
const { data: serverInfo } = openpeepsApi.useServerInfo();
|
|
56
67
|
const canPinToGroup =
|
|
@@ -293,6 +304,16 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
293
304
|
icon={ThumbsUpIcon}
|
|
294
305
|
action={() => setReactionsModalOpen(true)}
|
|
295
306
|
/>
|
|
307
|
+
{showEditHistory ? (
|
|
308
|
+
<PopupMenuButton
|
|
309
|
+
title={t('posts.editHistory.menu', {
|
|
310
|
+
defaultValue: 'Edit history',
|
|
311
|
+
})}
|
|
312
|
+
text={t('posts.editHistory.menu', { defaultValue: 'Edit history' })}
|
|
313
|
+
icon={HistoryIcon}
|
|
314
|
+
action={() => setHistoryModalOpen(true)}
|
|
315
|
+
/>
|
|
316
|
+
) : null}
|
|
296
317
|
|
|
297
318
|
{isBookmarked ? (
|
|
298
319
|
<PopupMenuButton
|
|
@@ -457,6 +478,13 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
457
478
|
open={reactionsModalOpen}
|
|
458
479
|
onClose={() => setReactionsModalOpen(false)}
|
|
459
480
|
/>
|
|
481
|
+
{showEditHistory ? (
|
|
482
|
+
<PostEditHistoryModal
|
|
483
|
+
post={post}
|
|
484
|
+
open={historyModalOpen}
|
|
485
|
+
onClose={() => setHistoryModalOpen(false)}
|
|
486
|
+
/>
|
|
487
|
+
) : null}
|
|
460
488
|
<DeletePostModal
|
|
461
489
|
ref={deleteMessageModalRef}
|
|
462
490
|
onDelete={handleDelete}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { Image, Linking, Pressable, View } from 'react-native';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import type { PostDataUnion, PublicPost } from '@openpeepshq/common/types';
|
|
5
|
+
import {
|
|
6
|
+
formatEventWhen,
|
|
7
|
+
postEditVersionKind,
|
|
8
|
+
postEditVersionTitle,
|
|
9
|
+
postEditVersions,
|
|
10
|
+
type PostVersionOrder,
|
|
11
|
+
} from '@openpeepshq/common/lib';
|
|
12
|
+
import { BaseSheet } from '../../../custom/modals/common/index';
|
|
13
|
+
import { UpdatingDate } from '../../../custom/date/updating-date';
|
|
14
|
+
import { OpenpeepsMarkdown } from '../../../markdown';
|
|
15
|
+
import { ThemedText } from '../../../ui/themed-text';
|
|
16
|
+
import { Button } from '../../../ui/button';
|
|
17
|
+
import { useControlledSheet } from '../../../../hooks/use-controlled-sheet';
|
|
18
|
+
|
|
19
|
+
export interface PostEditHistoryModalProps {
|
|
20
|
+
post: PublicPost;
|
|
21
|
+
open: boolean;
|
|
22
|
+
onClose: () => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const VersionBody = ({
|
|
26
|
+
post,
|
|
27
|
+
data,
|
|
28
|
+
}: {
|
|
29
|
+
post: PublicPost;
|
|
30
|
+
data: PostDataUnion;
|
|
31
|
+
}) => {
|
|
32
|
+
const { t } = useTranslation();
|
|
33
|
+
const title = postEditVersionTitle(data);
|
|
34
|
+
const image = 'image' in data ? data.image : undefined;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<View className="gap-2">
|
|
38
|
+
{image ? (
|
|
39
|
+
<Image
|
|
40
|
+
source={{ uri: image }}
|
|
41
|
+
accessibilityLabel={title ?? ''}
|
|
42
|
+
className="h-40 w-full rounded-md"
|
|
43
|
+
resizeMode="cover"
|
|
44
|
+
/>
|
|
45
|
+
) : null}
|
|
46
|
+
{title ? (
|
|
47
|
+
<ThemedText className="text-base font-semibold">{title}</ThemedText>
|
|
48
|
+
) : null}
|
|
49
|
+
{data.type === 'event' ? (
|
|
50
|
+
<ThemedText className="text-sm text-muted-foreground">
|
|
51
|
+
{formatEventWhen(data.start, {
|
|
52
|
+
end: data.end,
|
|
53
|
+
timeZone: data.timeZone,
|
|
54
|
+
allDay: data.wholeDay,
|
|
55
|
+
})}
|
|
56
|
+
</ThemedText>
|
|
57
|
+
) : null}
|
|
58
|
+
{data.content ? (
|
|
59
|
+
<OpenpeepsMarkdown source={data.content} mentions={post.mentions} />
|
|
60
|
+
) : null}
|
|
61
|
+
{data.type === 'question'
|
|
62
|
+
? data.options.map((option, index) => (
|
|
63
|
+
<ThemedText key={`${option.content}-${index}`} className="text-sm">
|
|
64
|
+
{`• ${option.content}`}
|
|
65
|
+
</ThemedText>
|
|
66
|
+
))
|
|
67
|
+
: null}
|
|
68
|
+
{data.type === 'resource' && data.url ? (
|
|
69
|
+
<Pressable onPress={() => void Linking.openURL(data.url!)}>
|
|
70
|
+
<ThemedText className="text-sm text-primary">{data.url}</ThemedText>
|
|
71
|
+
</Pressable>
|
|
72
|
+
) : null}
|
|
73
|
+
{/* Entry snapshots keep only attachment metadata (no binary), so the
|
|
74
|
+
placeholder covers removed attachments. Media referenced inline in the
|
|
75
|
+
note/event/event-agenda content is not snapshotted either and renders
|
|
76
|
+
as plain markdown text in a version. */}
|
|
77
|
+
{data.attachments?.length ? (
|
|
78
|
+
<View className="rounded-md border border-dashed border-border p-2">
|
|
79
|
+
<ThemedText className="text-xs text-muted-foreground">
|
|
80
|
+
{t('posts.editHistory.mediaUnavailable', {
|
|
81
|
+
defaultValue: 'Media from this version is no longer available',
|
|
82
|
+
})}
|
|
83
|
+
</ThemedText>
|
|
84
|
+
</View>
|
|
85
|
+
) : null}
|
|
86
|
+
</View>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const PostEditHistoryModal = ({
|
|
91
|
+
post,
|
|
92
|
+
open,
|
|
93
|
+
onClose,
|
|
94
|
+
}: PostEditHistoryModalProps) => {
|
|
95
|
+
const { t } = useTranslation();
|
|
96
|
+
const ref = useControlledSheet(open);
|
|
97
|
+
const [order, setOrder] = useState<PostVersionOrder>('newest');
|
|
98
|
+
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (open) setOrder('newest');
|
|
101
|
+
}, [open]);
|
|
102
|
+
|
|
103
|
+
const versions = postEditVersions(post.entries, order);
|
|
104
|
+
const kindLabel = {
|
|
105
|
+
original: t('posts.editHistory.original', { defaultValue: 'Original' }),
|
|
106
|
+
edit: t('posts.editHistory.edit', { defaultValue: 'Edit' }),
|
|
107
|
+
current: t('posts.editHistory.current', { defaultValue: 'Current' }),
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<BaseSheet ref={ref} snapPoints={['80%']} scrollable onDismiss={onClose}>
|
|
112
|
+
<View className="gap-3 px-4 pb-3">
|
|
113
|
+
<ThemedText className="text-center text-xl font-semibold">
|
|
114
|
+
{t('posts.editHistory.title')}
|
|
115
|
+
</ThemedText>
|
|
116
|
+
<Button
|
|
117
|
+
variant="outline"
|
|
118
|
+
size="sm"
|
|
119
|
+
className="self-start"
|
|
120
|
+
onPress={() =>
|
|
121
|
+
setOrder((current) => (current === 'oldest' ? 'newest' : 'oldest'))
|
|
122
|
+
}
|
|
123
|
+
>
|
|
124
|
+
<ThemedText>
|
|
125
|
+
{order === 'oldest'
|
|
126
|
+
? t('posts.editHistory.newestFirst')
|
|
127
|
+
: t('posts.editHistory.oldestFirst')}
|
|
128
|
+
</ThemedText>
|
|
129
|
+
</Button>
|
|
130
|
+
<View
|
|
131
|
+
accessibilityLabel={t('posts.editHistory.title', {
|
|
132
|
+
defaultValue: 'Edit history',
|
|
133
|
+
})}
|
|
134
|
+
accessibilityRole="list"
|
|
135
|
+
className="gap-3"
|
|
136
|
+
>
|
|
137
|
+
{versions.map((version) => (
|
|
138
|
+
<View
|
|
139
|
+
key={version.id}
|
|
140
|
+
className="gap-2 rounded-md border border-border p-3"
|
|
141
|
+
>
|
|
142
|
+
<View className="flex-row flex-wrap items-center gap-2">
|
|
143
|
+
<ThemedText className="text-xs font-medium">
|
|
144
|
+
{kindLabel[postEditVersionKind(version)]}
|
|
145
|
+
</ThemedText>
|
|
146
|
+
<UpdatingDate
|
|
147
|
+
date={version.createdAt}
|
|
148
|
+
className="text-xs text-muted-foreground"
|
|
149
|
+
/>
|
|
150
|
+
{version.profile?.handle ? (
|
|
151
|
+
<ThemedText className="text-xs text-muted-foreground">
|
|
152
|
+
{t('posts.editHistory.editedBy', {
|
|
153
|
+
defaultValue: 'by @{{handle}}',
|
|
154
|
+
handle: version.profile.handle,
|
|
155
|
+
})}
|
|
156
|
+
</ThemedText>
|
|
157
|
+
) : null}
|
|
158
|
+
</View>
|
|
159
|
+
<VersionBody post={post} data={version.data} />
|
|
160
|
+
</View>
|
|
161
|
+
))}
|
|
162
|
+
</View>
|
|
163
|
+
</View>
|
|
164
|
+
</BaseSheet>
|
|
165
|
+
);
|
|
166
|
+
};
|