diff --git a/src/FilterLists.Web.V2/src/shared/buttons/subscribe/SubscribeButton.tsx b/src/FilterLists.Web.V2/src/shared/buttons/subscribe/SubscribeButton.tsx index f3c6524e3..62f092bbd 100644 --- a/src/FilterLists.Web.V2/src/shared/buttons/subscribe/SubscribeButton.tsx +++ b/src/FilterLists.Web.V2/src/shared/buttons/subscribe/SubscribeButton.tsx @@ -14,30 +14,37 @@ interface Props { }; export const SubscribeButton = (props: Props): JSX.Element => - (props.viewUrlMirrors && props.viewUrlMirrors.length > 0) - ? + (props.viewUrlMirrors && props.viewUrlMirrors.length) + ? :
; -const SubscribeButtonDropdown = (props: Props): JSX.Element => { +const ButtonDropdown = (props: Props): JSX.Element => { var buttonProps = buildButtonProps(props.name, props.viewUrl); //TODO: pass title (ref https://github.com/ant-design/ant-design/issues/18122) return - {props.viewUrlMirrors.map((viewUrlMirror: string, i: number) => - - - )} - - }> + overlay={}> Subscribe ; }; +interface DropdownOverlayProps { + name: string; + viewUrlMirrors: string[]; +}; + +const DropdownOverlay = (props: DropdownOverlayProps) => + + {props.viewUrlMirrors.map((viewUrlMirror: string, i: number) => + + + + )} + ; + const buildButtonProps = (name: string, viewUrl: string): ButtonProps => { let type: ButtonType = "primary"; @@ -45,38 +52,30 @@ const buildButtonProps = (name: string, viewUrl: string): ButtonProps => { const hrefTitle = `${encodeURIComponent(name)}`; let href = `abp:subscribe?location=${hrefLocation}&title=${hrefTitle}`; - const defaultTitle = (prefix?: string) => `${prefix || ""}Subscribe to ${name} with a browser extension supporting the "abp:" protocol (e.g. uBlock Origin, Adblock Plus).`; - let title: string; + let prefixes: string[] = []; + let message = `Subscribe to ${name} with a browser extension supporting the "abp:" protocol (e.g. uBlock Origin, Adblock Plus).`; - switch (true) { - - // HTTP protocols - case viewUrl.includes(".onion/"): - type = "dashed"; - title = defaultTitle("Tor address - "); - break; - case viewUrl.includes("http://"): - type = "danger"; - title = defaultTitle("Not Secure - "); - break; - - // Software protocols - case viewUrl.includes(".tpl"): - href = `javascript:window.external.msAddTrackingProtectionList('${hrefLocation}', '${hrefTitle}')`; - title = `Subscribe to ${name} with Internet Explorer's Tracking Protection List feature.`; - break; - case viewUrl.includes(".lsrules"): - href = `x-littlesnitch:subscribe-rules?url=${hrefLocation}`; - title = `Subscribe to ${name} with Little Snitch's rule group subscription feature.`; - break; - case viewUrl.includes("?hostformat=littlesnitch"): - href = `x-littlesnitch:subscribe-rules?url=${hrefLocation}`; - title = `Subscribe to ${name} with Little Snitch's rule group subscription feature.`; - break; - default: - title = defaultTitle(); - break; + // HTTP protocols + if (viewUrl.includes(".onion/")) { + type = "dashed"; + prefixes.push("Tor"); + } + if (viewUrl.includes("http://")) { + type = "danger"; + prefixes.push("Insecure"); } - return { type, href, title } as ButtonProps + // Software protocols + if (viewUrl.includes(".tpl")) { + href = `javascript:window.external.msAddTrackingProtectionList('${hrefLocation}', '${hrefTitle}')`; + message = `Subscribe to ${name} with Internet Explorer's Tracking Protection List feature.`; + } + if (viewUrl.includes(".lsrules") || viewUrl.includes("?hostformat=littlesnitch")) { + href = `x-littlesnitch:subscribe-rules?url=${hrefLocation}`; + message = `Subscribe to ${name} with Little Snitch's rule group subscription feature.`; + } + + const title = `${prefixes.length ? prefixes.join(" | ") : ""}${message}`; + + return { type, href, title } }