Skip to content

Commit

Permalink
Removing optional chaining, to fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede committed Aug 21, 2020
1 parent 5642d15 commit 4a2870f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
11 changes: 6 additions & 5 deletions src/components/Attachment/Attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const Attachment = (props) => {
return null;
}

const Giphy = props?.Giphy || Card;
const UrlPreview = props?.UrlPreview || Card;
const Giphy = props.Giphy || Card;
const UrlPreview = props.UrlPreview || Card;
const cardProps = {
Header: CardHeader ? CardHeader : undefined,
Cover: CardCover ? CardCover : undefined,
Expand All @@ -61,11 +61,12 @@ const Attachment = (props) => {
type = 'card';
}

const hasAttachmentActions = attachment.actions && attachment.actions.length;
if (type === 'image') {
return (
<>
<Gallery alignment={alignment} images={[attachment]} />
{attachment.actions?.length && (
{hasAttachmentActions && (
<AttachmentActions
actionHandler={actionHandler}
key={`key-actions-${attachment.id}`}
Expand All @@ -77,7 +78,7 @@ const Attachment = (props) => {
}

if (type === 'giphy') {
if (attachment.actions?.length) {
if (hasAttachmentActions) {
return (
<View>
<Giphy alignment={alignment} {...attachment} {...cardProps} />
Expand All @@ -94,7 +95,7 @@ const Attachment = (props) => {
}

if (type === 'card') {
if (attachment.actions?.length) {
if (hasAttachmentActions) {
return (
<View>
<Card alignment={alignment} {...attachment} {...cardProps} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/Attachment/Gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const Gallery = ({ alignment, images }) => {
const [viewerModalImageIndex, setViewerModalImageIndex] = useState(0);
const [viewerModalOpen, setViewerModalOpen] = useState(false);

if (!images?.length) return null;
if (!images || !images.length) return null;

const galleryImages = [...images].map((image) => ({
url: makeImageCompatibleUrl(image.image_url || image.thumb_url),
Expand Down
3 changes: 2 additions & 1 deletion src/components/ChannelPreview/ChannelPreviewMessenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const ChannelPreviewMessenger = ({
</Date>
</DetailsTop>
<Message unread={unread > 0 ? unread : undefined}>
{latestMessage?.text &&
{latestMessage &&
latestMessage.text &&
truncate(latestMessage.text.replace(/\n/g, ' '), {
length: latestMessageLength,
})}
Expand Down
23 changes: 14 additions & 9 deletions src/components/SuggestionsProvider/SuggestionsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,25 @@ const SuggestionsProvider = ({ children }) => {
const getInputBoxPosition = () =>
new Promise((resolve) => {
const nodeHandleRoot = findNodeHandle(rootView.current);
messageInputBox.current?.measureLayout(
nodeHandleRoot,
(x, y, width, height) => {
resolve({ x, y, height, width });
},
);
messageInputBox.current &&
messageInputBox.current.measureLayout(
nodeHandleRoot,
(x, y, width, height) => {
resolve({ x, y, height, width });
},
);
});

const getChatBoxPosition = () =>
new Promise((resolve) => {
const nodeHandleRoot = findNodeHandle(rootView.current);
rootView.current?.measureLayout(nodeHandleRoot, (x, y, width, height) => {
resolve({ x, y, height, width });
});
rootView.current &&
rootView.current.measureLayout(
nodeHandleRoot,
(x, y, width, height) => {
resolve({ x, y, height, width });
},
);
});

const suggestionsContext = {
Expand Down
16 changes: 9 additions & 7 deletions src/components/docs/Gallery.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
```js
const images = [
{ image_url: 'https://i.picsum.photos/id/1/200/300.jpg' },
{ image_url: 'https://i.picsum.photos/id/2/200/300.jpg' },
{ image_url: 'https://i.picsum.photos/id/3/200/300.jpg' },
{ image_url: 'https://i.picsum.photos/id/4/200/300.jpg' },
{ image_url: 'https://i.picsum.photos/id/5/200/300.jpg' },
{ image_url: 'https://i.picsum.photos/id/6/200/300.jpg' },
{ image_url: 'https://i.picsum.photos/id/912/200/300.jpg?blur=5&hmac=Qk9-L9x5NUPVQh1fgIM_HucJtpX2RKOAK1sLTGD-7U4' },
{ image_url: 'https://i.picsum.photos/id/1/5616/3744.jpg?hmac=kKHwwU8s46oNettHKwJ24qOlIAsWN9d2TtsXDoCWWsQ' },
{ image_url: 'https://i.picsum.photos/id/10/2500/1667.jpg?hmac=J04WWC_ebchx3WwzbM-Z4_KC_LeLBWr5LZMaAkWkF68' },
{ image_url: 'https://i.picsum.photos/id/100/2500/1656.jpg?hmac=gWyN-7ZB32rkAjMhKXQgdHOIBRHyTSgzuOK6U0vXb1w' },
{ image_url: 'https://i.picsum.photos/id/912/200/300.jpg?blur=5&hmac=Qk9-L9x5NUPVQh1fgIM_HucJtpX2RKOAK1sLTGD-7U4' },
{ image_url: 'https://i.picsum.photos/id/912/200/300.jpg?blur=5&hmac=Qk9-L9x5NUPVQh1fgIM_HucJtpX2RKOAK1sLTGD-7U4' },
];
<Gallery images={images} />;
<Chat>
<Gallery images={images} />;
</Chat>
```

0 comments on commit 4a2870f

Please sign in to comment.