From 42d866931bd257b1ed4492bf7fd25816249d62de Mon Sep 17 00:00:00 2001 From: mastqe Date: Sat, 15 Oct 2022 10:01:10 -0400 Subject: [PATCH] Functional Component Refactor: Figma, Framer, Gist (#4260) --- shared/editor/embeds/Figma.tsx | 34 +++++++++--------- shared/editor/embeds/Framer.tsx | 23 +++++------- shared/editor/embeds/Gist.tsx | 64 +++++++++++++++------------------ 3 files changed, 54 insertions(+), 67 deletions(-) diff --git a/shared/editor/embeds/Figma.tsx b/shared/editor/embeds/Figma.tsx index 84cc23330..5f413037b 100644 --- a/shared/editor/embeds/Figma.tsx +++ b/shared/editor/embeds/Figma.tsx @@ -2,21 +2,21 @@ import * as React from "react"; import Frame from "../components/Frame"; import { EmbedProps as Props } from "."; -const URL_REGEX = new RegExp( - "https://([w.-]+\\.)?figma\\.com/(file|proto)/([0-9a-zA-Z]{22,128})(?:/.*)?$" -); - -export default class Figma extends React.Component { - static ENABLED = [URL_REGEX]; - - render() { - return ( - - ); - } +function Figma(props: Props) { + return ( + + ); } + +Figma.ENABLED = [ + new RegExp( + "https://([w.-]+\\.)?figma\\.com/(file|proto)/([0-9a-zA-Z]{22,128})(?:/.*)?$" + ), +]; + +export default Figma; diff --git a/shared/editor/embeds/Framer.tsx b/shared/editor/embeds/Framer.tsx index 4589dde3d..a14e5c179 100644 --- a/shared/editor/embeds/Framer.tsx +++ b/shared/editor/embeds/Framer.tsx @@ -2,19 +2,12 @@ import * as React from "react"; import Frame from "../components/Frame"; import { EmbedProps as Props } from "."; -const URL_REGEX = new RegExp("^https://framer.cloud/(.*)$"); - -export default class Framer extends React.Component { - static ENABLED = [URL_REGEX]; - - render() { - return ( - - ); - } +function Framer(props: Props) { + return ( + + ); } + +Framer.ENABLED = [new RegExp("^https://framer.cloud/(.*)$")]; + +export default Framer; diff --git a/shared/editor/embeds/Gist.tsx b/shared/editor/embeds/Gist.tsx index 8c333c165..75de907d6 100644 --- a/shared/editor/embeds/Gist.tsx +++ b/shared/editor/embeds/Gist.tsx @@ -2,43 +2,37 @@ import * as React from "react"; import styled from "styled-components"; import { EmbedProps as Props } from "."; -const URL_REGEX = new RegExp( - "^https://gist\\.github\\.com/([a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,38})/(.*)$" -); - -class Gist extends React.Component { - static ENABLED = [URL_REGEX]; - - get id() { - const gistUrl = new URL(this.props.attrs.href); - return gistUrl.pathname.split("/")[2]; - } - - render() { - const id = this.id; - const gistLink = `https://gist.github.com/${id}.js`; - const gistScript = ``; - const styles = - ""; - const iframeHtml = `${styles}${gistScript}`; - - return ( -