From a397b170abb3180e75003a3930823d4d1da849f2 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 29 Nov 2022 06:39:49 +0000 Subject: [PATCH] feat: enable mock account for deploy previews (#211) --- composables/dialog.ts | 2 +- composables/users.ts | 7 ++++--- nuxt.config.ts | 9 +++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/composables/dialog.ts b/composables/dialog.ts index 4b212b6a..590b2c3e 100644 --- a/composables/dialog.ts +++ b/composables/dialog.ts @@ -5,7 +5,7 @@ import { STORAGE_KEY_FIRST_VISIT, STORAGE_KEY_ZEN_MODE } from '~/constants' export const imagePreview = ref({ src: '', alt: '' }) export const statusEdit = ref() export const dialogDraftKey = ref() -export const isFirstVisit = useLocalStorage(STORAGE_KEY_FIRST_VISIT, true) +export const isFirstVisit = useLocalStorage(STORAGE_KEY_FIRST_VISIT, !process.mock) export const isZenMode = useLocalStorage(STORAGE_KEY_ZEN_MODE, false) export const toggleZenMode = useToggle(isZenMode) diff --git a/composables/users.ts b/composables/users.ts index fce93f7f..e687323e 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -4,9 +4,10 @@ import { clearUserDrafts } from './statusDrafts' import type { UserLogin } from '~/types' import { DEFAULT_POST_CHARS_LIMIT, DEFAULT_SERVER, STORAGE_KEY_CURRENT_USER, STORAGE_KEY_SERVERS, STORAGE_KEY_USERS } from '~/constants' -const users = useLocalStorage(STORAGE_KEY_USERS, [], { deep: true }) -const servers = useLocalStorage>(STORAGE_KEY_SERVERS, {}, { deep: true }) -const currentUserId = useLocalStorage(STORAGE_KEY_CURRENT_USER, '') +const mock = process.mock +const users = useLocalStorage(STORAGE_KEY_USERS, mock ? [mock.user] : [], { deep: true }) +const servers = useLocalStorage>(STORAGE_KEY_SERVERS, mock ? mock.server : {}, { deep: true }) +const currentUserId = useLocalStorage(STORAGE_KEY_CURRENT_USER, mock ? mock.user.account.id : '') export const currentUser = computed(() => { let user: UserLogin | undefined diff --git a/nuxt.config.ts b/nuxt.config.ts index eae115dd..d0dfc4c3 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -31,6 +31,7 @@ export default defineNuxtConfig({ define: { 'import.meta.env.__BUILD_TIME__': JSON.stringify(new Date().toISOString()), 'process.env.VSCODE_TEXTMATE_DEBUG': 'false', + 'process.mock': isCI && process.env.PULL_REQUEST === 'true' && process.env.MOCK_USER, }, build: { target: 'esnext', @@ -95,3 +96,11 @@ export default defineNuxtConfig({ defaultLocale: 'en-US', }, }) + +declare global { + namespace NodeJS { + interface Process { + mock?: Record + } + } +}