This repository has been archived by the owner on Apr 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
feature: implement mention link #65
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6d0df5d
feature: implement mention link
johnanisere f56676b
style: revert avatar atom changes
byCedric de68848
style: revert highlight atom changes
byCedric d7a1e51
style: revert user molecule double quotes
byCedric b5fae75
style: revert highlight atom trailing comma removal
byCedric 8e049de
refactor: revert user molecule highlight weight
byCedric edcb7f4
style: use single quotes in user molecule
byCedric 82127ff
fixup! style: use single quote in user molecule
byCedric 54a3676
fixup! style: use single quotes in user molecule
byCedric ef54ced
refactor: use match from decorator for github link
byCedric 8c731bc
fixup! refactor: use match from decorator for github link
byCedric a13a7a4
style: fix indentation and add trailing comma in user molecule
byCedric bfe66a4
Merge branch 'develop' into mentionLink
byCedric ac04b7c
style: use proper order of styling in user molecule
byCedric File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,19 +1,31 @@ | ||
import React from 'react'; | ||
import Avatar from 'src/atoms/avatar'; | ||
import Highlight from 'src/atoms/highlight'; | ||
import { propTypes, defaultProps } from './prop-type'; | ||
import UserMeta from './user-meta'; | ||
import React from "react"; | ||
import UserMeta from "./user-meta"; | ||
import Avatar from "src/atoms/avatar"; | ||
import Highlight from "src/atoms/highlight"; | ||
import { propTypes, defaultProps } from "./prop-type"; | ||
import { mentionLink } from "./util"; | ||
import { | ||
UserContainer, | ||
UserAvatar, | ||
UserName, | ||
UserDescription, | ||
UserDescriptionHighlight, | ||
} from './elements'; | ||
UserDescriptionHighlight | ||
} from "./elements"; | ||
|
||
const decorators = { | ||
'@': (segment, match, key) => <UserDescriptionHighlight key={key}>{segment}</UserDescriptionHighlight>, | ||
'#': (segment, match, key) => <UserDescriptionHighlight key={key}>{match}</UserDescriptionHighlight>, | ||
"@": (segment, match, key) => ( | ||
<UserDescriptionHighlight | ||
key={key} | ||
href={mentionLink(segment)} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I always forget the |
||
> | ||
{segment} | ||
</UserDescriptionHighlight> | ||
), | ||
"#": (segment, match, key) => ( | ||
<UserDescriptionHighlight key={key}>{match}</UserDescriptionHighlight> | ||
) | ||
}; | ||
|
||
export default function UserMolecule(props) { | ||
|
@@ -23,19 +35,11 @@ export default function UserMolecule(props) { | |
<UserContainer> | ||
<UserMeta {...props} /> | ||
<UserAvatar> | ||
<Avatar | ||
url={props.avatarUrl} | ||
name={identifier} | ||
title={identifier} | ||
/> | ||
<Avatar url={props.avatarUrl} name={identifier} title={identifier} /> | ||
</UserAvatar> | ||
<UserName title={identifier}> | ||
{props.name} | ||
</UserName> | ||
<UserName title={identifier}>{props.name}</UserName> | ||
<UserDescription> | ||
<Highlight decorators={decorators}> | ||
{props.description} | ||
</Highlight> | ||
<Highlight decorators={decorators}>{props.description}</Highlight> | ||
</UserDescription> | ||
</UserContainer> | ||
); | ||
|
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,11 @@ | ||
export function mentionLink(name) { | ||
let mention = name.split(""); | ||
|
||
mention.splice(0, 1); | ||
|
||
let username = mention.join(""); | ||
|
||
const url = `https://github.com/${username}`; | ||
|
||
return url; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must add a bit more documentation to the highlighter atom I think. In the
mentionLink
you separate the special character@
from the text right? Luckily I thought about this use case when I built the highlighter, it's thematch
parameter 😄 But again, this is fully my fault for lack of documentation.TL;DR; The
match
parameter is the value you can use here, without having to separate the character from text yourself 😄The decorator is invoked with the segment, match and key. Take this text for example:
This will result in 2x method invocations with the
@
decorator with the following arguments:@abc
abc
0
@qwe
qwe
1