feat: enable mock account for deploy previews (#211)

pull/200/head
Daniel Roe 2022-11-29 06:39:49 +00:00 zatwierdzone przez GitHub
rodzic 0caf7339ef
commit a397b170ab
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 14 dodań i 4 usunięć

Wyświetl plik

@ -5,7 +5,7 @@ import { STORAGE_KEY_FIRST_VISIT, STORAGE_KEY_ZEN_MODE } from '~/constants'
export const imagePreview = ref({ src: '', alt: '' }) export const imagePreview = ref({ src: '', alt: '' })
export const statusEdit = ref<StatusEdit>() export const statusEdit = ref<StatusEdit>()
export const dialogDraftKey = ref<string>() export const dialogDraftKey = ref<string>()
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 isZenMode = useLocalStorage(STORAGE_KEY_ZEN_MODE, false)
export const toggleZenMode = useToggle(isZenMode) export const toggleZenMode = useToggle(isZenMode)

Wyświetl plik

@ -4,9 +4,10 @@ import { clearUserDrafts } from './statusDrafts'
import type { UserLogin } from '~/types' import type { UserLogin } from '~/types'
import { DEFAULT_POST_CHARS_LIMIT, DEFAULT_SERVER, STORAGE_KEY_CURRENT_USER, STORAGE_KEY_SERVERS, STORAGE_KEY_USERS } from '~/constants' import { DEFAULT_POST_CHARS_LIMIT, DEFAULT_SERVER, STORAGE_KEY_CURRENT_USER, STORAGE_KEY_SERVERS, STORAGE_KEY_USERS } from '~/constants'
const users = useLocalStorage<UserLogin[]>(STORAGE_KEY_USERS, [], { deep: true }) const mock = process.mock
const servers = useLocalStorage<Record<string, Instance>>(STORAGE_KEY_SERVERS, {}, { deep: true }) const users = useLocalStorage<UserLogin[]>(STORAGE_KEY_USERS, mock ? [mock.user] : [], { deep: true })
const currentUserId = useLocalStorage<string>(STORAGE_KEY_CURRENT_USER, '') const servers = useLocalStorage<Record<string, Instance>>(STORAGE_KEY_SERVERS, mock ? mock.server : {}, { deep: true })
const currentUserId = useLocalStorage<string>(STORAGE_KEY_CURRENT_USER, mock ? mock.user.account.id : '')
export const currentUser = computed<UserLogin | undefined>(() => { export const currentUser = computed<UserLogin | undefined>(() => {
let user: UserLogin | undefined let user: UserLogin | undefined

Wyświetl plik

@ -31,6 +31,7 @@ export default defineNuxtConfig({
define: { define: {
'import.meta.env.__BUILD_TIME__': JSON.stringify(new Date().toISOString()), 'import.meta.env.__BUILD_TIME__': JSON.stringify(new Date().toISOString()),
'process.env.VSCODE_TEXTMATE_DEBUG': 'false', 'process.env.VSCODE_TEXTMATE_DEBUG': 'false',
'process.mock': isCI && process.env.PULL_REQUEST === 'true' && process.env.MOCK_USER,
}, },
build: { build: {
target: 'esnext', target: 'esnext',
@ -95,3 +96,11 @@ export default defineNuxtConfig({
defaultLocale: 'en-US', defaultLocale: 'en-US',
}, },
}) })
declare global {
namespace NodeJS {
interface Process {
mock?: Record<string, any>
}
}
}