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}
WHERE "userId" = $1
AND "lastStatus" = 'Answered'
ORDER BY "asOf" DESC`)).rows,
ORDER BY "asOf" DESC`,
[ userId ])).rows,
/**
* 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) => {
ctx.body = await db.request.answered(ctx.state.user.sub)
ctx.response.status = 200
await next()
})

View File

@ -1,18 +1,30 @@
<template lang="pug">
article
page-title(title='Answered Requests')
p(v-if='!loaded') Loading answered requests...
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>
<script>
'use static'
import Vue from 'vue'
import FullRequest from './request/FullRequest'
import api from '@/api'
export default {
name: 'answered',
data () {
return {
eventBus: new Vue(),
requests: [],
loaded: false
}
@ -25,14 +37,24 @@ export default {
this.$Progress.finish()
} catch (err) {
console.error(err)
this.$message({
message: 'Error loading requests; check console for details',
type: 'error'
})
this.toast.showToast('Error loading requests; check console for details', { theme: 'danger' })
this.$Progress.fail()
} finally {
this.loaded = true
}
},
components: {
FullRequest
},
computed: {
toast () {
return this.$parent.$refs.toast
}
},
methods: {
showFull (requestId) {
this.eventBus.$emit('full', requestId)
}
}
}
</script>

View File

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

View File

@ -1,5 +1,5 @@
<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-navbar-brand(to='/')
span(style='font-weight:100;') my

View File

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

View File

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

View File

@ -33,7 +33,12 @@ const logError = function (error) {
export default new Vuex.Store({
state: {
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: {},
isLoadingJournal: false
},