@@ -19,12 +19,10 @@ import {
1919} from '@utils/index'
2020import { ModelFile } from '@models/file'
2121import { useStoreEditor } from '@context/editor'
22- import { type Confirmation } from '@components/modal/ModalConfirmation'
2322import { type ResponseWithDetail } from '@api/instance'
23+ import { useStoreContext } from '@context/context'
2424
2525interface FileExplorer {
26- confirmation ?: Confirmation
27- showConfirmation : boolean
2826 activeRange : Set < ModelArtifact >
2927 setActiveRange : ( activeRange : Set < ModelArtifact > ) => void
3028 selectArtifactsInRange : ( to : ModelArtifact ) => void
@@ -34,13 +32,9 @@ interface FileExplorer {
3432 removeArtifacts : ( artifacts : Set < ModelArtifact > ) => void
3533 removeArtifactWithConfirmation : ( artifact : ModelArtifact ) => void
3634 moveArtifacts : ( artifacts : Set < ModelArtifact > , target : ModelDirectory ) => void
37- setShowConfirmation : ( show : boolean ) => void
38- setConfirmation : ( confirmation ?: Confirmation ) => void
3935}
4036
4137export const FileExplorerContext = createContext < FileExplorer > ( {
42- confirmation : undefined ,
43- showConfirmation : false ,
4438 activeRange : new Set ( ) ,
4539 setActiveRange : ( ) => { } ,
4640 selectArtifactsInRange : ( ) => { } ,
@@ -50,8 +44,6 @@ export const FileExplorerContext = createContext<FileExplorer>({
5044 removeArtifacts : ( ) => { } ,
5145 removeArtifactWithConfirmation : ( ) => { } ,
5246 moveArtifacts : ( ) => { } ,
53- setShowConfirmation : ( ) => { } ,
54- setConfirmation : ( ) => { } ,
5547} )
5648
5749export default function FileExplorerProvider ( {
@@ -64,17 +56,13 @@ export default function FileExplorerProvider({
6456 const setSelectedFile = useStoreProject ( s => s . setSelectedFile )
6557 const setFiles = useStoreProject ( s => s . setFiles )
6658
59+ const addConfirmation = useStoreContext ( s => s . addConfirmation )
60+
6761 const tab = useStoreEditor ( s => s . tab )
6862 const closeTab = useStoreEditor ( s => s . closeTab )
6963
7064 const [ isLoading , setIsLoading ] = useState ( false )
7165 const [ activeRange , setActiveRange ] = useState ( new Set < ModelArtifact > ( ) )
72- const [ confirmation , setConfirmation ] = useState < Confirmation > ( )
73- const [ showConfirmation , setShowConfirmation ] = useState ( false )
74-
75- useEffect ( ( ) => {
76- setShowConfirmation ( isNotNil ( confirmation ) )
77- } , [ confirmation ] )
7866
7967 useEffect ( ( ) => {
8068 setSelectedFile ( tab ?. file )
@@ -266,34 +254,10 @@ export default function FileExplorerProvider({
266254 }
267255
268256 function removeArtifactWithConfirmation ( artifact : ModelArtifact ) : void {
269- let confirmation : Confirmation = {
270- headline : `Removing ${
271- artifact instanceof ModelDirectory ? 'Directory' : 'File'
272- } `,
273- description : `Are you sure you want to remove the ${
274- artifact instanceof ModelDirectory ? 'directory' : 'file'
275- } "${ artifact . name } "?`,
276- yesText : 'Yes, Remove' ,
277- noText : 'No, Cancel' ,
278- action : ( ) => {
279- if ( artifact instanceof ModelDirectory ) {
280- if ( artifact . parent != null ) {
281- removeArtifacts ( new Set ( [ artifact ] ) )
282- }
283- }
284-
285- if ( artifact instanceof ModelFile ) {
286- if ( artifact . parent != null ) {
287- removeArtifacts ( new Set ( [ artifact ] ) )
288- }
289- }
290- } ,
291- }
292-
293257 if ( activeRange . has ( artifact ) ) {
294258 // User selected multiple including current directory
295259 // so here we should prompt to delete all selected
296- confirmation = {
260+ addConfirmation ( {
297261 headline : 'Removing Selected Files/Directories' ,
298262 description : `Are you sure you want to remove ${ activeRange . size } items?` ,
299263 yesText : 'Yes, Remove' ,
@@ -302,10 +266,24 @@ export default function FileExplorerProvider({
302266 action : ( ) => {
303267 removeArtifacts ( activeRange )
304268 } ,
305- }
269+ } )
270+ } else {
271+ addConfirmation ( {
272+ headline : `Removing ${
273+ artifact instanceof ModelDirectory ? 'Directory' : 'File'
274+ } `,
275+ description : `Are you sure you want to remove the ${
276+ artifact instanceof ModelDirectory ? 'directory' : 'file'
277+ } "${ artifact . name } "?`,
278+ yesText : 'Yes, Remove' ,
279+ noText : 'No, Cancel' ,
280+ action : ( ) => {
281+ if ( isNotNil ( artifact . parent ) ) {
282+ removeArtifacts ( new Set ( [ artifact ] ) )
283+ }
284+ } ,
285+ } )
306286 }
307-
308- setConfirmation ( confirmation )
309287 }
310288
311289 function moveArtifacts (
@@ -362,7 +340,7 @@ export default function FileExplorerProvider({
362340 } )
363341
364342 if ( isArrayNotEmpty ( duplicates ) ) {
365- setConfirmation ( {
343+ addConfirmation ( {
366344 headline : 'Moving Duplicates' ,
367345 description : `All duplicated names will be renamed!` ,
368346 yesText : 'Yes, Rename' ,
@@ -394,8 +372,6 @@ export default function FileExplorerProvider({
394372 return (
395373 < FileExplorerContext . Provider
396374 value = { {
397- confirmation,
398- showConfirmation,
399375 activeRange,
400376 createDirectory,
401377 createFile,
@@ -404,8 +380,6 @@ export default function FileExplorerProvider({
404380 removeArtifactWithConfirmation,
405381 moveArtifacts,
406382 selectArtifactsInRange,
407- setConfirmation,
408- setShowConfirmation,
409383 setActiveRange ( activeRange ) {
410384 setActiveRange (
411385 ( ) =>
0 commit comments