Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta #1

Merged
merged 2 commits into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@ Primary.args = {
onDataChanged: (data, action) => console.log(data, action),
onItemOpen: () => null
}

export const Selector: Story<SnekFinderProps> = Primary.bind({})

Selector.args = {
...Primary.args,
mode: 'selector',
onSelectorSelect: item => console.log(item),
onSelectorClose: () => null
}
55 changes: 48 additions & 7 deletions packages/snek-finder/src/components/organisms/Finder/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import {DeleteIcon} from '@chakra-ui/icons'
import {Box, Divider} from '@chakra-ui/layout'
import {
AbsoluteCenter,
Center,
Flex,
HStack,
Icon,
Image,
Portal,
Text,
useDisclosure,
useToast
useToast,
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalFooter,
ModalBody,
ModalCloseButton
} from '@chakra-ui/react'
import {FaFile} from '@react-icons/all-files/fa/FaFile'
import {FaFilePdf} from '@react-icons/all-files/fa/FaFilePdf'
Expand All @@ -31,18 +41,23 @@ import {
FinderData,
FinderFileItem,
FinderFolderItem,
FinderItem,
FinderMode,
MimeType,
SnekFinderAction
} from './types'

export type SnekFinderProps = {
mode?: FinderMode
onSelectorClose?: () => void
onSelectorSelect?: (item: FinderItem) => void
data: FinderData
rootUUID: string
onItemOpen: (uuid: string) => void
onDataChanged: (data: FinderData, action: SnekFinderAction) => void
}

const Finder: React.FC<SnekFinderProps> = props => {
const Finder: React.FC<SnekFinderProps> = ({mode = 'browser', ...props}) => {
const toast = useToast()
const folderCreateContextModal = useDisclosure()
const itemRenameContextModal = useDisclosure()
Expand Down Expand Up @@ -284,12 +299,19 @@ const Finder: React.FC<SnekFinderProps> = props => {
const uuid = resolveUUIDFromIndex(selectedFiles[0])
const item = data[uuid]

setContextMenu(null)

if ((item as FinderFolderItem).isFolder) {
switchParentNode(uuid)
} else {
if (mode === 'selector') {
if (props.onSelectorSelect) {
props.onSelectorSelect(item)
}
} else {
props.onItemOpen(uuid)
}
}

setContextMenu(null)
props.onItemOpen(uuid)
}

const handleFileRename = () => {
Expand Down Expand Up @@ -428,7 +450,7 @@ const Finder: React.FC<SnekFinderProps> = props => {
}
}, [isDragActive, isDragAccept, draggedFiles.length])

return (
const finder = (
<>
{contextMenu && (
<Box
Expand All @@ -442,7 +464,7 @@ const Finder: React.FC<SnekFinderProps> = props => {
? [
{
_type: 'ITEM',
content: <>{'Open'}</>,
content: <>{mode === 'selector' ? 'Select' : 'Open'}</>,
onItemClick: handleFileOpen
},
{
Expand Down Expand Up @@ -534,6 +556,25 @@ const Finder: React.FC<SnekFinderProps> = props => {
/>
</>
)

if (mode === 'selector' && props.onSelectorClose) {
return (
<Modal
isOpen={true}
onClose={props.onSelectorClose}
isCentered
size="6xl">
<ModalOverlay />
<ModalContent>
<ModalHeader>SnekFinder - Selector</ModalHeader>
<ModalCloseButton />
<ModalBody>{finder}</ModalBody>
</ModalContent>
</Modal>
)
}

return finder
}

export default Finder
2 changes: 2 additions & 0 deletions packages/snek-finder/src/components/organisms/Finder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type BasicItem = {
description?: string
}

export type FinderMode = 'browser' | 'selector'

export interface FinderFolderItem extends BasicItem {
isFolder: true
childUUIDs: string[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ IPFSBackend.initBackendLink =
'https://ipfs.io/ipfs/QmSw2QEGRx9PzBXsxt5HoKiong1hkWYN8pNwLKqwNPgaiR'

Primary.args = {backend: IPFSBackend}

export const Selector: Story<SnekFinderProps> = Template.bind({})

Selector.args = {
backend: IPFSBackend,
mode: 'selector',
onSelectorSelect: item => console.log(item),
onSelectorClose: () => console.log('close')
}
9 changes: 8 additions & 1 deletion packages/snek-finder/src/containers/SnekFinder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import Finder from '../../components/organisms/Finder'
import type {
FinderData,
FinderFileItem,
FinderFolderItem
FinderFolderItem,
FinderItem,
FinderMode
} from '../../components/organisms/Finder/types'
import {SnekFinderAction} from '../../components/organisms/Finder/types'
import ImageViewer from '../../components/organisms/ImageViewer'
Expand All @@ -15,6 +17,9 @@ import SnekStudio from '../../components/organisms/SnekStudio'

export type SnekFinderProps = {
backend: Backend
mode: FinderMode
onSelectorClose?: () => void
onSelectorSelect?: (item: FinderItem) => void
}

const initData: FinderData = {
Expand Down Expand Up @@ -76,9 +81,11 @@ const SnekFinder: React.FC<SnekFinderProps> = ({backend, ...props}) => {
}

const file = showModal && (data[showModal.uuid] as FinderFileItem)

return (
<div>
<Finder
{...props}
{...{
rootUUID: 'ae4b3bf8-6ed2-4ac6-bf18-722321af298c',
data: data as any,
Expand Down