First cut of answered requests

- changed import to only bring in church rather than the entire lodash
package
- changed webpack config to exclude moment's locale
- set the bearer token on load if the user is authenticated
This commit is contained in:
Daniel J. Summers 2017-09-30 16:12:14 -05:00
parent 834eaf2416
commit e0d27a708d
8 changed files with 41 additions and 11 deletions

View File

@ -77,7 +77,8 @@ export default function (pool) {
(await pool.query(`${currentRequestSql} (await pool.query(`${currentRequestSql}
WHERE "userId" = $1 WHERE "userId" = $1
AND "lastStatus" = 'Answered' AND "lastStatus" = 'Answered'
ORDER BY "asOf" DESC`)).rows, ORDER BY "asOf" DESC`,
[ userId ])).rows,
/** /**
* Get the "current" version of a request by its Id * Get the "current" version of a request by its Id

View File

@ -47,6 +47,7 @@ export default function (checkJwt) {
}) })
.get('/answered', checkJwt, async (ctx, next) => { .get('/answered', checkJwt, async (ctx, next) => {
ctx.body = await db.request.answered(ctx.state.user.sub) ctx.body = await db.request.answered(ctx.state.user.sub)
ctx.response.status = 200
await next() await next()
}) })

View File

@ -1,18 +1,30 @@
<template lang="pug"> <template lang="pug">
article article
page-title(title='Answered Requests')
p(v-if='!loaded') Loading answered requests... p(v-if='!loaded') Loading answered requests...
div(v-if='loaded') div(v-if='loaded')
p(v-for='req in requests')
b-btn(@click='showFull(req.requestId)' size='sm' variant='outline-secondary')
icon(name='search')
| &nbsp;View Full Request
| &nbsp; &nbsp; {{ req.text }}
full-request(:events='eventBus')
</template> </template>
<script> <script>
'use static' 'use static'
import Vue from 'vue'
import FullRequest from './request/FullRequest'
import api from '@/api' import api from '@/api'
export default { export default {
name: 'answered', name: 'answered',
data () { data () {
return { return {
eventBus: new Vue(),
requests: [], requests: [],
loaded: false loaded: false
} }
@ -25,14 +37,24 @@ export default {
this.$Progress.finish() this.$Progress.finish()
} catch (err) { } catch (err) {
console.error(err) console.error(err)
this.$message({ this.toast.showToast('Error loading requests; check console for details', { theme: 'danger' })
message: 'Error loading requests; check console for details',
type: 'error'
})
this.$Progress.fail() this.$Progress.fail()
} finally { } finally {
this.loaded = true this.loaded = true
} }
},
components: {
FullRequest
},
computed: {
toast () {
return this.$parent.$refs.toast
}
},
methods: {
showFull (requestId) {
this.eventBus.$emit('full', requestId)
}
} }
} }
</script> </script>

View File

@ -21,7 +21,7 @@ article
import Vue from 'vue' import Vue from 'vue'
import { mapState } from 'vuex' import { mapState } from 'vuex'
import _ from 'lodash' import chunk from 'lodash/chunk'
import EditRequest from './request/EditRequest' import EditRequest from './request/EditRequest'
import FullRequest from './request/FullRequest' import FullRequest from './request/FullRequest'
@ -48,7 +48,7 @@ export default {
return `${this.user.given_name}'s Prayer Journal` return `${this.user.given_name}'s Prayer Journal`
}, },
journalCardRows () { journalCardRows () {
return _.chunk(this.journal, 3) return chunk(this.journal, 3)
}, },
toast () { toast () {
return this.$parent.$refs.toast return this.$parent.$refs.toast

View File

@ -1,5 +1,5 @@
<template lang="pug"> <template lang="pug">
b-navbar(toggleable='sm' type='dark' variant='info' fixed='top') b-navbar(toggleable='sm' type='dark' variant='primary' fixed='top')
b-nav-toggle(target='nav_collapse') b-nav-toggle(target='nav_collapse')
b-navbar-brand(to='/') b-navbar-brand(to='/')
span(style='font-weight:100;') my span(style='font-weight:100;') my

View File

@ -1,6 +1,5 @@
<template lang="pug"> <template lang="pug">
span span
b-btn(@click='openDialog()' title='Show History' size='sm' variant='outline-secondary'): icon(name='search')
b-modal(title='Prayer Request History' b-modal(title='Prayer Request History'
v-model='historyVisible' v-model='historyVisible'
size='lg' size='lg'

View File

@ -1,6 +1,7 @@
import Vue from 'vue' import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
import Answered from '@/components/Answered'
import Home from '@/components/Home' import Home from '@/components/Home'
import Journal from '@/components/Journal' import Journal from '@/components/Journal'
import LogOn from '@/components/user/LogOn' import LogOn from '@/components/user/LogOn'
@ -11,6 +12,7 @@ export default new Router({
mode: 'history', mode: 'history',
routes: [ routes: [
{ path: '/', name: 'Home', component: Home }, { path: '/', name: 'Home', component: Home },
{ path: '/answered', name: 'Answered', component: Answered },
{ path: '/journal', name: 'Journal', component: Journal }, { path: '/journal', name: 'Journal', component: Journal },
{ path: '/user/log-on', name: 'LogOn', component: LogOn } { path: '/user/log-on', name: 'LogOn', component: LogOn }
] ]

View File

@ -33,7 +33,12 @@ const logError = function (error) {
export default new Vuex.Store({ export default new Vuex.Store({
state: { state: {
user: JSON.parse(localStorage.getItem('user_profile') || '{}'), user: JSON.parse(localStorage.getItem('user_profile') || '{}'),
isAuthenticated: this.auth0.isAuthenticated(), isAuthenticated: (() => {
if (this.auth0.isAuthenticated()) {
api.setBearer(localStorage.getItem('id_token'))
}
return this.auth0.isAuthenticated()
})(),
journal: {}, journal: {},
isLoadingJournal: false isLoadingJournal: false
}, },