@@ -21,21 +21,32 @@ import { getIconForClass } from '../views/FolderPage/iconMap';
2121import { NewFormFullPage } from '../components/forms/NewForm/NewFormPage' ;
2222
2323/** Start page for instantiating a new Resource from some Class */
24- function New ( ) : JSX . Element {
24+ function NewRoute ( ) : JSX . Element {
2525 const [ classSubject ] = useQueryString ( 'classSubject' ) ;
26+
27+ return (
28+ < ContainerNarrow >
29+ { classSubject ? (
30+ < NewFormFullPage classSubject = { classSubject . toString ( ) } />
31+ ) : (
32+ < NewResourceSelector />
33+ ) }
34+ </ ContainerNarrow >
35+ ) ;
36+ }
37+
38+ function NewResourceSelector ( ) {
2639 const [ parentSubject ] = useQueryString ( 'parentSubject' ) ;
27- // For selecting a class
40+ const { drive } = useSettings ( ) ;
41+ const calculatedParent = parentSubject || drive ;
42+ const parentResource = useResource ( calculatedParent ) ;
43+ const [ error , setError ] = useState < Error | undefined > ( undefined ) ;
2844 const [ classInputValue , setClassInputValue ] = useState < string | undefined > (
2945 undefined ,
3046 ) ;
31- const [ error , setError ] = useState < Error | undefined > ( undefined ) ;
32- const navigate = useNavigate ( ) ;
3347 const classFull = useResource ( classInputValue ) ;
3448 const [ className ] = useString ( classFull , urls . properties . shortname ) ;
35- const { drive } = useSettings ( ) ;
36-
37- const calculatedParent = parentSubject || drive ;
38- const parentResource = useResource ( calculatedParent ) ;
49+ const navigate = useNavigate ( ) ;
3950
4051 const buttons = [
4152 urls . classes . folder ,
@@ -44,7 +55,6 @@ function New(): JSX.Element {
4455 urls . classes . bookmark ,
4556 urls . classes . class ,
4657 urls . classes . property ,
47- urls . classes . importer ,
4858 ] ;
4959
5060 function handleClassSet ( e ) {
@@ -70,52 +80,46 @@ function New(): JSX.Element {
7080 ) ;
7181
7282 return (
73- < ContainerNarrow >
74- { classSubject ? (
75- < NewFormFullPage classSubject = { classSubject . toString ( ) } />
76- ) : (
77- < StyledForm onSubmit = { handleClassSet } >
78- < h1 >
79- Create new resource{ ' ' }
80- { parentSubject && (
81- < >
82- { `under ` }
83- < ResourceInline subject = { parentSubject } />
84- </ >
85- ) }
86- </ h1 >
87- < div >
88- < ResourceSelector
89- setSubject = { setClassInputValue }
90- value = { classInputValue }
91- error = { error }
92- setError = { setError }
93- classType = { urls . classes . class }
94- />
95- </ div >
96- < Row wrapItems >
97- { classInputValue && (
98- < Button onClick = { handleClassSet } > new { className } </ Button >
99- ) }
100- { ! classInputValue && (
101- < >
102- { buttons . map ( classType => (
103- < WrappedButton
104- key = { classType }
105- classType = { classType }
106- parent = { calculatedParent }
107- />
108- ) ) }
109- </ >
110- ) }
111- </ Row >
112- < FileDropzoneInput
113- parentResource = { parentResource }
114- onFilesUploaded = { onUploadComplete }
115- />
116- </ StyledForm >
117- ) }
118- </ ContainerNarrow >
83+ < StyledForm onSubmit = { handleClassSet } >
84+ < h1 >
85+ Create new resource{ ' ' }
86+ { parentSubject && (
87+ < >
88+ { `under ` }
89+ < ResourceInline subject = { parentSubject } />
90+ </ >
91+ ) }
92+ </ h1 >
93+ < div >
94+ < ResourceSelector
95+ setSubject = { setClassInputValue }
96+ value = { classInputValue }
97+ error = { error }
98+ setError = { setError }
99+ classType = { urls . classes . class }
100+ />
101+ </ div >
102+ < Row wrapItems >
103+ { classInputValue && (
104+ < Button onClick = { handleClassSet } > new { className } </ Button >
105+ ) }
106+ { ! classInputValue && (
107+ < >
108+ { buttons . map ( classType => (
109+ < WrappedButton
110+ key = { classType }
111+ classType = { classType }
112+ parent = { calculatedParent }
113+ />
114+ ) ) }
115+ </ >
116+ ) }
117+ </ Row >
118+ < FileDropzoneInput
119+ parentResource = { parentResource }
120+ onFilesUploaded = { onUploadComplete }
121+ />
122+ </ StyledForm >
119123 ) ;
120124}
121125
@@ -125,7 +129,7 @@ const StyledForm = styled.form`
125129 gap: ${ ( { theme } ) => theme . margin } rem;
126130` ;
127131
128- export default New ;
132+ export default NewRoute ;
129133
130134interface WrappedButtonProps {
131135 classType : string ;
0 commit comments