Skip to content

Commit

Permalink
Drag'n'drop added/existing file entries, add empty folder (#3999)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexei Mochalov <nl_0@quiltdata.io>
  • Loading branch information
fiskus and nl0 committed Jun 19, 2024
1 parent 3e55c58 commit 15fcd5a
Show file tree
Hide file tree
Showing 8 changed files with 1,077 additions and 185 deletions.
1 change: 1 addition & 0 deletions catalog/app/components/Dialog/Confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface PromptProps {
title: string
}

// TODO: Re-use utils/Dialog
export function useConfirm({ cancelTitle, title, onSubmit, submitTitle }: PromptProps) {
const [key, setKey] = React.useState(0)
const [opened, setOpened] = React.useState(false)
Expand Down
25 changes: 21 additions & 4 deletions catalog/app/components/Dialog/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import * as M from '@material-ui/core'
import * as Lab from '@material-ui/lab'

interface DialogProps {
children: React.ReactNode
initialValue?: string
onCancel: () => void
onSubmit: (value: string) => void
open: boolean
placeholder?: string
title: string
validate: (value: string) => Error | undefined
}

function Dialog({
children,
initialValue,
open,
onCancel,
onSubmit,
open,
placeholder,
title,
validate,
}: DialogProps) {
Expand All @@ -26,6 +30,7 @@ function Dialog({
const handleChange = React.useCallback((event) => setValue(event.target.value), [])
const handleSubmit = React.useCallback(
(event) => {
event.stopPropagation()
event.preventDefault()
setSubmitted(true)
if (!error) onSubmit(value)
Expand All @@ -37,11 +42,13 @@ function Dialog({
<form onSubmit={handleSubmit}>
<M.DialogTitle>{title}</M.DialogTitle>
<M.DialogContent>
{children}
<M.TextField
autoFocus
fullWidth
margin="dense"
onChange={handleChange}
placeholder={placeholder}
value={value}
/>
{!!error && !!submitted && (
Expand Down Expand Up @@ -69,11 +76,19 @@ function Dialog({
interface PromptProps {
initialValue?: string
onSubmit: (value: string) => void
placeholder?: string
title: string
validate: (value: string) => Error | undefined
}

export function usePrompt({ initialValue, title, onSubmit, validate }: PromptProps) {
// TODO: Re-use utils/Dialog
export function usePrompt({
onSubmit,
initialValue,
placeholder,
validate,
title,
}: PromptProps) {
const [key, setKey] = React.useState(0)
const [opened, setOpened] = React.useState(false)
const open = React.useCallback(() => {
Expand All @@ -89,20 +104,22 @@ export function usePrompt({ initialValue, title, onSubmit, validate }: PromptPro
[close, onSubmit],
)
const render = React.useCallback(
() => (
(children?: React.ReactNode) => (
<Dialog
{...{
children,
initialValue,
key,
onCancel: close,
onSubmit: handleSubmit,
open: opened,
placeholder,
title,
validate,
}}
/>
),
[initialValue, key, close, handleSubmit, opened, title, validate],
[close, handleSubmit, initialValue, key, opened, placeholder, title, validate],
)
return React.useMemo(
() => ({
Expand Down
Loading

0 comments on commit 15fcd5a

Please sign in to comment.