-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: delete asset from context menu for asset tiles (#638)
- Loading branch information
1 parent
cff9a1d
commit efc0f49
Showing
6 changed files
with
102 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/@dcl/inspector/src/components/ProjectAssetExplorer/Tile/Tile.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.Tile { | ||
display: flex; | ||
flex-direction: column; | ||
margin: 8px; | ||
align-items: center; | ||
height: 72px; | ||
width: 72px; | ||
border-radius: 8px; | ||
background-color: var(--tree-border-color); | ||
cursor: pointer; | ||
justify-content: space-evenly; | ||
} | ||
|
||
.Tile span { | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
width: inherit; | ||
padding: 0 8px; | ||
text-align: center; | ||
font-size: 10px; | ||
} | ||
|
||
.Tile svg { | ||
width: 42px; | ||
height: 42px; | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/@dcl/inspector/src/components/ProjectAssetExplorer/Tile/Tile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useCallback } from 'react' | ||
import { AiFillDelete as DeleteIcon } from 'react-icons/ai' | ||
import { IoIosImage } from 'react-icons/io' | ||
import { Menu, Item as MenuItem } from 'react-contexify' | ||
import { useDrag } from 'react-dnd' | ||
|
||
import FolderIcon from '../../Icons/Folder' | ||
import { withContextMenu } from '../../../hoc/withContextMenu' | ||
import { useContextMenu } from '../../../hooks/sdk/useContextMenu' | ||
import { Props } from './types' | ||
|
||
import './Tile.css' | ||
|
||
export const Tile = withContextMenu<Props>(({ | ||
valueId, | ||
value, | ||
getDragContext, | ||
onSelect, | ||
onRemove, | ||
contextMenuId, | ||
dndType | ||
}) => { | ||
const { handleAction } = useContextMenu() | ||
|
||
const [, drag] = useDrag( | ||
() => ({ type: dndType, item: { value: valueId, context: getDragContext() } }), | ||
[valueId] | ||
) | ||
|
||
const handleRemove = useCallback(() => { | ||
onRemove(valueId) | ||
}, [valueId]) | ||
|
||
if (!value) return null | ||
|
||
return ( | ||
<> | ||
{/* TODO: support removing folders */} | ||
{value.type === 'asset' && ( | ||
<Menu id={contextMenuId}> | ||
<MenuItem id="delete" onClick={handleAction(handleRemove)}> | ||
<DeleteIcon /> Delete | ||
</MenuItem> | ||
</Menu> | ||
)} | ||
<div ref={drag} className="Tile" key={value.name} onDoubleClick={onSelect}> | ||
{value.type === 'folder' ? <FolderIcon /> : <IoIosImage />} | ||
<span>{value.name}</span> | ||
</div> | ||
</> | ||
) | ||
}) |
2 changes: 2 additions & 0 deletions
2
packages/@dcl/inspector/src/components/ProjectAssetExplorer/Tile/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { Tile } from './Tile' | ||
export { Tile } |
10 changes: 10 additions & 0 deletions
10
packages/@dcl/inspector/src/components/ProjectAssetExplorer/Tile/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { TreeNode } from '../ProjectView' | ||
|
||
export interface Props { | ||
valueId: string | ||
value?: TreeNode | ||
getDragContext: () => unknown | ||
onSelect: () => void | ||
onRemove: (value: string) => void | ||
dndType: string | ||
} |