Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add p2p retrieval option #391

Merged
merged 43 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f2dd77d
feat: add config toggle for p2p retrieval
2color Oct 18, 2024
fd3c586
deps: add helia and bump verified fetch
2color Oct 18, 2024
c15199c
feat: load p2p helia
2color Oct 18, 2024
7a103d9
chore: remove console.log
2color Oct 18, 2024
eba97a4
feat: try to make recursive gateways optional
2color Oct 18, 2024
8eb8227
fixup! feat: add config toggle for p2p retrieval
2color Oct 21, 2024
804d098
chore: aegir lint --fix
SgtPooki Oct 21, 2024
a1043b8
chore: install missing deps
SgtPooki Oct 21, 2024
9a5981a
feat: use esbuild for building
SgtPooki Oct 21, 2024
1dec8ec
feat: remove webpack
SgtPooki Oct 21, 2024
ec62f19
test: fix e2e tests
SgtPooki Oct 21, 2024
04ebe4b
chore: remove timeout only required on my network
SgtPooki Oct 21, 2024
e27f549
chore: remove copyfiles
SgtPooki Oct 21, 2024
dcbddbf
chore: suggestions from self code review
SgtPooki Oct 21, 2024
a0df1fd
fix: gateways null when loading sw
SgtPooki Oct 21, 2024
6a47ff4
fix: use code-splitting
SgtPooki Oct 21, 2024
da60eb8
fix: firefox doesn't like ESM service workers
SgtPooki Oct 21, 2024
4225e61
fix: remove type in sw registration
2color Oct 22, 2024
2710f1e
feat: add git version into index.html
2color Oct 22, 2024
af67055
Merge branch 'feat/use-esbuild' into add-p2p
2color Oct 22, 2024
fd05172
Revert "feat: try to make recursive gateways optional"
2color Oct 22, 2024
900e081
fix: bug returning an array with 1 el
2color Oct 22, 2024
fe4f0f1
ui: improve contrast for disabled toggle
2color Oct 22, 2024
11b2aef
feat: add granular config options
2color Oct 22, 2024
6ea4336
test: fix config layout test
2color Oct 22, 2024
93108c1
deps: add missing deps
2color Oct 22, 2024
92eb26d
fix: unused deps
2color Oct 22, 2024
abe705b
Merge remote-tracking branch 'origin/main' into add-p2p
2color Oct 22, 2024
58a5e20
Merge branch 'main' into add-p2p
SgtPooki Oct 22, 2024
89c79a3
fix: make toggles smaller
2color Oct 23, 2024
cf4192c
fix: avoid setting defaults in inputs
2color Oct 23, 2024
2a57da9
feat: allow a single router for now
2color Oct 23, 2024
546b69c
chore: rename to get verified fetch
2color Oct 23, 2024
436e0db
feat: reorder config
2color Oct 23, 2024
c65e971
feat: add additional title
2color Oct 23, 2024
7e7ef6f
fix: break config UI into sections
SgtPooki Oct 23, 2024
a6cd325
chore: output localhost as listening host
SgtPooki Oct 23, 2024
975a51d
Merge remote-tracking branch 'origin/main' into add-p2p
2color Oct 24, 2024
17b5f53
fix: allow multiple routers
2color Oct 24, 2024
d2deff8
fix: run validation onblur to allow editing
2color Oct 24, 2024
565152c
fix: log config as string
2color Oct 24, 2024
6d9b7c6
feat: add ipip-484 filtering to delegated router
2color Oct 24, 2024
e618627
chore: more left padding on input section
SgtPooki Oct 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ if (watchRequested) {
}

if (serveRequested) {
const { host, port } = await ctx.serve({
const { port } = await ctx.serve({
servedir: 'dist',
port: 8345,
host: 'localhost'
})
console.info(`Listening on http://${host}:${port}`)
console.info(`Listening on http://localhost:${port}`)
}
12,572 changes: 9,162 additions & 3,410 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,28 @@
}
},
"dependencies": {
"@helia/verified-fetch": "^1.4.1",
"@libp2p/logger": "^4.0.10",
"@chainsafe/libp2p-noise": "^16.0.0",
"@chainsafe/libp2p-yamux": "^7.0.1",
"@helia/block-brokers": "^4.0.0",
"@helia/delegated-routing-v1-http-api-client": "^4.1.0",
"@helia/http": "^2.0.0",
"@helia/interface": "^5.0.0",
"@helia/routers": "^2.0.0",
"@helia/verified-fetch": "^2.0.0",
"@libp2p/crypto": "^5.0.5",
"@libp2p/dcutr": "^2.0.8",
"@libp2p/identify": "^3.0.8",
"@libp2p/keychain": "^5.0.7",
"@libp2p/logger": "^5.1.1",
"@libp2p/ping": "^2.0.8",
"@libp2p/websockets": "^9.0.8",
"@libp2p/webtransport": "^5.0.13",
"@multiformats/dns": "^1.0.6",
"@sgtpooki/file-type": "^1.0.1",
"debug": "^4.3.4",
"helia": "^5.0.1",
"ipfs-css": "^1.4.0",
"libp2p": "^2.1.9",
"multiformats": "^13.1.0",
"react": "^18.3.0",
"react-dom": "^18.3.1",
Expand Down
9 changes: 9 additions & 0 deletions src/components/input-description.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'

export const InputDescription: React.FC<{ description?: string }> = ({ description }) => {
if (description == null || description.length === 0) {
return null
}

return (<span className="charcoal f6 fw1 db pt1 lh-copy mb2">{description}</span>)
}
5 changes: 5 additions & 0 deletions src/components/input-label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react'

export const InputLabel: React.FC<{ label: string }> = ({ label }) => {
return (<span className='f5 ma0 pt3 teal fw4 db'>{label}</span>)
}
10 changes: 10 additions & 0 deletions src/components/input-section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'

export const InputSection: React.FC<{ label: string, children: React.ReactNode[] }> = ({ label, children }) => {
return (
<div className="bl bw2 br2 b--teal-muted pl2 mb3">
SgtPooki marked this conversation as resolved.
Show resolved Hide resolved
<span className='f3 ma0 teal fw4 db'>{label}</span>
{children}
</div>
)
}
22 changes: 13 additions & 9 deletions src/components/local-storage-input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { useEffect, useState } from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import { InputDescription } from './input-description'
import { InputLabel } from './input-label'

export interface LocalStorageInputProps extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
localStorageKey: string
Expand Down Expand Up @@ -45,35 +47,37 @@ export default ({ resetKey, localStorageKey, label, placeholder, validationFn, d
validationFn = defaultValidationFunction
}

useEffect(() => {
const saveValue = useCallback((e: React.ChangeEvent<HTMLTextAreaElement>) => {
const newValue = e.target.value
try {
const err = validationFn?.(value)
const err = validationFn?.(newValue)
if (err != null) {
throw err
}
localStorage.setItem(localStorageKey, preSaveFormat?.(value) ?? value)
setValue(newValue)
localStorage.setItem(localStorageKey, preSaveFormat?.(newValue) ?? newValue)
setError(null)
} catch (err) {
setError(err as Error)
}
}, [value])
}, [validationFn, localStorageKey, preSaveFormat])

props = {
...props,
className: `${props.className ?? ''} flex-column items-start mb3`
className: `${props.className ?? ''} flex-column items-start`
}

return (
<div {...props}>
<label htmlFor={localStorageKey} className='f5 ma0 pt3 teal fw4 db'>{label}</label>
<span className="charcoal-muted f6 fw1 db pt1 lh-copy">{description}</span>
<InputLabel label={label} />
<InputDescription description={description} />
<textarea
className='input-reset ba br2 b--light-silver code lh-copy black-80 bg-white pa2 w-100 mt2'
id={localStorageKey}
name={localStorageKey}
placeholder={placeholder}
value={value}
onChange={(e) => { setValue(e.target.value) }}
onChange={saveValue}
/>
{error != null && <span className='db lh-copy red pt1 tr f6 w-100'>⬑ {error.message}</span>}
</div>
Expand Down
73 changes: 16 additions & 57 deletions src/components/local-storage-toggle.css
Original file line number Diff line number Diff line change
@@ -1,64 +1,23 @@
/**
Inspiration from https://dev.to/codebubb/create-a-simple-on-off-slide-toggle-with-css-db8
*/

.local-storage-toggle input.status {
display: none;
}
/* .local-storage-toggle input.status + label {
height: 100%;
width: 100%;
} */
.local-storage-toggle input.status + label > .status-switch {
cursor: pointer;
/* width: 100%; */
/* height: 100%; */
position: relative;
background-color: #b7bbc8;
color: white;
transition: all 0.5s ease;
padding: 3px;
border-radius: 3px;
}
.local-storage-toggle input.status + label > .status-switch:before, .local-storage-toggle input.status + label > .status-switch:after {
border-radius: 2px;
height: calc(100% - 6px);
width: calc(50% - 3px);
display: flex;
align-items: center;
position: absolute;
justify-content: center;
transition: all 0.3s ease;
}
.local-storage-toggle input.status + label > .status-switch:before {
background-color: white;
color: black;
box-shadow: 0 0 4px 4px rgba(0, 0, 0, 0.2);
left: 3px;
z-index: 10;
content: attr(data-unchecked);
.transition-all {
transition-property: all;
}
.local-storage-toggle input.status + label > .status-switch:after {
right: 0;
content: attr(data-checked);
/* add strikethrough to show to the user that it's disabled */
text-decoration: line-through;

.transition-transform {
transition-property: transform;
}
.local-storage-toggle input.status:checked + label > .status-switch {
background-color: #40c253;

.duration-200 {
transition-duration: 200ms;
}
.local-storage-toggle input.status:checked + label > .status-switch:after {
left: 0;
content: attr(data-unchecked);
/* add strikethrough to show to the user that it's disabled */
text-decoration: line-through;

.ease-in-out {
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}
.local-storage-toggle input.status:checked + label > .status-switch:before {
color: #40c253;
left: 50%;
content: attr(data-checked);

.translate-x-0 {
transform: translateX(0);
}

.h3-custom {
height: 3rem;
.translate-x-100 {
transform: translateX(100%);
}
60 changes: 49 additions & 11 deletions src/components/local-storage-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,33 @@
*/
import React, { useEffect, useState } from 'react'
import './local-storage-toggle.css'
import { InputDescription } from './input-description'
import { InputLabel } from './input-label'

interface LocalStorageToggleProps extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
interface LocalStorageToggleProps {
label: string
defaultValue: boolean
description?: string
localStorageKey: string
offLabel: string
onLabel: string
className?: string
onClick?: React.MouseEventHandler<HTMLDivElement>
resetKey: number
}

export const LocalStorageToggle: React.FC<LocalStorageToggleProps> = ({ resetKey, localStorageKey, onLabel = 'Off', offLabel = 'On', ...props }) => {
export const LocalStorageToggle: React.FC<LocalStorageToggleProps> = ({
label,
description = '',
defaultValue,
resetKey,
localStorageKey,
...props
}) => {
const [isChecked, setIsChecked] = useState(() => {
const savedValue = localStorage.getItem(localStorageKey)
return savedValue === 'true'
return getLocalStorageValue(localStorageKey, defaultValue)
})

useEffect(() => {
setIsChecked(localStorage.getItem(localStorageKey) === 'true')
setIsChecked(getLocalStorageValue(localStorageKey, defaultValue))
}, [resetKey])

const handleChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
Expand All @@ -28,11 +39,38 @@ export const LocalStorageToggle: React.FC<LocalStorageToggleProps> = ({ resetKey
}

return (
<div {...props} className={`${props.className} local-storage-toggle input-reset bn black-80 w-100 mb3`}>
<input className="status" style={{ display: 'none' }} id={localStorageKey} type="checkbox" name="status" checked={isChecked} onChange={handleChange} />
<label htmlFor={localStorageKey} className="w-100 h-100">
<div className="status-switch relative h3-custom pointer white bg-gray w-100" data-unchecked={offLabel} data-checked={onLabel} />
<div {...props} className={`${props.className}`}>
<InputLabel label={label} />
<InputDescription description={description} />

<input
type="checkbox"
id={localStorageKey}
checked={isChecked}
onChange={handleChange}
className="dn"
/>
<label
htmlFor={localStorageKey}
className={`relative dib h1 w2 flex-shrink-0 pointer br4 ${
isChecked ? 'bg-green' : 'bg-dark-gray'
} transition-all duration-200 ease-in-out`}
>
<span
className={`absolute top-0 left-0 dib h1 w1 br-100 bg-white shadow-1 ${
isChecked ? 'translate-x-100' : 'translate-x-0'
} transition-transform duration-200 ease-in-out`}
/>
</label>
</div>
)
}

function getLocalStorageValue (localStorageKey: string, defaultValue: boolean): boolean {
const savedValue = localStorage.getItem(localStorageKey)
if (savedValue == null) {
return defaultValue
}

return savedValue === 'true'
}
Loading
Loading