-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(project): player fixes and UI improvements
* fix(home): click event not working properly on iOS Safari For some reason, when including a react-markdown component on the page, all click events don’t work properly anymore. We needed to click two times in order to navigate. Replacing react-markdown with marked fixes this issue as I couldn’t find the real culprit in react-markdown. * fix(player): player not respecting updated startTime * fix(player): player not on top when fading in * fix(player): store watch progress when leaving page * fix(player): update autostart option in player * fix: multiple ui improvements * chore: update snapshots
- Loading branch information
1 parent
d42f9fc
commit 5670fd8
Showing
24 changed files
with
139 additions
and
571 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
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,37 +1,39 @@ | ||
import React, { useMemo } from 'react'; | ||
import DOMPurify from 'dompurify'; | ||
import { marked } from 'marked'; | ||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
import ReactMarkdown from 'react-markdown'; | ||
|
||
import styles from './MarkdownComponent.module.scss'; | ||
|
||
const renderer = { | ||
link(href: string, title: string, text: string) { | ||
const externalLink = /^(https?|www\.|\/\/)/.test(href || ''); | ||
const targetAttr = externalLink ? 'target="_blank"' : undefined; | ||
const relAttr = externalLink ? 'rel="noopener"' : undefined; | ||
const titleAttr = title ? `title="${title}"` : undefined; | ||
const attributes = [targetAttr, relAttr, titleAttr].filter(Boolean); | ||
|
||
return `<a href="${href}" ${attributes.join(' ')}>${text}</a>`; | ||
}, | ||
}; | ||
|
||
marked.use({ renderer }); | ||
|
||
type Props = { | ||
markdownString: string; | ||
className?: string; | ||
disallowedElements?: string[]; | ||
inline?: boolean; | ||
}; | ||
|
||
const MarkdownComponent: React.FC<Props> = ({ markdownString, className, disallowedElements }: Props) => { | ||
return ( | ||
<ReactMarkdown | ||
className={classNames(styles.markdown, className)} | ||
components={{ | ||
a: ({ node, href, children, ...props }) => { | ||
const externalLink = /^(https?|www\.|\/\/)/.test(href || ''); | ||
const target = externalLink ? '_blank' : undefined; | ||
const rel = externalLink ? 'noopener' : undefined; | ||
return ( | ||
<a {...props} href={href} target={target} rel={rel}> | ||
{children} | ||
</a> | ||
); | ||
}, | ||
}} | ||
disallowedElements={disallowedElements} | ||
unwrapDisallowed | ||
> | ||
{markdownString} | ||
</ReactMarkdown> | ||
); | ||
const MarkdownComponent: React.FC<Props> = ({ markdownString, className, inline = false }) => { | ||
const sanitizedHTMLString = useMemo(() => { | ||
const parseDelegate = inline ? marked.parseInline : marked.parse; | ||
const dirtyHTMLString = parseDelegate(markdownString); | ||
|
||
return DOMPurify.sanitize(dirtyHTMLString, { ADD_ATTR: ['target'] }); | ||
}, [inline, markdownString]); | ||
|
||
return <div className={classNames(styles.markdown, className)} dangerouslySetInnerHTML={{ __html: sanitizedHTMLString }} />; | ||
}; | ||
|
||
export default MarkdownComponent; |
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 |
---|---|---|
|
@@ -15,6 +15,8 @@ exports[`<MarkdownComponent> > renders and matches snapshot 1`] = ` | |
testlink | ||
</a> | ||
</p> | ||
</div> | ||
</div> | ||
`; |
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
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
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
Oops, something went wrong.