Skip to content

Commit 6a86068

Browse files
committed
Initial Commit
1 parent 41d662c commit 6a86068

10 files changed

+288
-1
lines changed

README.md

+64-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,64 @@
1-
# pictureboardDApp
1+
# svelte app
2+
3+
This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template-webpack.
4+
5+
To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):
6+
7+
```bash
8+
npx degit sveltejs/template-webpack svelte-app
9+
cd svelte-app
10+
```
11+
12+
*Note that you will need to have [Node.js](https://nodejs.org) installed.*
13+
14+
15+
## Get started
16+
17+
Install the dependencies...
18+
19+
```bash
20+
cd svelte-app
21+
npm install
22+
```
23+
24+
...then start webpack:
25+
26+
```bash
27+
npm run dev
28+
```
29+
30+
Navigate to [localhost:8080](http://localhost:8080). You should see your app running. Edit a component file in `src`, save it, and the page should reload with your changes.
31+
32+
33+
## Deploying to the web
34+
35+
### With [now](https://zeit.co/now)
36+
37+
Install `now` if you haven't already:
38+
39+
```bash
40+
npm install -g now
41+
```
42+
43+
Then, from within your project folder:
44+
45+
```bash
46+
now
47+
```
48+
49+
As an alternative, use the [Now desktop client](https://zeit.co/download) and simply drag the unzipped project folder to the taskbar icon.
50+
51+
### With [surge](https://surge.sh/)
52+
53+
Install `surge` if you haven't already:
54+
55+
```bash
56+
npm install -g surge
57+
```
58+
59+
Then, from within your project folder:
60+
61+
```bash
62+
npm run build
63+
surge public
64+
```

package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "svelte-app",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
"cross-env": "^5.2.0",
6+
"css-loader": "^2.1.1",
7+
"mini-css-extract-plugin": "^0.6.0",
8+
"serve": "^11.0.0",
9+
"style-loader": "^0.23.1",
10+
"svelte": "^3.0.0",
11+
"svelte-loader": "2.13.3",
12+
"webpack": "^4.30.0",
13+
"webpack-cli": "^3.3.0",
14+
"webpack-dev-server": "^3.3.1"
15+
},
16+
"scripts": {
17+
"build": "cross-env NODE_ENV=production webpack",
18+
"dev": "webpack-dev-server --content-base public"
19+
},
20+
"dependencies": {
21+
"browser-image-compression": "^1.0.9",
22+
"ipfs-api": "^26.1.2"
23+
}
24+
}

public/favicon.png

3.05 KB
Loading

public/global.css

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
html, body {
2+
position: relative;
3+
width: 100%;
4+
height: 100%;
5+
}
6+
7+
body {
8+
color: #333;
9+
margin: 0;
10+
padding: 8px;
11+
box-sizing: border-box;
12+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
13+
}
14+
15+
a {
16+
color: rgb(0,100,200);
17+
text-decoration: none;
18+
}
19+
20+
a:hover {
21+
text-decoration: underline;
22+
}
23+
24+
a:visited {
25+
color: rgb(0,80,160);
26+
}
27+
28+
label {
29+
display: block;
30+
}
31+
32+
input, button, select, textarea {
33+
font-family: inherit;
34+
font-size: inherit;
35+
padding: 0.4em;
36+
margin: 0 0 0.5em 0;
37+
box-sizing: border-box;
38+
border: 1px solid #ccc;
39+
border-radius: 2px;
40+
}
41+
42+
input:disabled {
43+
color: #ccc;
44+
}
45+
46+
input[type="range"] {
47+
height: 0;
48+
}
49+
50+
button {
51+
background-color: #f4f4f4;
52+
outline: none;
53+
}
54+
55+
button:active {
56+
background-color: #ddd;
57+
}
58+
59+
button:focus {
60+
border-color: #666;
61+
}

public/index.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset='utf8'>
5+
<meta name='viewport' content='width=device-width'>
6+
7+
<title>Svelte app</title>
8+
9+
<link rel='icon' type='image/png' href='favicon.png'>
10+
<link rel='stylesheet' href='global.css'>
11+
<link rel='stylesheet' href='bundle.css'>
12+
</head>
13+
14+
<body>
15+
<script src='bundle.js'></script>
16+
</body>
17+
</html>

src/App.svelte

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<script>
2+
import ipfs from "./ipfs";
3+
4+
let filepreview;
5+
6+
const onSubmit = (e) => {
7+
e.preventDefault();
8+
console.log("Submitted");
9+
ipfs.add(filepreview, (err, hash) => {
10+
if (err) {
11+
return console.log(err);
12+
}
13+
console.log("https://ipfs.infura.io/ipfs/" + hash);
14+
})
15+
}
16+
17+
const fileChange = async (e) => {
18+
e.preventDefault();
19+
const file = e.srcElement.files[0];
20+
filepreview = await readFile(file);
21+
console.log(filepreview);
22+
}
23+
24+
function readFile (file) {
25+
const reader = new FileReader()
26+
return new Promise((resolve, reject) => {
27+
reader.onerror = () => {
28+
reader.abort()
29+
reject(`problem reading file ${file.name}`)
30+
}
31+
reader.onload = () => {
32+
resolve(reader.result)
33+
}
34+
reader.readAsDataURL(file)
35+
})
36+
}
37+
38+
</script>
39+
40+
<style>
41+
h1 {
42+
color: rgb(59, 70, 168);
43+
}
44+
</style>
45+
46+
<h1>Picture board DApp by Jason</h1>
47+
48+
<img src={filepreview} alt="filepreview" />
49+
50+
<form on:submit={onSubmit}>
51+
<input type="file" on:change={fileChange} />
52+
<input type="submit">
53+
</form>

src/files.js

Whitespace-only changes.

src/ipfs.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const IPFS = require('ipfs-api');
2+
const ipfs = new IPFS({host: 'ipfs.infura.io', port:5001, protocol:'https'});
3+
4+
export default ipfs;

src/main.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import App from './App.svelte';
2+
3+
const app = new App({
4+
target: document.body,
5+
6+
});
7+
8+
window.app = app;
9+
10+
export default app;

webpack.config.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2+
const path = require('path');
3+
4+
const mode = process.env.NODE_ENV || 'development';
5+
const prod = mode === 'production';
6+
7+
module.exports = {
8+
entry: {
9+
bundle: ['./src/main.js']
10+
},
11+
resolve: {
12+
alias: {
13+
svelte: path.resolve('node_modules', 'svelte')
14+
},
15+
extensions: ['.mjs', '.js', '.svelte'],
16+
mainFields: ['svelte', 'browser', 'module', 'main']
17+
},
18+
output: {
19+
path: __dirname + '/public',
20+
filename: '[name].js',
21+
chunkFilename: '[name].[id].js'
22+
},
23+
module: {
24+
rules: [
25+
{
26+
test: /\.svelte$/,
27+
use: {
28+
loader: 'svelte-loader',
29+
options: {
30+
emitCss: true,
31+
hotReload: true
32+
}
33+
}
34+
},
35+
{
36+
test: /\.css$/,
37+
use: [
38+
/**
39+
* MiniCssExtractPlugin doesn't support HMR.
40+
* For developing, use 'style-loader' instead.
41+
* */
42+
prod ? MiniCssExtractPlugin.loader : 'style-loader',
43+
'css-loader'
44+
]
45+
}
46+
]
47+
},
48+
mode,
49+
plugins: [
50+
new MiniCssExtractPlugin({
51+
filename: '[name].css'
52+
})
53+
],
54+
devtool: prod ? false: 'source-map'
55+
};

0 commit comments

Comments
 (0)