import { useContext, useId, useRef } from 'react' import { PktButton } from '../../button/Button' import { TFileAttributes, FileItem, PktFileUploadContext, TQueueItemOperation } from '../types' const RENAME_SYMBOL = Symbol('renameFile') const RenameFile = (props: { value: string | undefined; onSave: (newName: string) => void; onCancel: () => void }) => { const inputRef = useRef(null) const inputId = useId() const save = () => { props.onSave(inputRef.current?.value ?? '') } return ( <> { if (e.key === 'Enter') { e.preventDefault() e.stopPropagation() save() } if (e.key === 'Escape') { e.preventDefault() e.stopPropagation() props.onCancel() } }} /> props.onSave(inputRef.current!.value)}> Lagre Avbryt ) } const RenameHiddenInput = (props: { targetFilename: string }) => { const context = useContext(PktFileUploadContext) return } export const renameFileOperation = (attributes: TFileAttributes): TQueueItemOperation => { const targetFilenameAttribute = attributes('targetFilename') return { title: 'Rediger', ariaLabel: 'Rediger filnavn', renderInlineUI: (fileItem: FileItem, closeOperationUi: () => void) => ( { targetFilenameAttribute.set(fileItem.fileId, newName) closeOperationUi() }} onCancel={closeOperationUi} /> ), renderHidden: (fileItem: FileItem) => ( ), symbol: RENAME_SYMBOL, } }