mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 19:56:53 +01:00 
			
		
		
		
	Code cleanup for file manager
This commit is contained in:
		
							parent
							
								
									d644758986
								
							
						
					
					
						commit
						ff9f893dc3
					
				| @ -30,10 +30,6 @@ export default () => { | |||||||
|     const setSelectedFiles = ServerContext.useStoreActions(actions => actions.files.setSelectedFiles); |     const setSelectedFiles = ServerContext.useStoreActions(actions => actions.files.setSelectedFiles); | ||||||
| 
 | 
 | ||||||
|     useEffect(() => { |     useEffect(() => { | ||||||
|         // We won't automatically mutate the store when the component re-mounts, otherwise because of
 |  | ||||||
|         // my (horrible) programming this fires off way more than we intend it to.
 |  | ||||||
|         mutate(); |  | ||||||
| 
 |  | ||||||
|         setSelectedFiles([]); |         setSelectedFiles([]); | ||||||
|         setDirectory(hash.length > 0 ? hash : '/'); |         setDirectory(hash.length > 0 ? hash : '/'); | ||||||
|     }, [ hash ]); |     }, [ hash ]); | ||||||
|  | |||||||
| @ -18,7 +18,6 @@ const Row = styled.div` | |||||||
| 
 | 
 | ||||||
| const FileObjectRow = ({ file }: { file: FileObject }) => { | const FileObjectRow = ({ file }: { file: FileObject }) => { | ||||||
|     const directory = ServerContext.useStoreState(state => state.files.directory); |     const directory = ServerContext.useStoreState(state => state.files.directory); | ||||||
|     const setDirectory = ServerContext.useStoreActions(actions => actions.files.setDirectory); |  | ||||||
| 
 | 
 | ||||||
|     const history = useHistory(); |     const history = useHistory(); | ||||||
|     const match = useRouteMatch(); |     const match = useRouteMatch(); | ||||||
| @ -31,9 +30,7 @@ const FileObjectRow = ({ file }: { file: FileObject }) => { | |||||||
|         // Just trust me future me, leave this be.
 |         // Just trust me future me, leave this be.
 | ||||||
|         if (!file.isFile) { |         if (!file.isFile) { | ||||||
|             e.preventDefault(); |             e.preventDefault(); | ||||||
| 
 |  | ||||||
|             history.push(`#${cleanDirectoryPath(`${directory}/${file.name}`)}`); |             history.push(`#${cleanDirectoryPath(`${directory}/${file.name}`)}`); | ||||||
|             setDirectory(`${directory}/${file.name}`); |  | ||||||
|         } |         } | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -2,18 +2,18 @@ import useSWR from 'swr'; | |||||||
| import loadDirectory, { FileObject } from '@/api/server/files/loadDirectory'; | import loadDirectory, { FileObject } from '@/api/server/files/loadDirectory'; | ||||||
| import { cleanDirectoryPath } from '@/helpers'; | import { cleanDirectoryPath } from '@/helpers'; | ||||||
| import useServer from '@/plugins/useServer'; | import useServer from '@/plugins/useServer'; | ||||||
| import { useLocation } from 'react-router'; | import { ServerContext } from '@/state/server'; | ||||||
| 
 | 
 | ||||||
| export default () => { | export default () => { | ||||||
|     const { uuid } = useServer(); |     const { uuid } = useServer(); | ||||||
|     const { hash } = useLocation(); |     const directory = ServerContext.useStoreState(state => state.files.directory); | ||||||
| 
 | 
 | ||||||
|     return useSWR<FileObject[]>( |     return useSWR<FileObject[]>( | ||||||
|         `${uuid}:files:${hash}`, |         `${uuid}:files:${directory}`, | ||||||
|         () => loadDirectory(uuid, cleanDirectoryPath(hash)), |         () => loadDirectory(uuid, cleanDirectoryPath(directory)), | ||||||
|         { |         { | ||||||
|             revalidateOnMount: false, |             revalidateOnMount: true, | ||||||
|             refreshInterval: 0, |             refreshInterval: 0, | ||||||
|         } |         }, | ||||||
|     ); |     ); | ||||||
| }; | }; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dane Everitt
						Dane Everitt