Skip to content

Commit c785acf

Browse files
committed
refactor: Use options from schemas
1 parent 2f0ef76 commit c785acf

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

src/hooks/useOptions.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { useMemo, useRef, useEffect, useState } from 'react'
2-
import { BodyShape, PreviewCamera, PreviewEmote, PreviewOptions, PreviewProjection, PreviewType } from '@dcl/schemas'
2+
import {
3+
BodyShape,
4+
PreviewCamera,
5+
PreviewEmote,
6+
PreviewOptions,
7+
PreviewProjection,
8+
PreviewType,
9+
PreviewUnityMode,
10+
} from '@dcl/schemas'
311
import { SocialEmoteAnimation } from '@dcl/schemas/dist/dapps/preview/social-emote-animation'
412
import { parseZoom } from '../lib/zoom'
513
import { useOverrides } from './useOverrides'
614

7-
export enum UnityPreviewMode {
8-
PROFILE = 'profile',
9-
MARKETPLACE = 'marketplace',
10-
AUTHENTICATION = 'authentication',
11-
BUILDER = 'builder',
12-
CONFIGURATOR = 'configurator',
13-
}
14-
1515
export interface OptionsWithSource {
16-
options: PreviewOptions & { mode: UnityPreviewMode | null; disableLoader: boolean }
16+
options: PreviewOptions
1717
overrideSources: Record<string, boolean>
1818
}
1919

@@ -30,13 +30,7 @@ export const useOptions = (): OptionsWithSource => {
3030
}
3131
})
3232

33-
const options = useMemo<
34-
PreviewOptions & {
35-
mode: UnityPreviewMode | null
36-
disableLoader: boolean
37-
socialEmote?: SocialEmoteAnimation | null
38-
}
39-
>(() => {
33+
const options = useMemo<PreviewOptions>(() => {
4034
const autoRotateSpeedParam = searchParams.get('autoRotateSpeed') as string | null
4135
const offsetXParam = searchParams.get('offsetX') as string | null
4236
const offsetYParam = searchParams.get('offsetY') as string | null
@@ -62,11 +56,7 @@ export const useOptions = (): OptionsWithSource => {
6256
}
6357
const centerBoundingBox = searchParams.get('centerBoundingBox') !== 'false'
6458

65-
const options: PreviewOptions & {
66-
mode: UnityPreviewMode | null
67-
disableLoader: boolean
68-
socialEmote?: SocialEmoteAnimation | null
69-
} = {
59+
const options: PreviewOptions = {
7060
contractAddress: searchParams.get('contract')!,
7161
tokenId: searchParams.get('token'),
7262
itemId: searchParams.get('item'),
@@ -115,7 +105,7 @@ export const useOptions = (): OptionsWithSource => {
115105
lockAlpha: lockAlpha === 'true',
116106
lockBeta: lockBeta === 'true',
117107
lockRadius: lockRadius === 'true',
118-
mode: searchParams.get('mode') as UnityPreviewMode | null,
108+
unityMode: searchParams.get('mode') as PreviewUnityMode | null,
119109
disableLoader: searchParams.has('disableLoader'),
120110
username: searchParams.get('username'),
121111
socialEmote: (() => {

src/hooks/useUnityConfig.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ import {
99
EmoteDefinition,
1010
PreviewType,
1111
Avatar,
12+
PreviewUnityMode,
1213
} from '@dcl/schemas'
1314
import { config } from '../config'
1415
import { colorToHex, formatHex } from '../lib/color'
1516
import { fetchItemFromContract, fetchProfile, fetchProfileEntity, sanitizeProfile } from '../lib/config'
16-
import { UnityPreviewMode, useOptions } from './useOptions'
17+
import { useOptions } from './useOptions'
1718
import { isWearable } from '../lib/wearable'
1819
import { isTexture } from '../lib/representation'
1920
import { getWearableRepresentationOrDefault } from '../lib/representation'
2021
import { getRandomDefaultProfile } from '../lib/profile'
2122

2223
export interface UnityPreviewConfig {
2324
background: Background
24-
mode: UnityPreviewMode | null
25+
mode: PreviewUnityMode | null
2526
type: PreviewType
2627
base64: string | null
2728
bodyShape: BodyShape | null
@@ -59,7 +60,7 @@ type QueryParams = {
5960
eyeColor: string
6061
hairColor: string
6162
skinColor: string
62-
mode: UnityPreviewMode | string
63+
mode: PreviewUnityMode | string
6364
camera: PreviewCamera
6465
projection: PreviewProjection
6566
emote: string
@@ -198,7 +199,7 @@ export function useUnityConfig(): [UnityPreviewConfig | null, boolean, string |
198199
})
199200

200201
// Get camera settings
201-
const mode = options.mode || null
202+
const mode = options.unityMode || null
202203
const camera =
203204
options.camera && Object.values(PreviewCamera).includes(options.camera as PreviewCamera)
204205
? (options.camera as PreviewCamera)
@@ -248,7 +249,7 @@ export function useUnityConfig(): [UnityPreviewConfig | null, boolean, string |
248249
const base64s = toQueryArray(options.base64s)
249250

250251
// For configurator mode, only add mode parameter
251-
if (mode === 'configurator') {
252+
if (mode === PreviewUnityMode.CONFIG) {
252253
const queryParams: Partial<QueryParams> = {
253254
mode: toQueryValue(mode || ''),
254255
}

0 commit comments

Comments
 (0)