diff --git a/examples/http/client.js b/examples/http/client.js
index 2bdb663..39f45d9 100644
--- a/examples/http/client.js
+++ b/examples/http/client.js
@@ -5,6 +5,7 @@ sf('css-wipe/dest/bundle')
sf('tachyons')
const mainView = require('./views/main')
+const mailbox = require('./elements/mailbox')
const nav = require('./elements/nav')
const app = choo()
@@ -14,9 +15,9 @@ app.model('spam', require('./models/spam'))
app.model('sent', require('./models/sent'))
app.router((route) => [
- route('/', mainView(nav)),
- route('/:mailbox', mainView(nav), [
- route('/:message_id', mainView(nav))
+ route('/', mainView(nav, mailbox)),
+ route('/:mailbox', mainView(nav, mailbox), [
+ route('/:message_id', mainView(nav, mailbox))
])
])
diff --git a/examples/http/elements/mailbox.js b/examples/http/elements/mailbox.js
new file mode 100644
index 0000000..35a7192
--- /dev/null
+++ b/examples/http/elements/mailbox.js
@@ -0,0 +1,40 @@
+const choo = require('../../../')
+
+module.exports = function (params, state, send) {
+ const mailbox = params.mailbox
+
+ return choo.view`
+
+
+ ${createHeader()}
+ ${state[mailbox + ':messages'].map(function (msg) {
+ return createMessage(msg, mailbox)
+ })}
+
+
+ `
+}
+
+function createHeader () {
+ return choo.view`
+
+ | Data |
+ Subject |
+ From |
+ To |
+
+ `
+}
+
+function createMessage (message, mailbox) {
+ return choo.view`
+
+
+ | ${message.date} |
+ ${message.subject} |
+ ${message.from} |
+ ${message.to} |
+
+
+ `
+}
diff --git a/examples/http/elements/nav.js b/examples/http/elements/nav.js
index 14ba03e..5117932 100644
--- a/examples/http/elements/nav.js
+++ b/examples/http/elements/nav.js
@@ -1,14 +1,29 @@
const choo = require('../../../')
+const mailboxes = [ 'inbox', 'spam', 'sent' ]
+
module.exports = function (params, state, send) {
+ const mailbox = params.mailbox
+
return choo.view`
`
}
+
+function createLi (mailbox, messages) {
+ return choo.view`
+
+
+ ${mailbox.charAt(0).toUpperCase() + mailbox.slice(1)}
+ ${messages}
+
+
+ `
+}
diff --git a/examples/http/package.json b/examples/http/package.json
index e7bc1c6..1917536 100644
--- a/examples/http/package.json
+++ b/examples/http/package.json
@@ -4,7 +4,7 @@
"private": "true",
"main": "client.js",
"scripts": {
- "start": "node server.js"
+ "start": "NODE_ENV=development node server.js"
},
"browserify": {
"transform": [
@@ -13,8 +13,7 @@
},
"author": "Yoshua Wuyts ",
"license": "ISC",
- "devDependencies": {
- "css-wipe": "^4.2.1",
- "pathname-match": "^1.1.3"
+ "dependencies": {
+ "css-wipe": "^4.2.1"
}
}
diff --git a/examples/http/server.js b/examples/http/server.js
index 231b770..85d6517 100644
--- a/examples/http/server.js
+++ b/examples/http/server.js
@@ -13,6 +13,8 @@ function createRouter () {
const html = bankai.html({ css: false })
router.on('/', (req, res) => html(req, res).pipe(res))
+ router.on('/:inbox', (req, res) => html(req, res).pipe(res))
+ router.on('/:inbox/:message_id', (req, res) => html(req, res).pipe(res))
const js = bankai.js(browserify, require.resolve('./client.js'))
router.on('/bundle.js', (req, res) => js(req, res).pipe(res))
diff --git a/examples/http/views/main.js b/examples/http/views/main.js
index c0bea4f..da9c243 100644
--- a/examples/http/views/main.js
+++ b/examples/http/views/main.js
@@ -1,23 +1,13 @@
const pathname = require('pathname-match')
const choo = require('../../../')
-module.exports = function (nav) {
+module.exports = function (nav, mailbox) {
return function (params, state, send) {
- console.log(state)
return choo.view`
- URL: ${'/' + pathname(state.location)}
+ URL: ${pathname(state.location) || '/'}
${nav(params, state, send)}
-
-
-
- | Data |
- Subject |
- From |
- To |
-
-
-
+ ${mailbox(params, state, send)}
`
}