@@ -58,6 +58,7 @@ import { FormSelectOption } from '../../../../design/components/molecules/Form/a
5858import FormInput from '../../../../design/components/molecules/Form/atoms/FormInput'
5959import { useCloudApi } from '../../../lib/hooks/useCloudApi'
6060import Spinner from '../../../../design/components/atoms/Spinner'
61+ import TableViewContentManagerNewFolderRow from './TableViewContentmanagerNewFolderRow'
6162
6263interface ContentManagerProps {
6364 team : SerializedTeam
@@ -85,7 +86,7 @@ const TableViewContentManager = ({
8586} : ContentManagerProps ) => {
8687 const { translate } = useI18n ( )
8788 const { openContextModal, closeAllModals } = useModal ( )
88- const { createFolder , createDoc } = useCloudApi ( )
89+ const { createDoc } = useCloudApi ( )
8990 const { push } = useRouter ( )
9091 const { preferences, setPreferences } = usePreferences ( )
9192 const [ order , setOrder ] = useState < typeof sortingOrders [ number ] [ 'value' ] > (
@@ -254,37 +255,6 @@ const TableViewContentManager = ({
254255 [ setPreferences ]
255256 )
256257
257- const [ newFolderRowState , setNewFolderRowState ] = useState <
258- 'idle' | 'editing' | 'submitting'
259- > ( 'idle' )
260- const [ newFolderName , setNewFolderName ] = useState ( '' )
261- const compositionStateRef = useRef ( false )
262- const newFolderInputRef = useRef < HTMLInputElement > ( null )
263-
264- useEffect ( ( ) => {
265- if ( newFolderInputRef . current != null && newFolderRowState === 'editing' ) {
266- newFolderInputRef . current . focus ( )
267- }
268- } , [ newFolderRowState ] )
269-
270- const createNewFolder = useCallback ( async ( ) => {
271- setNewFolderRowState ( 'submitting' )
272- if ( currentWorkspaceId != null ) {
273- await createFolder (
274- team ,
275- {
276- folderName : newFolderName ,
277- description : '' ,
278- workspaceId : currentWorkspaceId ,
279- parentFolderId : currentFolderId ,
280- } ,
281- { skipRedirect : true }
282- )
283- }
284- setNewFolderName ( '' )
285- setNewFolderRowState ( 'idle' )
286- } , [ currentWorkspaceId , currentFolderId , createFolder , team , newFolderName ] )
287-
288258 const [ newDocRowState , setNewDocRowState ] = useState <
289259 'idle' | 'editing' | 'submitting'
290260 > ( 'idle' )
@@ -585,58 +555,12 @@ const TableViewContentManager = ({
585555 ) ) }
586556
587557 { currentWorkspaceId != null && (
588- < TableContentManagerRow className = 'content__manager--no-border' >
589- { newFolderRowState === 'idle' ? (
590- < Button
591- className = 'content__manager--no-padding'
592- onClick = { ( ) => {
593- setNewFolderRowState ( 'editing' )
594- } }
595- variant = 'transparent'
596- iconPath = { mdiPlus }
597- >
598- { translate ( lngKeys . ModalsCreateNewFolder ) }
599- </ Button >
600- ) : newFolderRowState === 'editing' ? (
601- < FormInput
602- ref = { newFolderInputRef }
603- value = { newFolderName }
604- onChange = { ( event ) => {
605- setNewFolderName ( event . target . value )
606- } }
607- onCompositionStart = { ( ) => {
608- compositionStateRef . current = true
609- } }
610- onCompositionEnd = { ( ) => {
611- compositionStateRef . current = false
612- if ( newFolderInputRef . current != null ) {
613- newFolderInputRef . current . focus ( )
614- }
615- } }
616- onKeyPress = { ( event ) => {
617- if ( compositionStateRef . current ) {
618- return
619- }
620- switch ( event . key ) {
621- case 'Escape' :
622- event . preventDefault ( )
623- setNewFolderRowState ( 'idle' )
624- setNewFolderName ( '' )
625- return
626- case 'Enter' :
627- event . preventDefault ( )
628- createNewFolder ( )
629- return
630- }
631- } }
632- onBlur = { ( ) => {
633- createNewFolder ( )
634- } }
635- />
636- ) : (
637- < Spinner />
638- ) }
639- </ TableContentManagerRow >
558+ < TableViewContentManagerNewFolderRow
559+ className = 'content__manager--no-border'
560+ team = { team }
561+ folderId = { currentFolderId }
562+ workspaceId = { currentWorkspaceId }
563+ />
640564 ) }
641565 </ >
642566 ) }
0 commit comments