-
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.
fix(search): update buildURL and make a componen of highlightedmessage
- Loading branch information
Showing
5 changed files
with
68 additions
and
47 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const HighlightedMessage = ({ | ||
message, | ||
highlightedQuery, | ||
}: { | ||
message: string; | ||
highlightedQuery: string; | ||
}) => { | ||
const renderHighlightedMessage = () => { | ||
if (!highlightedQuery) return message; | ||
|
||
const lowerCaseMessage = message?.toLowerCase(); | ||
const lowerCaseQuery = highlightedQuery?.toLowerCase(); | ||
const index = lowerCaseMessage.indexOf(lowerCaseQuery); | ||
if (index === -1) return message; | ||
|
||
const prefix = message.substring(0, index); | ||
const highlight = message.substring(index, index + highlightedQuery.length); | ||
const suffix = message.substring(index + highlightedQuery.length); | ||
|
||
return ( | ||
<> | ||
{prefix} | ||
<span style={{ backgroundColor: "#efcb3a" }}>{highlight}</span> | ||
{suffix} | ||
</> | ||
); | ||
}; | ||
|
||
return <>{renderHighlightedMessage()}</>; | ||
}; | ||
|
||
export default HighlightedMessage; |
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