Skip to content

Commit 1489a77

Browse files
committed
docs: bring examples back
1 parent 8acdd55 commit 1489a77

16 files changed

+364
-0
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# required because react-scripts scans *up* the tree from this project and finds
2+
# a conflicting version of eslint in the node_modules dir for js-ipfs.
3+
SKIP_PREFLIGHT_CHECK=true

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
## [0.1.2](https://github.com/ipfs/js-ipfs/compare/example-browser-create-react-app@[email protected]) (2020-04-08)
7+
8+
**Note:** Version bump only for package example-browser-create-react-app
9+
10+
11+
12+
13+
14+
## 0.1.1 (2020-03-31)
15+
16+
**Note:** Version bump only for package example-browser-create-react-app

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
## IPFS React app
2+
3+
A minimal demonstration of how to use js-ipfs in a `create-react-app` generated app.
4+
5+
It boots up a js-ipfs instance via a custom React hook in `./src/hooks/use-ipfs-factory.js`, which is called from `./src/App.js`, which is where the magic happens.
6+
7+
![Screen shot of the js ipfs node id info](./screenshot.png)
8+
9+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). **v2.1.3**
10+
11+
## Before you start
12+
13+
First clone this repo, install dependencies in the project root and build the project.
14+
15+
```console
16+
$ git clone https://github.com/ipfs/js-ipfs.git
17+
$ cd js-ipfs
18+
$ npm install
19+
$ npm run build
20+
```
21+
22+
## Available Scripts
23+
24+
In the project directory, you can run:
25+
26+
### `npm start`
27+
28+
Runs the app in the development mode.<br>
29+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
30+
31+
The page will reload if you make edits.<br>
32+
You will also see any lint errors in the console.
33+
34+
### `npm test`
35+
36+
Launches the test runner in the interactive watch mode.<br>
37+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
38+
39+
### `npm run build`
40+
41+
Builds the app for production to the `build` folder.<br>
42+
It correctly bundles React in production mode and optimizes the build for the best performance.
43+
44+
The build is minified and the filenames include the hashes.<br>
45+
Your app is ready to be deployed!
46+
47+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
48+
49+
### `npm run eject`
50+
51+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
52+
53+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
54+
55+
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
56+
57+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
58+
59+
## Learn More
60+
61+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
62+
63+
To learn React, check out the [React documentation](https://reactjs.org/).
64+
65+
### Code Splitting
66+
67+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
68+
69+
### Analyzing the Bundle Size
70+
71+
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
72+
73+
### Making a Progressive Web App
74+
75+
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
76+
77+
### Advanced Configuration
78+
79+
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
80+
81+
### Deployment
82+
83+
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
84+
85+
### `npm run build` fails to minify
86+
87+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "example-browser-create-react-app",
3+
"version": "1.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"dot-prop": "^5.0.0",
7+
"ipfs": "^0.46.0",
8+
"ipfs-css": "^0.13.1",
9+
"react": "^16.8.6",
10+
"react-dom": "^16.8.6",
11+
"react-scripts": "^3.2.0",
12+
"tachyons": "^4.11.1"
13+
},
14+
"devDependencies": {
15+
"test-ipfs-example": "^2.0.3"
16+
},
17+
"scripts": {
18+
"start": "react-scripts start",
19+
"build": "react-scripts build",
20+
"eject": "react-scripts eject",
21+
"test": "test-ipfs-example",
22+
"clean": "rm -rf ./build"
23+
},
24+
"eslintConfig": {
25+
"extends": "react-app"
26+
},
27+
"browserslist": [
28+
">0.2%",
29+
"not dead",
30+
"not ie <= 11",
31+
"not op_mini all"
32+
]
33+
}

public/favicon.ico

33.7 KB
Binary file not shown.

public/index.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta
7+
name="viewport"
8+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
9+
/>
10+
<meta name="theme-color" content="#000000" />
11+
<!--
12+
manifest.json provides metadata used when your web app is added to the
13+
homescreen on Android. See https://developers.google.com/web/fundamentals/web-app-manifest/
14+
-->
15+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
16+
<!--
17+
Notice the use of %PUBLIC_URL% in the tags above.
18+
It will be replaced with the URL of the `public` folder during the build.
19+
Only files inside the `public` folder can be referenced from the HTML.
20+
21+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
22+
work correctly both with client-side routing and a non-root public URL.
23+
Learn how to configure a non-root public URL by running `npm run build`.
24+
-->
25+
<title>IPFS React App</title>
26+
</head>
27+
<body>
28+
<noscript>You need to enable JavaScript to run this app.</noscript>
29+
<div id="root"></div>
30+
<!--
31+
This HTML file is a template.
32+
If you open it directly in the browser, you will see an empty page.
33+
34+
You can add webfonts, meta tags, or analytics to this file.
35+
The build step will place the bundled scripts into the <body> tag.
36+
37+
To begin the development, run `npm start` or `yarn start`.
38+
To create a production bundle, use `npm run build` or `yarn build`.
39+
-->
40+
</body>
41+
</html>

public/manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "IPFS React App",
3+
"name": "IPFS Create React App Example",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": ".",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

screenshot.png

628 KB
Loading

src/App.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react'
2+
import useIpfsFactory from './hooks/use-ipfs-factory.js'
3+
import useIpfs from './hooks/use-ipfs.js'
4+
import logo from './ipfs-logo.svg'
5+
6+
const App = () => {
7+
const { ipfs, ipfsInitError } = useIpfsFactory({ commands: ['id'] })
8+
const id = useIpfs(ipfs, 'id')
9+
return (
10+
<div className='sans-serif'>
11+
<header className='flex items-center pa3 bg-navy bb bw3 b--aqua'>
12+
<a href='https://ipfs.io' title='home'>
13+
<img alt='IPFS logo' src={logo} style={{ height: 50 }} className='v-top' />
14+
</a>
15+
<h1 className='flex-auto ma0 tr f3 fw2 montserrat aqua'>IPFS React</h1>
16+
</header>
17+
<main>
18+
{ipfsInitError && (
19+
<div className='bg-yellow pa4 mw7 center mv4 white'>
20+
Error: {ipfsInitError.message || ipfsInitError}
21+
</div>
22+
)}
23+
{id && <IpfsId {...id} />}
24+
</main>
25+
</div>
26+
)
27+
}
28+
29+
const Title = ({ children }) => {
30+
return (
31+
<h2 className='f5 ma0 pb2 tracked aqua fw4 montserrat'>{children}</h2>
32+
)
33+
}
34+
35+
const IpfsId = (props) => {
36+
if (!props) return null
37+
return (
38+
<section className='bg-snow mw7 center mt5'>
39+
<h1 className='f3 fw4 ma0 pv3 aqua montserrat tc' data-test='title'>Connected to IPFS</h1>
40+
<div className='pa4'>
41+
{['id', 'agentVersion'].map((key) => (
42+
<div className='mb4' key={key}>
43+
<Title>{key}</Title>
44+
<div className='bg-white pa2 br2 truncate monospace' data-test={key}>{props[key]}</div>
45+
</div>
46+
))}
47+
</div>
48+
</section>
49+
)
50+
}
51+
52+
export default App

src/App.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react'
2+
import ReactDOM from 'react-dom'
3+
import App from './App'
4+
5+
it('renders without crashing', () => {
6+
const div = document.createElement('div')
7+
ReactDOM.render(<App />, div)
8+
ReactDOM.unmountComponentAtNode(div)
9+
})

0 commit comments

Comments
 (0)