@@ -9,7 +9,6 @@ import { motion } from 'framer-motion'
9
9
import dynamic from 'next/dynamic'
10
10
import { Inter } from 'next/font/google'
11
11
import { useRef , useState } from 'react'
12
-
13
12
const Spline = dynamic ( ( ) => import ( '@splinetool/react-spline' ) )
14
13
const inter = Inter ( { variable : '--font-inter' , subsets : [ 'latin' ] } )
15
14
@@ -52,10 +51,11 @@ const chat = {
52
51
}
53
52
54
53
const SPLINE_SCENE = 'https://prod.spline.design/W83XdmrQbaQnPMlJ/scene.splinecode'
54
+ const SPLINE_BOT_ID = '7a1937ee-e0ec-4da1-bca9-10b1ff105490'
55
55
56
56
const Home = ( ) => {
57
57
const [ selected , setSelected ] = useState < string | null > ( null )
58
- const [ chatToggle , setChatToggle ] = useState < boolean > ( false )
58
+ const [ isBotChangeOpened , setIsBotChangeOpened ] = useState < boolean > ( false )
59
59
60
60
const handleNavSelect = ( name : string ) => {
61
61
if ( selected === name ) {
@@ -71,11 +71,17 @@ const Home = () => {
71
71
72
72
const onLoad = ( spline : Application ) => {
73
73
splineRef . current = spline
74
- const botObj = spline . findObjectByName ( 'Character' )
74
+ const botObj = spline . findObjectByName ( SPLINE_BOT_ID )
75
75
botObj ?. emitEvent ( 'mouseDown' )
76
76
botRef . current = botObj
77
77
}
78
78
79
+ const toggleChat = ( ) => {
80
+ ! ! isBotChangeOpened
81
+ ? splineRef . current ?. emitEventReverse ( 'mouseDown' , SPLINE_BOT_ID )
82
+ : splineRef . current ?. emitEvent ( 'mouseDown' , SPLINE_BOT_ID )
83
+ setIsBotChangeOpened ( ! isBotChangeOpened )
84
+ }
79
85
return (
80
86
< main className = { inter . variable } >
81
87
< div className = "w-full h-[100vh] flex justify-center relative overflow-hidden" >
@@ -86,17 +92,10 @@ const Home = () => {
86
92
className = "absolute w-full h-full
87
93
flex justify-center items-center z-30 pointer-events-auto"
88
94
>
89
- < Spline
90
- scene = { SPLINE_SCENE }
91
- onLoad = { onLoad }
92
- onMouseDown = { ( e ) => {
93
- botRef . current ?. emitEvent ( 'mouseDown' )
94
- setChatToggle ( ! chatToggle )
95
- } }
96
- />
95
+ < Spline scene = { SPLINE_SCENE } onLoad = { onLoad } />
97
96
</ div >
98
97
99
- < ChatBox isOpen = { chatToggle } />
98
+ < ChatBox isOpen = { isBotChangeOpened } />
100
99
101
100
{ navList . map ( ( nav , i ) => (
102
101
< NavModal selected = { selected === nav . name } { ...nav } key = { `nav-modal-${ nav } -${ i } ` } />
@@ -117,7 +116,9 @@ const Home = () => {
117
116
{ ...nav }
118
117
selected = { selected === nav . name }
119
118
onClick = { ( ) => {
120
- setChatToggle ( false )
119
+ if ( ! ! isBotChangeOpened ) {
120
+ toggleChat ( )
121
+ }
121
122
handleNavSelect ( nav . name )
122
123
} }
123
124
/>
@@ -131,11 +132,11 @@ const Home = () => {
131
132
transition = { { ease : 'easeInOut' , duration : 0.25 * navList . length } }
132
133
>
133
134
< NavItem
135
+ selected = { ! ! isBotChangeOpened }
134
136
{ ...chat }
135
137
onClick = { ( ) => {
136
138
setSelected ( null )
137
- botRef . current ?. emitEventReverse ( 'mouseDown' )
138
- setChatToggle ( ! chatToggle )
139
+ toggleChat ( )
139
140
} }
140
141
/>
141
142
</ motion . div >
0 commit comments