Skip to content

Commit

Permalink
wip, breaking out SubscribeButton component
Browse files Browse the repository at this point in the history
ref #467
  • Loading branch information
collinbarrett committed Sep 11, 2018
1 parent 7c3d0c2 commit 2552f5a
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 59 deletions.
61 changes: 2 additions & 59 deletions src/FilterLists.Web/ClientApp/components/ListDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from "react";
import "isomorphic-fetch";
import * as moment from "moment";
import SubscribeButton from "./SubscribeButton";

export default class ListDetails extends React.Component<any, any> {

Expand Down Expand Up @@ -75,9 +76,7 @@ function ListInfo(props: any) {

function ListUrls(props: any) {
return <div className="col-3 p-0 btn-group-vertical justify-content-start d-flex align-items-end">
<SubscribeUrl url={props.details.viewUrl} name={props.details.name}/>
<SubscribeUrlMirror url={props.details.viewUrlMirror1} name={props.details.name}/>
<SubscribeUrlMirror url={props.details.viewUrlMirror2} name={props.details.name}/>
<SubscribeButton details={props.details}/>
<ViewUrl url={props.details.viewUrl} name={props.details.name}/>
<ViewUrlMirror url={props.details.viewUrlMirror1} name={props.details.name}/>
<ViewUrlMirror url={props.details.viewUrlMirror2} name={props.details.name}/>
Expand Down Expand Up @@ -171,62 +170,6 @@ function License(props: any) {
: null;
}

function SubscribeUrl(props: any) {
return props.url.indexOf("https://") === -1
? SubscribeUrlNotSecure()
: props.url.indexOf("web.archive.org") === -1
? SubscribeUrlPrimary()
: SubscribeUrlWayback();

function SubscribeUrlPrimary() {
return <a href={`abp:subscribe?location=${encodeURIComponent(props.url)}&amp;title=${encodeURIComponent(props.name)}`}
className="btn btn-primary btn-block fl-btn-details-action"
title={`Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}>
Subscribe
</a>;
}

function SubscribeUrlWayback() {
return <a href={`abp:subscribe?location=${encodeURIComponent(props.url)}&amp;title=${encodeURIComponent(props.name)}`}
className="btn btn-secondary btn-block fl-btn-details-action"
title={`Archive.org Mirror (Original Offline) - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}>
Subscribe
</a>;
}

function SubscribeUrlNotSecure() {
return <a href={`abp:subscribe?location=${encodeURIComponent(props.url)}&amp;title=${encodeURIComponent(props.name)}`}
className="btn btn-danger btn-block fl-btn-details-action"
title={`Not Secure - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}>
Subscribe
</a>;
}
};

function SubscribeUrlMirror(props: any) {
return props.url
? props.url.indexOf("https://") === -1
? SubscribeUrlNotSecure()
: SubscribeUrlSecondary()
: null;

function SubscribeUrlSecondary() {
return <a href={`abp:subscribe?location=${encodeURIComponent(props.url)}&amp;title=${encodeURIComponent(props.name)}`}
className="btn btn-secondary btn-block fl-btn-details-action"
title={`Mirror - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}>
Subscribe
</a>;
}

function SubscribeUrlNotSecure() {
return <a href={`abp:subscribe?location=${encodeURIComponent(props.url)}&amp;title=${encodeURIComponent(props.name)}`}
className="btn btn-danger btn-block fl-btn-details-action"
title={`Mirrow - Not Secure - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}>
Subscribe
</a>;
}
};

function ViewUrl(props: any) {
return props.url.indexOf("https://") === -1
? ViewUrlNotSecure()
Expand Down
90 changes: 90 additions & 0 deletions src/FilterLists.Web/ClientApp/components/SubscribeButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import * as React from "react";

export default class SubscribeButton extends React.Component<any, any> {

constructor(props: ISubscribeUrlDto) {
super(props);
}

render() {
return <div className="btn-group-vertical" role="group">
<button id="btnGroupDropSubscribe" type="button" className="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Subscribe
</button>
<div className="dropdown-menu" aria-labelledby="btnGroupDropSubscribe">
<SubscribeUrl details={this.props.details} />
<SubscribeUrlMirror details={this.props.details} index={1} />
<SubscribeUrlMirror details={this.props.details} index={2} />
</div>
</div>;
}
}

function SubscribeUrl(props: any) {
return props.details.viewUrl.indexOf("https://") === -1
? SubscribeUrlNotSecure()
: props.details.viewUrl.indexOf("web.archive.org") === -1
? SubscribeUrlPrimary()
: SubscribeUrlWayback();

function SubscribeUrlPrimary() {
return <a href={`abp:subscribe?location=${encodeURIComponent(props.details.viewUrl)}&amp;title=${encodeURIComponent(props.details.name)}`}
className="btn btn-primary btn-block fl-btn-details-action"
title={`Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}>
Subscribe
</a>;
}

function SubscribeUrlWayback() {
return <a href={`abp:subscribe?location=${encodeURIComponent(props.details.viewUrl)}&amp;title=${encodeURIComponent(props.details.name)}`}
className="btn btn-secondary btn-block fl-btn-details-action"
title={`Archive.org Mirror (Original Offline) - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}>
Subscribe
</a>;
}

function SubscribeUrlNotSecure() {
return <a href={`abp:subscribe?location=${encodeURIComponent(props.details.viewUrl)}&amp;title=${encodeURIComponent(props.details.name)}`}
className="btn btn-danger btn-block fl-btn-details-action"
title={`Not Secure - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}>
Subscribe
</a>;
}
};

function SubscribeUrlMirror(props: any, index: number) {
return index === 1
? props.details.viewUrlMirror1
? props.details.viewUrlMirror1.indexOf("https://") === -1
? SubscribeUrlNotSecure(props.details.viewUrlMirror1)
: SubscribeUrlSecondary(props.details.viewUrlMirror1)
: null
: props.details.viewUrlMirror2
? props.details.viewUrlMirror2.indexOf("https://") === -1
? SubscribeUrlNotSecure(props.details.viewUrlMirror2)
: SubscribeUrlSecondary(props.details.viewUrlMirror2)
: null;

function SubscribeUrlSecondary(url: any) {
return <a href={`abp:subscribe?location=${encodeURIComponent(url)}&amp;title=${encodeURIComponent(props.details.name)}`}
className="btn btn-secondary btn-block fl-btn-details-action"
title={`Mirror - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}>
Mirror
</a>;
}

function SubscribeUrlNotSecure(url: any) {
return <a href={`abp:subscribe?location=${encodeURIComponent(url)}&amp;title=${encodeURIComponent(props.details.name)}`}
className="btn btn-danger btn-block fl-btn-details-action"
title={`Mirror - Not Secure - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}>
Mirror
</a>;
}
};

interface ISubscribeUrlDto {
name: string;
viewUrl: string;
viewUrlMirror1: string;
viewUrlMirror2: string;
}

0 comments on commit 2552f5a

Please sign in to comment.