-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: config collapsed, reload button, sw-ready-btn
- Loading branch information
Showing
6 changed files
with
120 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React, { useState } from 'react' | ||
|
||
export interface CollapsibleProps { | ||
children: React.ReactNode | ||
collapsedLabel: string | ||
expandedLabel: string | ||
collapsed: boolean | ||
} | ||
|
||
export function Collapsible ({ children, collapsedLabel, expandedLabel, collapsed }: CollapsibleProps): JSX.Element { | ||
const [cId] = useState(Math.random().toString(36).substring(7)) | ||
const [isCollapsed, setCollapsed] = useState(collapsed) | ||
|
||
return ( | ||
<React.Fragment> | ||
<input type="checkbox" className="dn" name="collapsible" id={`collapsible-${cId}`} onClick={() => { setCollapsed(!isCollapsed) }} /> | ||
<label htmlFor={`collapsible-${cId}`} className="collapsible__item-label db pv3 link black hover-blue pointer blue">{isCollapsed ? collapsedLabel : expandedLabel}</label> | ||
<div className={`bb b--black-20 ${isCollapsed ? 'dn' : ''}`}> | ||
{children} | ||
</div> | ||
</React.Fragment> | ||
) | ||
} |
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,39 @@ | ||
import React, { useContext, useMemo } from 'react' | ||
import { ServiceWorkerContext } from '../context/service-worker-context.tsx' | ||
type ButtonProps = JSX.IntrinsicElements['button'] | ||
|
||
interface ServiceWorkerReadyButtonProps extends ButtonProps { | ||
label: string | ||
waitingLabel?: string | ||
} | ||
|
||
export const ServiceWorkerReadyButton = ({ className, label, waitingLabel, ...props }: ServiceWorkerReadyButtonProps): JSX.Element => { | ||
const { isServiceWorkerRegistered } = useContext(ServiceWorkerContext) | ||
|
||
const buttonClasses = new Set(['button-reset', 'pv3', 'tc', 'bn', 'white', 'w-100', 'cursor-disabled', 'bg-gray']) | ||
if (isServiceWorkerRegistered) { | ||
buttonClasses.delete('bg-gray') | ||
buttonClasses.delete('cursor-disabled') | ||
buttonClasses.add('bg-animate') | ||
buttonClasses.add('bg-black-80') | ||
buttonClasses.add('hover-bg-aqua') | ||
buttonClasses.add('pointer') | ||
} | ||
|
||
const lbl = useMemo(() => { | ||
if (!isServiceWorkerRegistered) { | ||
return waitingLabel ?? label | ||
} | ||
return label | ||
}, [isServiceWorkerRegistered, waitingLabel, label]) | ||
|
||
return ( | ||
<button | ||
disabled={!isServiceWorkerRegistered} | ||
className={`${Array.from(buttonClasses).join(' ')} ${className}`} | ||
{...props} | ||
> | ||
{lbl} | ||
</button> | ||
) | ||
} |
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,35 @@ | ||
import { dnsLinkLabelDecoder, isInlinedDnsLink } from './dns-link-labels.ts' | ||
|
||
export interface UrlParts { | ||
id: string | null | ||
protocol: string | null | ||
parentDomain: string | ||
} | ||
|
||
export function getSubdomainParts (urlString: string): UrlParts { | ||
const labels = new URL(urlString).hostname.split('.') | ||
let id: string | null = null | ||
let protocol: string | null = null | ||
let parentDomain: string = urlString | ||
|
||
// DNS label inspection happens from from right to left | ||
// to work fine with edge cases like docs.ipfs.tech.ipns.foo.localhost | ||
for (let i = labels.length - 1; i >= 0; i--) { | ||
if (labels[i].startsWith('ipfs') || labels[i].startsWith('ipns')) { | ||
protocol = labels[i] | ||
id = labels.slice(0, i).join('.') | ||
parentDomain = labels.slice(i + 1).join('.') | ||
if (protocol === 'ipns' && isInlinedDnsLink(id)) { | ||
// un-inline DNSLink names according to https://specs.ipfs.tech/http-gateways/subdomain-gateway/#host-request-header | ||
id = dnsLinkLabelDecoder(id) | ||
} | ||
break | ||
} | ||
} | ||
|
||
return { | ||
id, | ||
parentDomain, | ||
protocol | ||
} | ||
} |
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