11import { MenuItemProps } from "../../components/MenuItems" ;
2- import { FSObjectType } from "../../stores/localFS" ;
2+ import { FSObject , FSObjectType , LocalFSState } from "../../stores/localFS" ;
33
44export type ContextMenuAction = "delete" | "rename" ;
55
@@ -29,15 +29,21 @@ export function getMainContentContextItems(
2929}
3030
3131export function getFSObjectContextMenu (
32- fsObjectType : FSObjectType ,
32+ fsObject : FSObject ,
33+ fs : LocalFSState ,
3334 setContextAction : ( action : ContextMenuAction ) => void ,
3435 setContextMenuOpen : ( open : boolean ) => void
3536) : Array < MenuItemProps > {
36- switch ( fsObjectType ) {
37+ switch ( fsObject . type ) {
3738 case "file" :
3839 return getFSFileContextMenu ( setContextAction , setContextMenuOpen ) ;
3940 case "directory" :
40- return getFSDirectoryContextMenu ( setContextAction , setContextMenuOpen ) ;
41+ return getFSDirectoryContextMenu (
42+ fsObject ,
43+ fs ,
44+ setContextAction ,
45+ setContextMenuOpen
46+ ) ;
4147 }
4248}
4349
@@ -64,7 +70,10 @@ function getFSFileContextMenu(
6470}
6571
6672function getFSDirectoryContextMenu (
73+ fsObject : FSObject ,
74+ fs : LocalFSState ,
6775 setContextAction : ( action : ContextMenuAction ) => void ,
76+
6877 setContextMenuOpen : ( open : boolean ) => void
6978) : Array < MenuItemProps > {
7079 return [
@@ -82,5 +91,16 @@ function getFSDirectoryContextMenu(
8291 setContextMenuOpen ( false ) ;
8392 } ,
8493 } ,
94+ {
95+ title : fs . favorites . includes ( fsObject . path )
96+ ? "Remove from Favorites"
97+ : "Add to Favorites" ,
98+ action : ( ) => {
99+ fs . favorites . includes ( fsObject . path )
100+ ? fs . removeFromFavorites ( fsObject . path )
101+ : fs . addToFavorites ( fsObject . path ) ;
102+ setContextMenuOpen ( false ) ;
103+ } ,
104+ } ,
85105 ] ;
86106}
0 commit comments