@@ -35,7 +35,7 @@ import { getDocLinkHref } from '../../Link/DocLink'
3535import PropPicker from '../../Props/PropPicker'
3636import DocTagsList from '../../DocPage/DocTagsList'
3737import { getFormattedBoosthubDateTime } from '../../../lib/date'
38- import { mdiFileDocumentOutline , mdiPlus } from '@mdi/js'
38+ import { mdiFileDocumentOutline } from '@mdi/js'
3939import NavigationItem from '../../../../design/components/molecules/Navigation/NavigationItem'
4040import TableAddPropertyContext from './TableAddPropertyContext'
4141import { TableViewActionsRef } from '../../../lib/hooks/views/tableView'
@@ -48,17 +48,14 @@ import Button from '../../../../design/components/atoms/Button'
4848import TablePropertiesContext from './TablePropertiesContext'
4949import TableViewContentManagerFolderRow from './TableViewContentManagerFolderRow'
5050import TableViewContentManagerRow from './TableViewContentManagerRow'
51- import TableContentManagerRow from './TableContentManagerRow'
5251import { overflowEllipsis } from '../../../../design/lib/styled/styleFunctions'
5352import { usePreferences } from '../../../lib/stores/preferences'
5453import SortingOption , {
5554 sortingOrders ,
5655} from '../../ContentManager/SortingOption'
5756import { FormSelectOption } from '../../../../design/components/molecules/Form/atoms/FormSelect'
58- import FormInput from '../../../../design/components/molecules/Form/atoms/FormInput'
59- import { useCloudApi } from '../../../lib/hooks/useCloudApi'
60- import Spinner from '../../../../design/components/atoms/Spinner'
6157import TableViewContentManagerNewFolderRow from './TableViewContentmanagerNewFolderRow'
58+ import TableViewContentManagerNewDocRow from './TableViewContentManagerNewDocRow'
6259
6360interface ContentManagerProps {
6461 team : SerializedTeam
@@ -86,7 +83,6 @@ const TableViewContentManager = ({
8683} : ContentManagerProps ) => {
8784 const { translate } = useI18n ( )
8885 const { openContextModal, closeAllModals } = useModal ( )
89- const { createDoc } = useCloudApi ( )
9086 const { push } = useRouter ( )
9187 const { preferences, setPreferences } = usePreferences ( )
9288 const [ order , setOrder ] = useState < typeof sortingOrders [ number ] [ 'value' ] > (
@@ -255,36 +251,6 @@ const TableViewContentManager = ({
255251 [ setPreferences ]
256252 )
257253
258- const [ newDocRowState , setNewDocRowState ] = useState <
259- 'idle' | 'editing' | 'submitting'
260- > ( 'idle' )
261- const [ newDocName , setNewDocName ] = useState ( '' )
262- const newDocCompositionStateRef = useRef ( false )
263- const newDocInputRef = useRef < HTMLInputElement > ( null )
264-
265- useEffect ( ( ) => {
266- if ( newDocInputRef . current != null && newDocRowState === 'editing' ) {
267- newDocInputRef . current . focus ( )
268- }
269- } , [ newDocRowState ] )
270-
271- const createNewDoc = useCallback ( async ( ) => {
272- setNewDocRowState ( 'submitting' )
273- if ( currentWorkspaceId != null ) {
274- await createDoc (
275- team ,
276- {
277- title : newDocName ,
278- workspaceId : currentWorkspaceId ,
279- parentFolderId : currentFolderId ,
280- } ,
281- { skipRedirect : true }
282- )
283- }
284- setNewDocName ( '' )
285- setNewDocRowState ( 'idle' )
286- } , [ currentWorkspaceId , createDoc , team , newDocName , currentFolderId ] )
287-
288254 return (
289255 < Container >
290256 < Scroller className = 'cm__scroller' >
@@ -475,56 +441,11 @@ const TableViewContentManager = ({
475441 />
476442 { orderedDocs . length === 0 && < EmptyRow label = 'No Documents' /> }
477443 { currentWorkspaceId != null && (
478- < TableContentManagerRow >
479- { newDocRowState === 'idle' ? (
480- < Button
481- className = 'content__manager--no-padding'
482- variant = 'transparent'
483- iconPath = { mdiPlus }
484- onClick = { ( ) => setNewDocRowState ( 'editing' ) }
485- >
486- { translate ( lngKeys . ModalsCreateNewDocument ) }
487- </ Button >
488- ) : newDocRowState === 'editing' ? (
489- < FormInput
490- ref = { newDocInputRef }
491- value = { newDocName }
492- onChange = { ( event ) => {
493- setNewDocName ( event . target . value )
494- } }
495- onCompositionStart = { ( ) => {
496- newDocCompositionStateRef . current = true
497- } }
498- onCompositionEnd = { ( ) => {
499- newDocCompositionStateRef . current = false
500- if ( newDocInputRef . current != null ) {
501- newDocInputRef . current . focus ( )
502- }
503- } }
504- onKeyPress = { ( event ) => {
505- if ( newDocCompositionStateRef . current ) {
506- return
507- }
508- switch ( event . key ) {
509- case 'Escape' :
510- event . preventDefault ( )
511- setNewDocRowState ( 'idle' )
512- setNewDocName ( '' )
513- return
514- case 'Enter' :
515- event . preventDefault ( )
516- createNewDoc ( )
517- return
518- }
519- } }
520- onBlur = { ( ) => {
521- createNewDoc ( )
522- } }
523- />
524- ) : (
525- < Spinner />
526- ) }
527- </ TableContentManagerRow >
444+ < TableViewContentManagerNewDocRow
445+ team = { team }
446+ workspaceId = { currentWorkspaceId }
447+ folderId = { currentFolderId }
448+ />
528449 ) }
529450
530451 { folders != null && (
0 commit comments