@@ -2,7 +2,7 @@ import React, { lazy, useEffect, useState } from 'react';
22import { ServerContext } from '@/state/server' ;
33import getFileContents from '@/api/server/files/getFileContents' ;
44import useRouter from 'use-react-router' ;
5- import { Actions , useStoreActions , useStoreState } from 'easy-peasy' ;
5+ import { Actions , useStoreActions } from 'easy-peasy' ;
66import { ApplicationStore } from '@/state' ;
77import { httpErrorToHuman } from '@/api/http' ;
88import SpinnerOverlay from '@/components/elements/SpinnerOverlay' ;
@@ -13,10 +13,12 @@ import FileNameModal from '@/components/server/files/FileNameModal';
1313import Can from '@/components/elements/Can' ;
1414import FlashMessageRender from '@/components/FlashMessageRender' ;
1515import PageContentBlock from '@/components/elements/PageContentBlock' ;
16+ import ServerError from '@/components/screens/ServerError' ;
1617
1718const LazyAceEditor = lazy ( ( ) => import ( /* webpackChunkName: "editor" */ '@/components/elements/AceEditor' ) ) ;
1819
1920export default ( ) => {
21+ const [ error , setError ] = useState ( '' ) ;
2022 const { action } = useParams ( ) ;
2123 const { history, location : { hash } } = useRouter ( ) ;
2224 const [ loading , setLoading ] = useState ( action === 'edit' ) ;
@@ -31,12 +33,12 @@ export default () => {
3133 if ( action !== 'new' ) {
3234 useEffect ( ( ) => {
3335 setLoading ( true ) ;
34- clearFlashes ( 'files:view ') ;
36+ setError ( ' ') ;
3537 getFileContents ( uuid , hash . replace ( / ^ # / , '' ) )
3638 . then ( setContent )
3739 . catch ( error => {
3840 console . error ( error ) ;
39- addError ( { key : 'files:view' , message : httpErrorToHuman ( error ) } ) ;
41+ setError ( httpErrorToHuman ( error ) ) ;
4042 } )
4143 . then ( ( ) => setLoading ( false ) ) ;
4244 } , [ uuid , hash ] ) ;
@@ -49,9 +51,10 @@ export default () => {
4951
5052 setLoading ( true ) ;
5153 clearFlashes ( 'files:view' ) ;
52- fetchFileContent ( ) . then ( content => {
53- return saveFileContents ( uuid , name || hash . replace ( / ^ # / , '' ) , content ) ;
54- } )
54+ fetchFileContent ( )
55+ . then ( content => {
56+ return saveFileContents ( uuid , name || hash . replace ( / ^ # / , '' ) , content ) ;
57+ } )
5558 . then ( ( ) => {
5659 if ( name ) {
5760 history . push ( `/server/${ id } /files/edit#/${ name } ` ) ;
@@ -67,6 +70,15 @@ export default () => {
6770 . then ( ( ) => setLoading ( false ) ) ;
6871 } ;
6972
73+ if ( error ) {
74+ return (
75+ < ServerError
76+ message = { error }
77+ onBack = { ( ) => history . goBack ( ) }
78+ />
79+ ) ;
80+ }
81+
7082 return (
7183 < PageContentBlock >
7284 < FlashMessageRender byKey = { 'files:view' } className = { 'mb-4' } />
0 commit comments