@@ -27,6 +27,7 @@ import {SettingContext} from './contexts/SettingContext';
2727import { HistoryContext } from './contexts/HistoryContext' ;
2828import { EditorContext } from './contexts/EditorContext' ;
2929import NativePreview from './components/NativeMobile' ;
30+ import { TemplateContext } from './contexts/TemplateContext' ;
3031import UpdateChatInput from './components/chatInput/Update' ;
3132import dynamic from "next/dynamic" ;
3233import { getPartCodeUid , setUidAnchorPoint } from './compiler' ;
@@ -81,6 +82,7 @@ function App() {
8182 const [ tabValue , setTabValue ] = useState < string > ( settings . generatedCodeConfig == GeneratedCodeConfig . REACT_NATIVE ? 'native' : 'desktop' )
8283 const [ template , setTemplate ] = useState < any > ( { } ) ;
8384 const [ openDialog , setOpenDialog ] = useState < boolean > ( false ) ;
85+ const { debugTemplate, templateList } = useContext ( TemplateContext ) ;
8486
8587 // Tracks the currently shown version from app history
8688
@@ -110,7 +112,18 @@ function App() {
110112
111113 const templateFn = useDebounceFn ( ( ) => {
112114 const slug = nextRouter . query . slug ;
113- const template = templates . list . find ( item => item . id === slug ) ;
115+ let template = templates . list . find ( item => item . id === slug ) ;
116+ let customTemplate = templateList . find ( item => item . id === slug ) ;
117+ if ( slug ?. includes ( 'debug' ) || customTemplate ) {
118+ const template = slug ?. includes ( 'debug' ) ? debugTemplate : customTemplate as any ;
119+ setGeneratedCode ( template . code ) ;
120+ addHistory ( "create" , updateInstruction , referenceImages , referenceText , template . code , partValue . message ) ;
121+ setAppState ( AppState . CODE_READY ) ;
122+ return ;
123+ }
124+
125+ // templateList
126+
114127 if ( template ) {
115128 setTemplate ( template )
116129 }
@@ -145,7 +158,7 @@ function App() {
145158 } else {
146159 templateFn . run ( ) ;
147160 }
148- } , [ initCreate , dataUrls , initCreateText ] ) ;
161+ } , [ initCreate , dataUrls , initCreateText , template ] ) ;
149162
150163 const takeScreenshot = async ( ) : Promise < string > => {
151164 const iframeElement = document . querySelector (
@@ -200,8 +213,7 @@ function App() {
200213 setAppState ( AppState . CODING ) ;
201214
202215 // Merge settings with params
203- const updatedParams = { ...params , ...settings , slug : nextRouter . query . slug } ;
204-
216+ const updatedParams = { ...params , ...settings , slug : nextRouter . query . slug , template } ;
205217 generateCode (
206218 wsRef ,
207219 updatedParams ,
0 commit comments