From f019b61f40cdf3feb15e0ca6ecd47ca436176f03 Mon Sep 17 00:00:00 2001 From: Ken Eucker Date: Tue, 9 Jan 2024 11:12:17 -0800 Subject: [PATCH] feat(store): cleanup of the store and now all constants are in a common/constants.ts file This update is going to be a major breaking version simply to begin the process of matching the version numbers of this project with the biketag-api project, and the current version of this project (3.2.7). BREAKING CHANGE: The store is now present in the component library. --- README.md | 2 +- package.json | 3 +- src/App.vue | 1 - src/app.ts | 4 +- src/common/constants.ts | 47 ++++++++ src/common/index.ts | 1 + src/common/types.ts | 55 +++------- src/common/utils.ts | 14 +-- src/components/BikeTagQueue.vue | 4 +- src/components/QueuePostedShare.vue | 2 +- src/components/QueueSubmit.vue | 8 +- src/components/QueueView.vue | 6 +- src/index.ts | 3 +- src/store/index.ts | 163 ++++++++++++---------------- src/views/Play.vue | 44 ++++---- src/views/Round.vue | 8 +- vite.config.ts | 69 ++++++------ 17 files changed, 220 insertions(+), 214 deletions(-) create mode 100644 src/common/constants.ts diff --git a/README.md b/README.md index 8f209fb0..e82519bf 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Below you will find some of the primary settings for testing all features of the ```sh #.env # Used for internal authentication -SUPER_ADMIN=admin@email.com +ADMIN_EMAIL=admin@email.com HOST_KEY=anythingyouwantititobe ACCESS_TOKEN=BIKETAGACCESSTOKEN # Used for uploading new BikeTag posts diff --git a/package.json b/package.json index b308ea1f..2fa9fa5f 100644 --- a/package.json +++ b/package.json @@ -143,7 +143,8 @@ "module": "./biketag-vue.es.js", "exports": { ".": { - "import": "./biketag-vue.es.js" + "import": "./biketag-vue.es.js", + "types": "./index.d.ts" }, "./biketag-vue.css": { "import": "./biketag-vue.css" diff --git a/src/App.vue b/src/App.vue index 9f447bf4..4cadf090 100644 --- a/src/App.vue +++ b/src/App.vue @@ -140,7 +140,6 @@ function checkForNewBikeTagPost() { async function created() { const initResults = [] /// Set it first thing - store.SET_DATA_INITIALIZED() const game = await store.setGame() const _gameIsSet = game?.name?.length !== 0 diff --git a/src/app.ts b/src/app.ts index 0cc13016..2994dc6e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -9,7 +9,7 @@ import VueCookies from 'vue3-cookies' import App from './App.vue' import { dynamicFontDirective } from './directives' import router from './router' -import { store } from './store' +import { biketagStore } from './store' // eslint-disable-next-line // @ts-ignore @@ -50,7 +50,7 @@ class BikeTagApp { this.app.use(VueCookies) } router() { - this.app.use(router).use(store) + this.app.use(router).use(biketagStore) } authentication() { if (isAuthenticationEnabled()) { diff --git a/src/common/constants.ts b/src/common/constants.ts new file mode 100644 index 00000000..11e3ac78 --- /dev/null +++ b/src/common/constants.ts @@ -0,0 +1,47 @@ +export const BikeTagDefaults = { + appId: 'com.app.biketag', + accessToken: '8b4e2b86a724bf3f39d6766de6e67212', + admingEmail: 'biketag@biketag.org', + gameName: '', + host: 'biketag.org', + hostKey: 'ItsABikeTagGame', + source: 'sanity', + logo: '/images/BikeTag.svg', + jingle: 'media/biketag-jingle-1.mp3', + store: 'biketag', + manifest: { + name: 'BikeTag', + shortName: 'BikeTag', + description: 'BikeTag is a photo mystery tag game played on bicycles. No login required.', + themeColor: '#000000', + }, + /// TODO: THIS IS BAD + sanityImagesCDNUrl: 'https://cdn.sanity.io/images/', + sanityBaseCDNUrl: 'https://cdn.sanity.io/images/x37ikhvs/production/', + sanityPlayerRoleID: 'rol_pcbQ68Q9L0yn1o3O', + sanityAmbassadorRoleID: 'rol_iET51vzIn8z6Utz0', +} + +export const special = [ + 'zeroth', + 'first', + 'second', + 'third', + 'fourth', + 'fifth', + 'sixth', + 'seventh', + 'eighth', + 'ninth', + 'tenth', + 'eleventh', + 'twelfth', + 'thirteenth', + 'fourteenth', + 'fifteenth', + 'sixteenth', + 'seventeenth', + 'eighteenth', + 'nineteenth', +] +export const deca = ['twent', 'thirt', 'fort', 'fift', 'sixt', 'sevent', 'eight', 'ninet'] diff --git a/src/common/index.ts b/src/common/index.ts index 903c358e..65bbcf27 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -1,3 +1,4 @@ +export * from './constants' export * from './types' export * from './utils' export * from './uuid' diff --git a/src/common/types.ts b/src/common/types.ts index e8f7ad90..6bbdc620 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -1,6 +1,14 @@ -import { Achievement, Game, Player, Tag } from 'biketag/lib/common/schema' +import { + Achievement, + Ambassador, + Game, + Player, + Region, + Setting, + Tag, +} from 'biketag/lib/common/schema' -export type { Achievement, Game, Player, Tag } +export type { Achievement, Ambassador, Game, Player, Region, Setting, Tag } export type DomainInfo = { host: string @@ -8,40 +16,6 @@ export type DomainInfo = { isSubdomain: boolean } -export const BikeTagDefaults = { - gameName: '', - source: 'sanity', - logo: '/images/BikeTag.svg', - jingle: 'media/biketag-jingle-1.mp3', - store: 'biketag', - /// TODO: THIS IS BAD - sanityBaseCDNUrl: 'https://cdn.sanity.io/images/x37ikhvs/production/', -} - -export const special = [ - 'zeroth', - 'first', - 'second', - 'third', - 'fourth', - 'fifth', - 'sixth', - 'seventh', - 'eighth', - 'ninth', - 'tenth', - 'eleventh', - 'twelfth', - 'thirteenth', - 'fourteenth', - 'fifteenth', - 'sixteenth', - 'seventeenth', - 'eighteenth', - 'nineteenth', -] -export const deca = ['twent', 'thirt', 'fort', 'fift', 'sixt', 'sevent', 'eight', 'ninet'] - export interface ProfileMeta { name: string passcode: string @@ -56,7 +30,6 @@ export interface ProfileMeta { skipSteps: boolean } } - export interface AmbassadorMeta extends ProfileMeta { credentials: { imgur: { @@ -99,7 +72,7 @@ export interface AmbassadorProfile extends Profile { zipcode: string } export type BikeTagProfile = Partial & Partial -export interface State { +export interface BikeTagStoreState { dataInitialized: boolean game: Game allGames: Game[] @@ -116,11 +89,11 @@ export interface State { formStep: number playerTag: Tag credentialsFetched: boolean - mostRecentlyViewedTagnumber: BiketagFormSteps + mostRecentlyViewedTagnumber: BiketagQueueFormSteps regionPolyon: any } -export enum BiketagFormSteps { +export enum BiketagQueueFormSteps { viewRound = 0.5, addFoundImage = 1, roundJoined = 1.5, @@ -130,7 +103,7 @@ export enum BiketagFormSteps { shareBikeTagPost = 3.5, } -export enum Settings { +export enum BikeTagSettingsKeys { AutoPost = 'queue::autoPost', Jingle = 'easter::jingle', SupportsReddit = 'social::reddit', diff --git a/src/common/utils.ts b/src/common/utils.ts index eab64776..de92e51a 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -9,11 +9,11 @@ import { useCookies } from 'vue3-cookies' import { BikeTagDefaults, BikeTagProfile, - BiketagFormSteps, + BiketagQueueFormSteps, DomainInfo, deca, special, -} from '../../src/common/types' +} from '../../src/common' export const stringifyNumber = (n: number): string => { if (n < 20) return special[n] @@ -263,16 +263,16 @@ export const GetQueryString = (win: Window, name: string): string | null => { return null } -export const getQueuedTagState = (queuedTag: Tag): BiketagFormSteps => { +export const getQueuedTagState = (queuedTag: Tag): BiketagQueueFormSteps => { const mysteryImageSet = queuedTag.mysteryImageUrl?.length > 0 const foundImageSet = queuedTag.foundImageUrl?.length > 0 - let queuedTagState = BiketagFormSteps.addFoundImage + let queuedTagState = BiketagQueueFormSteps.addFoundImage if (mysteryImageSet && foundImageSet) { - queuedTagState = BiketagFormSteps.roundPosted + queuedTagState = BiketagQueueFormSteps.roundPosted } else { queuedTagState = foundImageSet - ? BiketagFormSteps.addMysteryImage - : BiketagFormSteps.addFoundImage + ? BiketagQueueFormSteps.addMysteryImage + : BiketagQueueFormSteps.addFoundImage } return queuedTagState diff --git a/src/components/BikeTagQueue.vue b/src/components/BikeTagQueue.vue index bdc8b05c..7adeba40 100644 --- a/src/components/BikeTagQueue.vue +++ b/src/components/BikeTagQueue.vue @@ -88,7 +88,7 @@ import { inject, computed, nextTick } from 'vue' import { useRouter } from 'vue-router' import { useBikeTagStore } from '../store/index' -import { BiketagFormSteps } from '../common/types' +import { BiketagQueueFormSteps } from '../common/types' import { useI18n } from 'vue-i18n' import VLazyImage from 'v-lazy-image' @@ -137,7 +137,7 @@ const showNumber = computed(() => (props.size !== 's' ? props.showNumber : false // methods function canReset() { - return getQueuedTagState.value !== BiketagFormSteps.roundPosted + return getQueuedTagState.value !== BiketagQueueFormSteps.roundPosted } async function resetToFound() { await store.fetchCredentials() diff --git a/src/components/QueuePostedShare.vue b/src/components/QueuePostedShare.vue index 54be06aa..b8a5479a 100644 --- a/src/components/QueuePostedShare.vue +++ b/src/components/QueuePostedShare.vue @@ -87,7 +87,7 @@ import { ref, computed, onMounted } from 'vue' import { useRouter } from 'vue-router' import { useBikeTagStore } from '@/store/index' -import { Settings } from '@/common/types' +import { BikeTagSettingsKeys } from '@/common/types' // components import Markdown from 'vue3-markdown-it' diff --git a/src/components/QueueSubmit.vue b/src/components/QueueSubmit.vue index ada6c25f..37b560f2 100644 --- a/src/components/QueueSubmit.vue +++ b/src/components/QueueSubmit.vue @@ -111,7 +111,7 @@