Merge pull request #4041 from overleaf/ae-use-ref-with-autofocus

Rename hooks files and move to shared folder

GitOrigin-RevId: 9659247b5e767197c3e11acc9a3922ecaab49162
This commit is contained in:
Alf Eaton 2021-05-18 11:56:56 +01:00 committed by Copybot
parent f7fd2dec65
commit 8c3578e74b
10 changed files with 13 additions and 11 deletions

View file

@ -13,7 +13,7 @@ import { useApplicationContext } from '../../../shared/context/application-conte
import { useEditorContext } from '../../../shared/context/editor-context' import { useEditorContext } from '../../../shared/context/editor-context'
import { getJSON, postJSON } from '../../../infrastructure/fetch-json' import { getJSON, postJSON } from '../../../infrastructure/fetch-json'
import { appendMessage, prependMessages } from '../utils/message-list-appender' import { appendMessage, prependMessages } from '../utils/message-list-appender'
import useBrowserWindow from '../../../infrastructure/browser-window-hook' import useBrowserWindow from '../../../shared/hooks/use-browser-window'
import { useLayoutContext } from '../../../shared/context/layout-context' import { useLayoutContext } from '../../../shared/context/layout-context'
const PAGE_SIZE = 50 const PAGE_SIZE = 50

View file

@ -12,7 +12,7 @@ import { useDroppable } from '../contexts/file-tree-draggable'
import FileTreeItemInner from './file-tree-item/file-tree-item-inner' import FileTreeItemInner from './file-tree-item/file-tree-item-inner'
import FileTreeFolderList from './file-tree-folder-list' import FileTreeFolderList from './file-tree-folder-list'
import usePersistedState from '../../../infrastructure/persisted-state-hook' import usePersistedState from '../../../shared/hooks/use-persisted-state'
function FileTreeFolder({ name, id, folders, docs, files }) { function FileTreeFolder({ name, id, folders, docs, files }) {
const { t } = useTranslation() const { t } = useTranslation()

View file

@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { useRefWithAutoFocus } from '../../../../infrastructure/auto-focus' import { useRefWithAutoFocus } from '../../../../shared/hooks/use-ref-with-auto-focus'
import { useFileTreeActionable } from '../../contexts/file-tree-actionable' import { useFileTreeActionable } from '../../contexts/file-tree-actionable'

View file

@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import { Button, Modal } from 'react-bootstrap' import { Button, Modal } from 'react-bootstrap'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useRefWithAutoFocus } from '../../../../infrastructure/auto-focus' import { useRefWithAutoFocus } from '../../../../shared/hooks/use-ref-with-auto-focus'
import AccessibleModal from '../../../../shared/components/accessible-modal' import AccessibleModal from '../../../../shared/components/accessible-modal'

View file

@ -13,7 +13,7 @@ import classNames from 'classnames'
import { findInTree } from '../util/find-in-tree' import { findInTree } from '../util/find-in-tree'
import { useFileTreeMutable } from './file-tree-mutable' import { useFileTreeMutable } from './file-tree-mutable'
import { useFileTreeMainContext } from './file-tree-main' import { useFileTreeMainContext } from './file-tree-main'
import usePersistedState from '../../../infrastructure/persisted-state-hook' import usePersistedState from '../../../shared/hooks/use-persisted-state'
const FileTreeSelectableContext = createContext() const FileTreeSelectableContext = createContext()

View file

@ -7,7 +7,7 @@ import PreviewValidationIssue from './preview-validation-issue'
import PreviewDownloadFileList from './preview-download-file-list' import PreviewDownloadFileList from './preview-download-file-list'
import PreviewError from './preview-error' import PreviewError from './preview-error'
import Icon from '../../../shared/components/icon' import Icon from '../../../shared/components/icon'
import usePersistedState from '../../../infrastructure/persisted-state-hook' import usePersistedState from '../../../shared/hooks/use-persisted-state'
function PreviewLogsPane({ function PreviewLogsPane({
logEntries = { all: [], errors: [], warnings: [], typesetting: [] }, logEntries = { all: [], errors: [], warnings: [], typesetting: [] },

View file

@ -2,7 +2,7 @@ import React, { createContext, useCallback, useContext } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import useScopeValue from './util/scope-value-hook' import useScopeValue from './util/scope-value-hook'
import { useApplicationContext } from './application-context' import { useApplicationContext } from './application-context'
import useBrowserWindow from '../../infrastructure/browser-window-hook' import useBrowserWindow from '../hooks/use-browser-window'
export const EditorContext = createContext() export const EditorContext = createContext()

View file

@ -1,5 +1,5 @@
import { useState, useCallback } from 'react' import { useState, useCallback } from 'react'
import localStorage from './local-storage' import localStorage from '../../infrastructure/local-storage'
function usePersistedState(key, defaultValue) { function usePersistedState(key, defaultValue) {
const [value, setValue] = useState(() => { const [value, setValue] = useState(() => {

View file

@ -1,12 +1,14 @@
import { createRef, useEffect } from 'react' import { useRef, useEffect } from 'react'
export function useRefWithAutoFocus() { export function useRefWithAutoFocus() {
const autoFocusedRef = createRef() const autoFocusedRef = useRef()
useEffect(() => { useEffect(() => {
if (autoFocusedRef.current) { if (autoFocusedRef.current) {
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
if (autoFocusedRef.current) autoFocusedRef.current.focus() if (autoFocusedRef.current) {
autoFocusedRef.current.focus()
}
}) })
} }
}, [autoFocusedRef]) }, [autoFocusedRef])