example-mailbox: v3

This commit is contained in:
Yoshua Wuyts
2016-05-12 19:33:52 +07:00
parent 94e8073af1
commit 5219fbafca
6 changed files with 80 additions and 31 deletions
+3 -2
View File
@@ -16,8 +16,9 @@ app.model('sent', require('./models/sent'))
app.router((route) => [ app.router((route) => [
route('/', mainView(nav, mailbox)), route('/', mainView(nav, mailbox)),
route('/:mailbox', mainView(nav, mailbox), [ route('/:mailbox', [
route('/:message_id', mainView(nav, mailbox)) route('/', mainView(nav, mailbox)),
route('/:message', mainView(nav, mailbox))
]) ])
]) ])
+65 -22
View File
@@ -1,40 +1,83 @@
const dateformat = require('dateformat')
const choo = require('../../../') const choo = require('../../../')
module.exports = function (params, state, send) { module.exports = function (params, state, send) {
const mailbox = params.mailbox const mailbox = params.mailbox
const message = params.message
return choo.view` if (mailbox) {
<section> if (message) {
<table> const email = state[mailbox + ':messages'].filter(function (msg) {
${createHeader()} return String(msg.id) === message
${state[mailbox + ':messages'].map(function (msg) { })[0]
return createMessage(msg, mailbox)
})} return choo.view`
</table> <section class="fl mt4 w-80 db">
</section> ${createHeader()}
` ${state[mailbox + ':messages'].map(function (msg) {
return createMessage(msg, mailbox)
})}
${email ? createEmail(email) : 'error: no email found'}
</section>
`
} else {
return choo.view`
<section class="fl mt4 w-80 db">
${createHeader()}
${state[mailbox + ':messages'].map(function (msg) {
return createMessage(msg, mailbox)
})}
</section>
`
}
} else {
return choo.view`
<section>
<p>Select a mailbox</p>
</section>
`
}
} }
function createHeader () { function createHeader () {
return choo.view` return choo.view`
<tr> <div class="db cf w-100">
<th>Data</th> <div class="fl mb3 w-25 mt0 b">Date</th>
<th>Subject</th> <div class="fl mb3 w-25 mt0 b">Subject</th>
<th>From</th> <div class="fl mb3 w-25 mt0 b">From</th>
<th>To</th> <div class="fl mb3 w-25 mt0 b">To</th>
</tr> </div>
` `
} }
function createMessage (message, mailbox) { function createMessage (message, mailbox) {
return choo.view` return choo.view`
<tr> <div class="db cf w-100">
<a href="${'/' + mailbox + '/' + message.id}"> <a href="${'/' + mailbox + '/' + message.id}">
<td>${message.date}</td> <div class="fl mb3 w-25 f6 link">
<td>${message.subject}</td> ${dateformat(message.date, 'mmmm dS')}
<td>${message.from}</td> </div>
<td>${message.to}</td> <div class="fl mb3 w-25 f6 link">${message.subject}</div>
<div class="fl mb3 w-25 f6 link">${message.from}</div>
<div class="fl mb3 w-25 f6 link">${message.to}</div>
</a> </a>
</tr> </div>
`
}
function createEmail (message) {
return choo.view`
<div class="mail">
<dl>
<dt>From</dt>
<dd>${message.from}</dd>
<dt>To</dt>
<dd>${message.to}</dd>
<dt>Date</dt>
<dd>${message.date}</dd>
</dl>
<h4>${message.subject}</h4>
<p>${message.body}</p>
</div>
` `
} }
+5 -3
View File
@@ -6,9 +6,11 @@ module.exports = function (params, state, send) {
const mailbox = params.mailbox const mailbox = params.mailbox
return choo.view` return choo.view`
<aside> <aside class="fl mt4 w-20 db">
<ul> <ul>
<li><h2>Mailboxes</h2></li> <li>
<h2 class="f4 b lh0">Mailbox</h2>
</li>
${mailboxes.map(function (name) { ${mailboxes.map(function (name) {
return createLi(name, state[name + ':messages'], mailbox) return createLi(name, state[name + ':messages'], mailbox)
})} })}
@@ -19,7 +21,7 @@ module.exports = function (params, state, send) {
function createLi (mailbox, messages) { function createLi (mailbox, messages) {
return choo.view` return choo.view`
<li> <li class="mt4 f6">
<a href="/${mailbox}"> <a href="/${mailbox}">
${mailbox.charAt(0).toUpperCase() + mailbox.slice(1)} ${mailbox.charAt(0).toUpperCase() + mailbox.slice(1)}
<span>${messages}</span> <span>${messages}</span>
+2 -1
View File
@@ -14,6 +14,7 @@
"author": "Yoshua Wuyts <i@yoshuawuyts.com>", "author": "Yoshua Wuyts <i@yoshuawuyts.com>",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"css-wipe": "^4.2.1" "css-wipe": "^4.2.1",
"dateformat": "^1.0.12"
} }
} }
+4 -2
View File
@@ -4,8 +4,10 @@ const choo = require('../../../')
module.exports = function (nav, mailbox) { module.exports = function (nav, mailbox) {
return function (params, state, send) { return function (params, state, send) {
return choo.view` return choo.view`
<main class="app"> <main class="mw5 mw7-ns center cf">
<span>URL: ${pathname(state.location) || '/'}</span> <span class="fl mt4 w-100 f4 b">
URL: ${pathname(state.location) || '/'}
</span>
${nav(params, state, send)} ${nav(params, state, send)}
${mailbox(params, state, send)} ${mailbox(params, state, send)}
</main> </main>
+1 -1
View File
@@ -21,7 +21,7 @@
"dependencies": { "dependencies": {
"global": "^4.3.0", "global": "^4.3.0",
"send-action": "^1.1.0", "send-action": "^1.1.0",
"sheet-router": "^2.0.4", "sheet-router": "^2.0.5",
"xtend": "^4.0.1", "xtend": "^4.0.1",
"yo-yo": "^1.2.0" "yo-yo": "^1.2.0"
}, },