Optimised mode for managing reserved words

pull/1194/head
ioedeveloper 4 years ago
parent c3e5683116
commit 6a8442f568
  1. 12
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx

@ -97,7 +97,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
modals: [],
toasterMsg: '',
mouseOverElement: null,
showContextMenu: false
showContextMenu: false,
reservedKeywords: [name, 'gist-']
})
const [fileSystem, dispatch] = useReducer(fileSystemReducer, fileSystemInitialState)
const editRef = useRef(null)
@ -222,6 +223,11 @@ export const FileExplorer = (props: FileExplorerProps) => {
return keyPath.join('/')
}
const hasReservedKeyword = (content: string): boolean => {
if (state.reservedKeywords.findIndex(value => content.startsWith(value)) !== -1) return true
else return false
}
const createNewFile = async (newFilePath: string) => {
const fileManager = state.fileManager
@ -584,7 +590,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
modal('Validation Error', 'Special characters are not allowed', 'OK', () => {})
} else {
if (state.focusEdit.isNew) {
if ((content === props.name) || (content.indexOf('gist-') === 0)) {
if (hasReservedKeyword(content)) {
removeInputField(parentFolder)(dispatch)
modal('Reserved Keyword', `File name contains remix reserved keywords. '${content}'`, {
label: 'Close',
@ -595,7 +601,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
removeInputField(parentFolder)(dispatch)
}
} else {
if ((content === props.name) || (content.indexOf('gist-') === 0)) {
if (hasReservedKeyword(content)) {
editRef.current.textContent = state.focusEdit.lastEdit
modal('Reserved Keyword', `File name contains remix reserved keywords. '${content}'`, {
label: 'Close',

Loading…
Cancel
Save