-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create link preview for sent messages
- Loading branch information
1 parent
a71a38c
commit 3bae93b
Showing
7 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../components/Chat/ChatMessage/components/MessageLinkPreview/MessageLinkPreview.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@import "../../../../../../constants"; | ||
|
||
$border-radius: 0.625rem; | ||
|
||
.container { | ||
--container-bg: #{$link-my-reply-bg}; | ||
--title-color: var(--primary-background); | ||
--description-color: var(--hover-fill); | ||
--url-color: #{$link-my-reply}; | ||
|
||
max-width: 14rem; | ||
margin-bottom: 0.625rem; | ||
display: flex; | ||
flex-direction: column; | ||
background-color: var(--container-bg); | ||
border-radius: $border-radius; | ||
text-align: left; | ||
} | ||
.containerOtherPerson { | ||
--container-bg: var(--secondary-background); | ||
--title-color: var(--primary-text); | ||
--description-color: #{$editor-checkbox-inactive}; | ||
--url-color: var(--highlight); | ||
} | ||
|
||
.contentWrapper { | ||
padding: 0.5rem; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.image { | ||
height: 9.5rem; | ||
object-fit: cover; | ||
border-top-left-radius: $border-radius; | ||
border-top-right-radius: $border-radius; | ||
} | ||
|
||
.title { | ||
display: -webkit-box; | ||
font-size: 0.8125rem; | ||
font-weight: 600; | ||
color: var(--title-color); | ||
-webkit-line-clamp: 2; | ||
-webkit-box-orient: vertical; | ||
overflow: hidden; | ||
} | ||
|
||
.description { | ||
display: -webkit-box; | ||
font-size: 0.6875rem; | ||
color: var(--description-color); | ||
white-space: pre-wrap; | ||
-webkit-line-clamp: 4; | ||
-webkit-box-orient: vertical; | ||
overflow: hidden; | ||
} | ||
|
||
.url { | ||
font-size: 0.6875rem; | ||
color: var(--url-color); | ||
} |
48 changes: 48 additions & 0 deletions
48
src/shared/components/Chat/ChatMessage/components/MessageLinkPreview/MessageLinkPreview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { FC, useMemo } from "react"; | ||
import classNames from "classnames"; | ||
import styles from "./MessageLinkPreview.module.scss"; | ||
|
||
interface MessageLinkPreviewProps { | ||
isOtherPersonMessage: boolean; | ||
} | ||
|
||
const getUrlOrigin = (url: string): string => { | ||
try { | ||
return new URL(url).host; | ||
} catch (err) { | ||
return ""; | ||
} | ||
}; | ||
|
||
const MessageLinkPreview: FC<MessageLinkPreviewProps> = (props) => { | ||
const { isOtherPersonMessage } = props; | ||
const data = { | ||
title: "David Kushner - Mr. Forgettable [Official Music Video]", | ||
description: | ||
"HEADLINE SHOWSOctober 18th - Brooklyn, NY - https://bit.ly/3SkMxSlOctober 21st - Los Angeles, CA - https://bit.ly/3BPd9UCOctober 26th - Chicago, IL - https:/...", | ||
image: "https://i.ytimg.com/vi/7TCncxWNcPU/maxresdefault.jpg", | ||
url: "https://youtu.be/7TCncxWNcPU?list=RD7TCncxWNcPU", | ||
}; | ||
const urlOrigin = useMemo(() => getUrlOrigin(data.url), [data.url]); | ||
|
||
return ( | ||
<div | ||
className={classNames(styles.container, { | ||
[styles.containerOtherPerson]: isOtherPersonMessage, | ||
})} | ||
> | ||
<img className={styles.image} src={data.image} alt={data.title} /> | ||
<div className={styles.contentWrapper}> | ||
<span className={styles.title} title={data.title}> | ||
{data.title} | ||
</span> | ||
<span className={styles.description} title={data.description}> | ||
{data.description} | ||
</span> | ||
<span className={styles.url}>{urlOrigin}</span> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MessageLinkPreview; |
1 change: 1 addition & 0 deletions
1
src/shared/components/Chat/ChatMessage/components/MessageLinkPreview/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as MessageLinkPreview } from "./MessageLinkPreview"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters