From e59472a683f330ae696740ba099d8cd3b6f0a9d5 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Thu, 21 Nov 2019 21:15:00 -0600 Subject: [PATCH] Convert to TS - builds (#36) Liberal use of any, but it builds now; on to actually implementing types... --- .../wwwroot/legacy-assets-index.html.json | 1 - src/app/package.json | 1 + src/app/src/auth/AuthService.ts | 12 +++--- src/app/src/main.ts | 6 +-- src/app/src/router.ts | 37 ++++++++++--------- src/app/src/store/index.ts | 6 ++- src/app/tsconfig.json | 1 + src/app/yarn.lock | 5 +++ 8 files changed, 40 insertions(+), 29 deletions(-) delete mode 100644 src/MyPrayerJournal.Api/wwwroot/legacy-assets-index.html.json diff --git a/src/MyPrayerJournal.Api/wwwroot/legacy-assets-index.html.json b/src/MyPrayerJournal.Api/wwwroot/legacy-assets-index.html.json deleted file mode 100644 index 37bfa35..0000000 --- a/src/MyPrayerJournal.Api/wwwroot/legacy-assets-index.html.json +++ /dev/null @@ -1 +0,0 @@ -[{"tagName":"script","closeTag":true,"attributes":{"type":"text/javascript","src":"/js/chunk-vendors-legacy.fc4b9fd6.js"}},{"tagName":"script","closeTag":true,"attributes":{"type":"text/javascript","src":"/js/app-legacy.7e012dcd.js"}}] \ No newline at end of file diff --git a/src/app/package.json b/src/app/package.json index 99e45a0..9a1bf0e 100644 --- a/src/app/package.json +++ b/src/app/package.json @@ -23,6 +23,7 @@ "vuex": "^3.0.1" }, "devDependencies": { + "@types/auth0-js": "^9.10.6", "@typescript-eslint/eslint-plugin": "^2.8.0", "@typescript-eslint/parser": "^2.8.0", "@vue/cli-plugin-babel": "^4.0.5", diff --git a/src/app/src/auth/AuthService.ts b/src/app/src/auth/AuthService.ts index 2a22bc5..5a1c912 100644 --- a/src/app/src/auth/AuthService.ts +++ b/src/app/src/auth/AuthService.ts @@ -1,7 +1,7 @@ 'use strict' /* eslint-disable */ -import auth0 from 'auth0-js' -import EventEmitter from 'events' +import auth0 from 'auth0-js' +import { EventEmitter } from 'events' import AUTH_CONFIG from './auth0-variables' import mutations from '@/store/mutation-types' @@ -26,7 +26,7 @@ class AuthService extends EventEmitter { AUTH_SESSION = 'auth-session' // Received and calculated values for our ssesion (initially loaded from local storage if present) - session = {} + session: any = {} constructor() { super() @@ -64,7 +64,7 @@ class AuthService extends EventEmitter { */ async handleAuthentication (store) { try { - const authResult = await this.parseHash() + const authResult: any = await this.parseHash() if (authResult && authResult.accessToken && authResult.idToken) { this.setSession(authResult) store.commit(mutations.USER_LOGGED_ON, this.session.profile) @@ -102,7 +102,7 @@ class AuthService extends EventEmitter { refreshSession () { this.session = localStorage.getItem(this.AUTH_SESSION) - ? JSON.parse(localStorage.getItem(this.AUTH_SESSION)) + ? JSON.parse(localStorage.getItem(this.AUTH_SESSION) || '{}') : { profile: {}, id: { token: null, @@ -182,7 +182,7 @@ class AuthService extends EventEmitter { return this.session.access.token } else { try { - const authResult = await this.renewTokens() + const authResult: any = await this.renewTokens() return authResult.accessToken } catch (reject) { throw reject diff --git a/src/app/src/main.ts b/src/app/src/main.ts index f86c531..395b4d7 100644 --- a/src/app/src/main.ts +++ b/src/app/src/main.ts @@ -21,11 +21,11 @@ import { MdApp, MdTooltip } from 'vue-material/dist/components' // myPrayerJournal components -import App from './App' +import App from './App.vue' import router from './router' import store from './store' -import DateFromNow from './components/common/DateFromNow' -import PageTitle from './components/common/PageTitle' +import DateFromNow from './components/common/DateFromNow.vue' +import PageTitle from './components/common/PageTitle.vue' import AuthPlugin from './plugins/auth' /* eslint-enable */ diff --git a/src/app/src/router.ts b/src/app/src/router.ts index b22a227..7143fee 100644 --- a/src/app/src/router.ts +++ b/src/app/src/router.ts @@ -5,12 +5,12 @@ import Vue from 'vue' import Router from 'vue-router' import auth from './auth/AuthService' -import Home from '@/components/Home' +import Home from '@/components/Home.vue' /* eslint-enable */ Vue.use(Router) -export default new Router({ +const router = new Router({ mode: 'history', base: process.env.BASE_URL, scrollBehavior (to, from, savedPosition) { @@ -20,12 +20,6 @@ export default new Router({ return { x: 0, y: 0 } } }, - beforeEach (to, from, next) { - if (to.path === '/' || to.path === '/user/log-on' || auth.isAuthenticated()) { - return next() - } - auth.login({ target: to.path }) - }, routes: [ { path: '/', @@ -35,49 +29,58 @@ export default new Router({ { path: '/journal', name: 'Journal', - component: () => import('@/components/Journal') + component: () => import('@/components/Journal.vue') }, { path: '/legal/privacy-policy', name: 'PrivacyPolicy', - component: () => import('@/components/legal/PrivacyPolicy') + component: () => import('@/components/legal/PrivacyPolicy.vue') }, { path: '/legal/terms-of-service', name: 'TermsOfService', - component: () => import('@/components/legal/TermsOfService') + component: () => import('@/components/legal/TermsOfService.vue') }, { path: '/request/:id/edit', name: 'EditRequest', - component: () => import('@/components/request/EditRequest'), + component: () => import('@/components/request/EditRequest.vue'), props: true }, { path: '/request/:id/full', name: 'FullRequest', - component: () => import('@/components/request/FullRequest'), + component: () => import('@/components/request/FullRequest.vue'), props: true }, { path: '/requests/active', name: 'ActiveRequests', - component: () => import('@/components/request/ActiveRequests') + component: () => import('@/components/request/ActiveRequests.vue') }, { path: '/requests/answered', name: 'AnsweredRequests', - component: () => import('@/components/request/AnsweredRequests') + component: () => import('@/components/request/AnsweredRequests.vue') }, { path: '/requests/snoozed', name: 'SnoozedRequests', - component: () => import('@/components/request/SnoozedRequests') + component: () => import('@/components/request/SnoozedRequests.vue') }, { path: '/user/log-on', name: 'LogOn', - component: () => import('@/components/user/LogOn') + component: () => import('@/components/user/LogOn.vue') } ] }) + +router.beforeEach((to, from, next) => { + if (to.path === '/' || to.path === '/user/log-on' || auth.isAuthenticated()) { + return next() + } + auth.login({ target: to.path }) +}) + +export default router diff --git a/src/app/src/store/index.ts b/src/app/src/store/index.ts index f009869..afd1fc4 100644 --- a/src/app/src/store/index.ts +++ b/src/app/src/store/index.ts @@ -61,11 +61,13 @@ const sortValue = x => x.showAfter === 0 ? x.asOf : x.showAfter */ const journalSort = (a, b) => sortValue(a) - sortValue(b) +const emptyJournal: any = [] + export default new Vuex.Store({ state: { user: auth.session.profile, isAuthenticated: auth.isAuthenticated(), - journal: [], + journal: emptyJournal, isLoadingJournal: false }, mutations: { @@ -137,7 +139,7 @@ export default new Vuex.Store({ progress.$emit('show', 'indeterminate') try { await setBearer() - const oldReq = (state.journal.filter(req => req.requestId === requestId) || [])[0] || {} + const oldReq: any = (state.journal.filter(req => req.requestId === requestId) || [])[0] || {} if (!(status === 'Prayed' && updateText === '')) { if (status !== 'Answered' && (oldReq.recurType !== recurType || oldReq.recurCount !== recurCount)) { await api.updateRecurrence(requestId, recurType, recurCount) diff --git a/src/app/tsconfig.json b/src/app/tsconfig.json index 499f5e2..ff664e8 100644 --- a/src/app/tsconfig.json +++ b/src/app/tsconfig.json @@ -9,6 +9,7 @@ "esModuleInterop": true, "allowSyntheticDefaultImports": true, "sourceMap": true, + "noImplicitAny": false, "baseUrl": ".", "types": [ "webpack-env" diff --git a/src/app/yarn.lock b/src/app/yarn.lock index d6e4383..9ccf633 100644 --- a/src/app/yarn.lock +++ b/src/app/yarn.lock @@ -781,6 +781,11 @@ error-stack-parser "^2.0.0" string-width "^2.0.0" +"@types/auth0-js@^9.10.6": + version "9.10.6" + resolved "https://registry.yarnpkg.com/@types/auth0-js/-/auth0-js-9.10.6.tgz#9782ac28ea9cff5a2594b780fd3fd0caa615d1e6" + integrity sha512-tPdhjqzQRJOdILFLssr/zrinjNvYsKKrEzS74XK80ZkQJKejjTERbIh3+T5niFKxx3XYPB3140ys8Y4Q2UFwHw== + "@types/babel-types@*", "@types/babel-types@^7.0.0": version "7.0.7" resolved "https://registry.yarnpkg.com/@types/babel-types/-/babel-types-7.0.7.tgz#667eb1640e8039436028055737d2b9986ee336e3"