@@ -31,18 +31,20 @@ import {
3131 SandboxAlternative ,
3232} from './elements' ;
3333import { TemplateList } from './TemplateList' ;
34- import { useTemplateCollections } from './hooks/useTemplateCollections' ;
35- import { useOfficialTemplates } from './hooks/useOfficialTemplates' ;
3634import { useTeamTemplates } from './hooks/useTeamTemplates' ;
3735import { CreateParams , SandboxToFork } from './utils/types' ;
3836import { SearchBox } from './SearchBox' ;
3937import { ImportTemplate } from './ImportTemplate' ;
40- import { CreateBoxForm , PrivacyLevel } from './CreateBox/CreateBoxForm' ;
38+ import { CreateBoxForm } from './CreateBox/CreateBoxForm' ;
4139import { TemplateInfo } from './CreateBox/TemplateInfo' ;
42- import { useFeaturedTemplates } from './hooks/useFeaturedTemplates' ;
43- import { useAllTemplates } from './hooks/useAllTemplates' ;
44- import { mapSandboxGQLResponseToSandboxToFork } from './utils/api' ;
40+ import {
41+ getTemplatesInCollections ,
42+ getAllMatchingTemplates ,
43+ mapSandboxGQLResponseToSandboxToFork ,
44+ parsePrivacy ,
45+ } from './utils/api' ;
4546import { WorkspaceSelect } from '../WorkspaceSelect' ;
47+ import { FEATURED_IDS } from './utils/constants' ;
4648
4749type CreateBoxProps = ModalContentProps & {
4850 collectionId ?: string ;
@@ -51,30 +53,19 @@ type CreateBoxProps = ModalContentProps & {
5153 isStandalone ?: boolean ;
5254} ;
5355
54- function parsePrivacy ( privacy : string | undefined ) : PrivacyLevel | undefined {
55- if ( privacy === 'public' ) {
56- return 0 ;
57- }
58-
59- if ( privacy === 'unlisted' ) {
60- return 1 ;
61- }
62-
63- if ( privacy === 'private' ) {
64- return 2 ;
65- }
66-
67- return undefined ;
68- }
69-
7056export const CreateBox : React . FC < CreateBoxProps > = ( {
7157 collectionId : initialCollectionId ,
7258 sandboxIdToFork,
7359 type = 'devbox' ,
7460 closeModal,
7561 isStandalone,
7662} ) => {
77- const { hasLogIn, activeTeam } = useAppState ( ) ;
63+ const {
64+ hasLogIn,
65+ activeTeam,
66+ officialDevboxTemplates,
67+ officialSandboxTemplates,
68+ } = useAppState ( ) ;
7869 const effects = useEffects ( ) ;
7970 const actions = useActions ( ) ;
8071 const { isFrozen } = useWorkspaceLimits ( ) ;
@@ -106,32 +97,44 @@ export const CreateBox: React.FC<CreateBoxProps> = ({
10697 false
10798 ) ;
10899
109- const { collections } = useTemplateCollections ( { type } ) ;
110- const { templates : officialTemplates } = useOfficialTemplates ( { type } ) ;
100+ const officialTemplates =
101+ type === 'devbox' ? officialDevboxTemplates : officialSandboxTemplates ;
102+
103+ const collections = getTemplatesInCollections ( officialTemplates , [
104+ { tag : 'frontend' , title : 'Frontend frameworks' } ,
105+ { tag : 'backend' , title : 'Backend frameworks' } ,
106+ { tag : 'playground' , title : 'Code playgrounds' } ,
107+ { tag : 'starter' , title : 'Project starters' } ,
108+ ] ) ;
109+
111110 const { teamTemplates, recentTemplates } = useTeamTemplates ( {
112111 teamId : activeTeam ,
113112 hasLogIn,
114113 type,
115114 } ) ;
116115
117116 const recentlyUsedTemplates = recentTemplates . slice ( 0 , 3 ) ;
118- const featuredTemplates = useFeaturedTemplates ( {
119- officialTemplates,
120- recentTemplates,
121- } ) ;
117+ const hasRecentlyUsedTemplates = recentlyUsedTemplates . length > 0 ;
118+ const recentlyUsedTemplatesIds = recentlyUsedTemplates . map ( t => t . id ) ;
122119
123- const allTemplates = useAllTemplates ( {
124- featuredTemplates,
120+ const featuredTemplates = FEATURED_IDS . map ( id =>
121+ officialTemplates . find (
122+ t => t . id === id && ! recentlyUsedTemplatesIds . includes ( t . id )
123+ )
124+ )
125+ . filter ( Boolean )
126+ . slice ( 0 , hasRecentlyUsedTemplates ? 6 : 9 ) ;
127+
128+ const allTemplates = getAllMatchingTemplates ( {
125129 officialTemplates,
126130 teamTemplates,
127- collections,
128131 searchQuery,
129132 } ) ;
130133
131134 /**
132135 * Only show the team templates if the list is populated.
133136 */
134- const hasRecentlyUsedTemplates = recentlyUsedTemplates . length > 0 ;
137+
135138 const showTeamTemplates = teamTemplates . length > 0 ;
136139 const showImportTemplates = hasLogIn && activeTeam && type === 'devbox' ;
137140
@@ -224,7 +227,8 @@ export const CreateBox: React.FC<CreateBoxProps> = ({
224227 const selectTemplate = ( sandbox : SandboxToFork , trackingSource : string ) => {
225228 if ( ! hasLogIn ) {
226229 // Open template in editor for anonymous users
227- window . location . href = sandboxUrl ( sandbox , hasBetaEditorExperiment ) ;
230+ window . location . href =
231+ sandbox . editorUrl || sandboxUrl ( sandbox , hasBetaEditorExperiment ) ;
228232 return ;
229233 }
230234
@@ -239,7 +243,8 @@ export const CreateBox: React.FC<CreateBoxProps> = ({
239243 } ;
240244
241245 const openTemplate = ( sandbox : SandboxToFork , trackingSource : string ) => {
242- const url = sandboxUrl ( sandbox , hasBetaEditorExperiment ) ;
246+ const url =
247+ sandbox . editorUrl || sandboxUrl ( sandbox , hasBetaEditorExperiment ) ;
243248 window . open ( url , '_blank' ) ;
244249
245250 track ( `Create ${ type } - Open template` , {
0 commit comments