Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick committed Jan 12, 2018
0 parents commit 7a627b8
Show file tree
Hide file tree
Showing 19 changed files with 244 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/.bin/acorn
node_modules/
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "uva-preact",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "eslint src && preact test",
"start": "if-env NODE_ENV=production && npm run -s serve || npm run -s dev",
"build": "preact build",
"serve": "preact build && preact serve",
"dev": "preact watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"eslintConfig": {
"extends": "eslint-config-synacor"
},
"devDependencies": {
"eslint": "^4.15.0",
"eslint-config-synacor": "^2.0.4",
"if-env": "^1.0.0",
"node-sass": "^4.7.2",
"preact-cli": "^2.1.0",
"sass-loader": "^6.0.6"
},
"dependencies": {
"preact": "^8.2.7",
"preact-compat": "^3.17.0",
"preact-router": "^2.6.0"
}
}
Binary file added src/assets/favicon.ico
Binary file not shown.
Binary file added src/assets/icons/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/icons/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/icons/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/icons/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/icons/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/icons/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/components/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { h, Component } from 'preact';
import { Router } from 'preact-router';

import Header from './header';
import Home from '../routes/home';
import Profile from '../routes/profile';
// import Home from 'async!./home';
// import Profile from 'async!./profile';

export default class App extends Component {
/** Gets fired when the route changes.
* @param {Object} event "change" event from [preact-router](http://git.io/preact-router)
* @param {string} event.url The newly routed URL
*/
handleRoute = e => {
this.currentUrl = e.url;
};

render() {
return (
<div id="app">
<Header />
<Router onChange={this.handleRoute}>
<Home path="/" />
<Profile path="/profile/" user="me" />
<Profile path="/profile/:user" />
</Router>
</div>
);
}
}
18 changes: 18 additions & 0 deletions src/components/header/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { h, Component } from 'preact';
import { Link } from 'preact-router/match';
import style from './style';

export default class Header extends Component {
render() {
return (
<header class={style.header}>
<h1>Preact App</h1>
<nav>
<Link activeClassName={style.active} href="/">Home</Link>
<Link activeClassName={style.active} href="/profile">Me</Link>
<Link activeClassName={style.active} href="/profile/john">John</Link>
</nav>
</header>
);
}
}
48 changes: 48 additions & 0 deletions src/components/header/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.header {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 56px;
padding: 0;
background: #673AB7;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
z-index: 50;
}

.header h1 {
float: left;
margin: 0;
padding: 0 15px;
font-size: 24px;
line-height: 56px;
font-weight: 400;
color: #FFF;
}

.header nav {
float: right;
font-size: 100%;
}

.header nav a {
display: inline-block;
height: 56px;
line-height: 56px;
padding: 0 15px;
min-width: 50px;
text-align: center;
background: rgba(255,255,255,0);
text-decoration: none;
color: #FFF;
will-change: background-color;
}

.header nav a:hover,
.header nav a:active {
background: rgba(0,0,0,0.2);
}

.header nav a.active {
background: rgba(0,0,0,0.4);
}
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import './style';
import App from './components/app';

export default App;
19 changes: 19 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Preact PWA",
"short_name": "Preact PWA",
"start_url": "/",
"display": "standalone",
"orientation": "portrait",
"background_color": "#fff",
"theme_color": "#673ab8",
"icons": [{
"src": "/assets/icons/android-chrome-192x192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/assets/icons/android-chrome-512x512.png",
"type": "image/png",
"sizes": "512x512"
}]
}
13 changes: 13 additions & 0 deletions src/routes/home/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { h, Component } from 'preact';
import style from './style';

export default class Home extends Component {
render() {
return (
<div class={style.home}>
<h1>Home</h1>
<p>This is the Home component.</p>
</div>
);
}
}
5 changes: 5 additions & 0 deletions src/routes/home/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.home {
padding: 56px 20px;
min-height: 100%;
width: 100%;
}
47 changes: 47 additions & 0 deletions src/routes/profile/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { h, Component } from 'preact';
import style from './style';

export default class Profile extends Component {
state = {
time: Date.now(),
count: 10
};

// gets called when this route is navigated to
componentDidMount() {
// start a timer for the clock:
this.timer = setInterval(this.updateTime, 1000);
}

// gets called just before navigating away from the route
componentWillUnmount() {
clearInterval(this.timer);
}

// update the current time
updateTime = () => {
this.setState({ time: Date.now() });
};

increment = () => {
this.setState({ count: this.state.count+1 });
};

// Note: `user` comes from the URL, courtesy of our router
render({ user }, { time, count }) {
return (
<div class={style.profile}>
<h1>Profile: {user}</h1>
<p>This is the user profile for a user named { user }.</p>

<div>Current time: {new Date(time).toLocaleString()}</div>

<p>
<button onClick={this.increment}>Click Me</button>
{' '}
Clicked {count} times.
</p>
</div>
);
}
}
5 changes: 5 additions & 0 deletions src/routes/profile/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.profile {
padding: 56px 20px;
min-height: 100%;
width: 100%;
}
20 changes: 20 additions & 0 deletions src/style/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
html, body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
background: #FAFAFA;
font-family: 'Helvetica Neue', arial, sans-serif;
font-weight: 400;
color: #444;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

* {
box-sizing: border-box;
}

#app {
height: 100%;
}

0 comments on commit 7a627b8

Please sign in to comment.