Skip to content

Commit 6856a27

Browse files
Merge pull request #293 from GetStream/vishal/docs-fix
Removing optional chaining, to fix docs
2 parents 40756d5 + 25a28ed commit 6856a27

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

src/components/Attachment/Attachment.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const Attachment = (props) => {
3434
return null;
3535
}
3636

37-
const Giphy = props?.Giphy || Card;
38-
const UrlPreview = props?.UrlPreview || Card;
37+
const Giphy = props && props.Giphy ? props.Giphy : Card;
38+
const UrlPreview = props && props.UrlPreview ? props.UrlPreview : Card;
3939
const cardProps = {
4040
Header: CardHeader ? CardHeader : undefined,
4141
Cover: CardCover ? CardCover : undefined,
@@ -61,11 +61,12 @@ const Attachment = (props) => {
6161
type = 'card';
6262
}
6363

64+
const hasAttachmentActions = attachment.actions && attachment.actions.length;
6465
if (type === 'image') {
6566
return (
6667
<>
6768
<Gallery alignment={alignment} images={[attachment]} />
68-
{attachment.actions?.length && (
69+
{hasAttachmentActions && (
6970
<AttachmentActions
7071
actionHandler={actionHandler}
7172
key={`key-actions-${attachment.id}`}
@@ -77,7 +78,7 @@ const Attachment = (props) => {
7778
}
7879

7980
if (type === 'giphy') {
80-
if (attachment.actions?.length) {
81+
if (hasAttachmentActions) {
8182
return (
8283
<View>
8384
<Giphy alignment={alignment} {...attachment} {...cardProps} />
@@ -94,7 +95,7 @@ const Attachment = (props) => {
9495
}
9596

9697
if (type === 'card') {
97-
if (attachment.actions?.length) {
98+
if (hasAttachmentActions) {
9899
return (
99100
<View>
100101
<Card alignment={alignment} {...attachment} {...cardProps} />

src/components/Attachment/Gallery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const Gallery = ({ alignment, images }) => {
9595
const [viewerModalImageIndex, setViewerModalImageIndex] = useState(0);
9696
const [viewerModalOpen, setViewerModalOpen] = useState(false);
9797

98-
if (!images?.length) return null;
98+
if (!images || !images.length) return null;
9999

100100
const galleryImages = [...images].map((image) => ({
101101
url: makeImageCompatibleUrl(image.image_url || image.thumb_url),

src/components/ChannelPreview/ChannelPreviewMessenger.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ const ChannelPreviewMessenger = ({
8989
</Date>
9090
</DetailsTop>
9191
<Message unread={unread > 0 ? unread : undefined}>
92-
{latestMessage?.text &&
92+
{latestMessage &&
93+
latestMessage.text &&
9394
truncate(latestMessage.text.replace(/\n/g, ' '), {
9495
length: latestMessageLength,
9596
})}

src/components/SuggestionsProvider/SuggestionsProvider.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,25 @@ const SuggestionsProvider = ({ children }) => {
5454
const getInputBoxPosition = () =>
5555
new Promise((resolve) => {
5656
const nodeHandleRoot = findNodeHandle(rootView.current);
57-
messageInputBox.current?.measureLayout(
58-
nodeHandleRoot,
59-
(x, y, width, height) => {
60-
resolve({ x, y, height, width });
61-
},
62-
);
57+
messageInputBox.current &&
58+
messageInputBox.current.measureLayout(
59+
nodeHandleRoot,
60+
(x, y, width, height) => {
61+
resolve({ x, y, height, width });
62+
},
63+
);
6364
});
6465

6566
const getChatBoxPosition = () =>
6667
new Promise((resolve) => {
6768
const nodeHandleRoot = findNodeHandle(rootView.current);
68-
rootView.current?.measureLayout(nodeHandleRoot, (x, y, width, height) => {
69-
resolve({ x, y, height, width });
70-
});
69+
rootView.current &&
70+
rootView.current.measureLayout(
71+
nodeHandleRoot,
72+
(x, y, width, height) => {
73+
resolve({ x, y, height, width });
74+
},
75+
);
7176
});
7277

7378
const suggestionsContext = {

src/components/docs/Gallery.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
```js
22
const images = [
3-
{ image_url: 'https://i.picsum.photos/id/1/200/300.jpg' },
4-
{ image_url: 'https://i.picsum.photos/id/2/200/300.jpg' },
5-
{ image_url: 'https://i.picsum.photos/id/3/200/300.jpg' },
6-
{ image_url: 'https://i.picsum.photos/id/4/200/300.jpg' },
7-
{ image_url: 'https://i.picsum.photos/id/5/200/300.jpg' },
8-
{ image_url: 'https://i.picsum.photos/id/6/200/300.jpg' },
3+
{ image_url: 'https://i.picsum.photos/id/912/200/300.jpg?blur=5&hmac=Qk9-L9x5NUPVQh1fgIM_HucJtpX2RKOAK1sLTGD-7U4' },
4+
{ image_url: 'https://i.picsum.photos/id/1/5616/3744.jpg?hmac=kKHwwU8s46oNettHKwJ24qOlIAsWN9d2TtsXDoCWWsQ' },
5+
{ image_url: 'https://i.picsum.photos/id/10/2500/1667.jpg?hmac=J04WWC_ebchx3WwzbM-Z4_KC_LeLBWr5LZMaAkWkF68' },
6+
{ image_url: 'https://i.picsum.photos/id/100/2500/1656.jpg?hmac=gWyN-7ZB32rkAjMhKXQgdHOIBRHyTSgzuOK6U0vXb1w' },
7+
{ image_url: 'https://i.picsum.photos/id/912/200/300.jpg?blur=5&hmac=Qk9-L9x5NUPVQh1fgIM_HucJtpX2RKOAK1sLTGD-7U4' },
8+
{ image_url: 'https://i.picsum.photos/id/912/200/300.jpg?blur=5&hmac=Qk9-L9x5NUPVQh1fgIM_HucJtpX2RKOAK1sLTGD-7U4' },
99
];
10-
<Gallery images={images} />;
10+
<Chat>
11+
<Gallery images={images} />;
12+
</Chat>
1113
```

0 commit comments

Comments
 (0)