From 78cfc6cf3220fca109471ea415de6c6c19a363d6 Mon Sep 17 00:00:00 2001 From: Ken Eucker Date: Tue, 9 Jan 2024 17:17:45 -0800 Subject: [PATCH 1/3] feat(library): refactor of the store and the published library to be a Vue Plugin includes other fixes, including reducing the amount of time before the service worker checks for updates --- .vscode/settings.json | 4 - package.json | 11 ++- publish.config.ts | 4 +- src/app.ts | 11 ++- src/common/constants.ts | 52 ++++++++++++- src/common/types.ts | 2 +- src/common/utils.ts | 18 ++++- src/components/BikeTagMap.vue | 13 +++- src/components/BikeTagQueue.vue | 19 +---- src/components/QueueView.vue | 12 ++- src/components/ServiceWorker.vue | 2 +- src/index.ts | 47 +++++++++++- src/store/index.ts | 122 +++++++++++++++++-------------- src/views/Play.vue | 8 +- vite.config.ts | 52 +------------ 15 files changed, 230 insertions(+), 147 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 478a8ee2..b34c3577 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,10 +5,6 @@ "source.fixAll.eslint": "explicit", "source.sortImports": "explicit" }, - "i18n-ally.localesPaths": [ - "src/i18n", - "src/i18n/locales" - ], "[vue]": { "editor.defaultFormatter": "Vue.volar" } diff --git a/package.json b/package.json index 2fa9fa5f..5d88002a 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "lint:js": "eslint --ext .ts,.js,.vue src --fix", "lint:style": "stylelint \"./src/**/*.vue\" \"./src/**/*.scss\" --fix", "serve": "vite", - "pub:expose": "mv dist/index.d.ts ./index.d.ts && mv dist/biketag-vue.* ./ && mv dist/components ./components && mv dist/common ./common && mv dist/store ./store", + "pub:expose": "mv dist/index.d.ts ./index.d.ts && mv dist/biketag-vue.* ./ && mv dist/components ./components && mv dist/common ./common && mv dist/store ./store && mv dist/directives ./directives", "pub:clear": "rm -f ./index.d.ts ./biketag-vue.es.js ./biketag-vue.css && rm -rf dist ./components ./common ./store", "pub:build": "vue-tsc && vite build --config publish.config.ts", "build": "vite build", @@ -64,7 +64,10 @@ "vue3-markdown-it": "^1.0.10" }, "peerDependencies": { - "vue": "^3.0.0" + "biketag": "^3.0.0", + "pinia": "^2.0.0", + "vue": "^3.0.0", + "vue-router": "^4.0.0" }, "devDependencies": { "@commitlint/cli": "^16.1.0", @@ -144,10 +147,12 @@ "exports": { ".": { "import": "./biketag-vue.es.js", + "require": "./biketag-vue.umd.js", "types": "./index.d.ts" }, "./biketag-vue.css": { - "import": "./biketag-vue.css" + "import": "./biketag-vue.css", + "require": "./biketag-vue.css" } } } diff --git a/publish.config.ts b/publish.config.ts index a97b216c..faf75ef5 100644 --- a/publish.config.ts +++ b/publish.config.ts @@ -9,11 +9,11 @@ export default defineConfig({ lib: { entry: path.resolve(__dirname, 'src/index.ts'), name: 'BikeTag', - formats: ['es'], + formats: ['es', 'umd'], fileName: (format) => `biketag-vue.${format}.js`, }, rollupOptions: { - external: ['vue'], + external: ['vue', 'vue-router', 'pinia', 'biketag'], output: { assetFileNames: (assetInfo) => { if (assetInfo.name === 'style.css') return 'biketag-vue.css' diff --git a/src/app.ts b/src/app.ts index 2994dc6e..78af5f93 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,15 +1,16 @@ import i18n from '@/i18n' import BootstrapVueNext from 'bootstrap-vue-next' import mitt from 'mitt' +import { createPinia } from 'pinia' import { createApp } from 'vue' import VueGoogleMaps from 'vue-google-maps-community-fork' import VueSocials from 'vue-socials' import { useToast } from 'vue-toast-notification' import VueCookies from 'vue3-cookies' +import { createBikeTag } from '.' import App from './App.vue' import { dynamicFontDirective } from './directives' import router from './router' -import { biketagStore } from './store' // eslint-disable-next-line // @ts-ignore @@ -50,7 +51,12 @@ class BikeTagApp { this.app.use(VueCookies) } router() { - this.app.use(router).use(biketagStore) + this.app.use(router) + } + store() { + this.app + .use(createPinia()) + .use(createBikeTag({ includeComponents: false, includeDirectives: false })) } authentication() { if (isAuthenticationEnabled()) { @@ -101,6 +107,7 @@ class BikeTagApp { this.directives() this.components() this.router() + this.store() this.mount() } } diff --git a/src/common/constants.ts b/src/common/constants.ts index 11e3ac78..22290bcc 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -5,9 +5,10 @@ export const BikeTagDefaults = { gameName: '', host: 'biketag.org', hostKey: 'ItsABikeTagGame', - source: 'sanity', logo: '/images/BikeTag.svg', jingle: 'media/biketag-jingle-1.mp3', + imageSource: 'imgur', + gameSource: 'sanity', store: 'biketag', manifest: { name: 'BikeTag', @@ -22,6 +23,55 @@ export const BikeTagDefaults = { sanityAmbassadorRoleID: 'rol_iET51vzIn8z6Utz0', } +export const BikeTagEnv = { + APP_ID: process.env.APP_ID ?? BikeTagDefaults.appId, + ACCESS_TOKEN: process.env.ACCESS_TOKEN ?? BikeTagDefaults.accessToken, + CONTEXT: process.env.CONTEXT ?? null, + ADMIN_EMAIL: process.env.ADMIN_EMAIL ?? BikeTagDefaults.admingEmail, + AMBASSADOR_ROLE: process.env.AMBASSADOR_ROLE ?? BikeTagDefaults.sanityAmbassadorRoleID, + PLAYER_ROLE: process.env.PLAYER_ROLE ?? BikeTagDefaults.sanityPlayerRoleID, + /* Auth0 Configuration */ + A_AUDIENCE: process.env.A_AUDIENCE ?? null, + A_CID: process.env.A_CID ?? null, + A_DOMAIN: process.env.A_DOMAIN ?? null, + A_M_CS: process.env.A_M_CS ?? null, + A_M_CID: process.env.A_M_CID ?? null, + /* Bugs Configuration */ + B_AKEY: process.env.B_AKEY ?? null, + /* BikeTag Configuration */ + GAME_NAME: process.env.GAME_NAME ?? 'null', + GAME_SOURCE: process.env.GAME_SOURCE ?? null, + HOST: process.env.HOST ?? BikeTagDefaults.host, + HOST_KEY: process.env.HOST_KEY ?? BikeTagDefaults.hostKey, + /* Google Configuration */ + G_AKEY: process.env.G_AKEY ?? process.env.GOOGLE_ACCESS_TOKEN ?? null, + G_CID: process.env.G_CID ?? process.env.GOOGLE_CLIENT_ID ?? null, + G_CSECRET: process.env.G_CSECRET ?? process.env.GOOGLE_CLIENT_SECRET ?? null, + G_EMAIL: process.env.G_EMAIL ?? process.env.GOOGLE_EMAIL_ADDRESS ?? null, + G_PASS: process.env.G_PASS ?? process.env.GOOGLE_PASSWORD ?? null, + G_RTOKEN: process.env.G_RTOKEN ?? process.env.GOOGLE_REFRESH_TOKEN ?? null, + /* Imgur Admin Configuration */ + IA_CID: process.env.IA_CID ?? process.env.IMGUR_ADMIN_CLIENT_ID ?? null, + IA_CSECRET: process.env.IA_CSECRET ?? process.env.IMGUR_ADMIN_CLIENT_SECRET ?? null, + IA_RTOKEN: process.env.IA_RTOKEN ?? process.env.IMGUR_ADMIN_REFRESH_TOKEN ?? null, + IA_TOKEN: process.env.IA_TOKEN ?? process.env.IMGUR_ADMIN_ACCESS_TOKEN ?? null, + /* Imgur Configuration */ + I_CID: process.env.I_CID ?? process.env.IMGUR_CLIENT_ID ?? null, + I_CSECRET: process.env.I_CSECRET ?? process.env.IMGUR_CLIENT_SECRET ?? null, + I_RTOKEN: process.env.I_RTOKEN ?? process.env.IMGUR_REFRESH_TOKEN ?? null, + I_TOKEN: process.env.I_TOKEN ?? process.env.IMGUR_ACCESS_TOKEN ?? null, + /* Sanity Admin Configuration */ + SA_CDN_URL: process.env.SA_CDN_URL ?? BikeTagDefaults.sanityImagesCDNUrl, + SA_DSET: process.env.SA_DSET ?? process.env.SANITY_ADMIN_DATASET ?? null, + SA_PID: process.env.SA_PID ?? process.env.SANITY_ADMIN_PROJECT_ID ?? null, + SA_TOKEN: process.env.SA_TOKEN ?? process.env.SANITY_ADMIN_ACCESS_TOKEN ?? null, + /* Sanity Configuration */ + S_CURL: process.env.S_CURL ?? BikeTagDefaults.sanityImagesCDNUrl, + S_DSET: process.env.S_DSET ?? process.env.SANITY_DATASET ?? null, + S_PID: process.env.S_PID ?? process.env.SANITY_PROJECT_ID ?? null, + S_TOKEN: process.env.S_TOKEN ?? process.env.SANITY_ACCESS_TOKEN ?? null, +} + export const special = [ 'zeroth', 'first', diff --git a/src/common/types.ts b/src/common/types.ts index 6bbdc620..ddf9d79c 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -73,7 +73,7 @@ export interface AmbassadorProfile extends Profile { } export type BikeTagProfile = Partial & Partial export interface BikeTagStoreState { - dataInitialized: boolean + dataLoaded: boolean game: Game allGames: Game[] achievements: Achievement[] diff --git a/src/common/utils.ts b/src/common/utils.ts index de92e51a..0f716551 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -337,9 +337,15 @@ export const getSanityImageUrl = ( } export const getApiUrl = (path = '') => { + if (!window) { + return process.env.CONTEXT === 'dev' + ? `http://localhost:7200/.netlify/functions/${path}` + : `/api/${path}` + } + const url = process.env.CONTEXT === 'dev' - ? `${window.location.protocol}//${window.location.hostname}:7200/.netlify/functions/${path}` + ? `${window?.location?.protocol}//${window?.location?.hostname}:7200/.netlify/functions/${path}` : `/api/${path}` return url @@ -412,3 +418,13 @@ export const isOnline = async (checkExternally = false) => { export const isAuthenticationEnabled = () => !!process.env.A_DOMAIN?.length export const isGmapsEnabled = () => !!process.env.G_AKEY?.length + +export const dequeueErrorNotify = (toast: any) => (error: string) => { + return toast.open({ + message: `dequeue tag error: ${error}`, + type: 'error', + duration: 10000, + timeout: false, + position: 'bottom', + }) +} diff --git a/src/components/BikeTagMap.vue b/src/components/BikeTagMap.vue index 32061975..504d4f2b 100644 --- a/src/components/BikeTagMap.vue +++ b/src/components/BikeTagMap.vue @@ -26,7 +26,12 @@ /> - + @@ -64,10 +69,11 @@