mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-01 15:03:11 +02:00
Move a bunch of git ops to use the git binary (#302)
This commit is contained in:
39
src-web/lib/prompt-form.tsx
Normal file
39
src-web/lib/prompt-form.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { DialogProps } from '../components/core/Dialog';
|
||||
import type { PromptProps } from '../components/core/Prompt';
|
||||
import { Prompt } from '../components/core/Prompt';
|
||||
import { showDialog } from './dialog';
|
||||
|
||||
type FormArgs = Pick<DialogProps, 'title' | 'description'> &
|
||||
Omit<PromptProps, 'onClose' | 'onCancel' | 'onResult'> & {
|
||||
id: string;
|
||||
};
|
||||
|
||||
export async function showPromptForm({ id, title, description, ...props }: FormArgs) {
|
||||
return new Promise((resolve: PromptProps['onResult']) => {
|
||||
showDialog({
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
hideX: true,
|
||||
size: 'sm',
|
||||
disableBackdropClose: true, // Prevent accidental dismisses
|
||||
onClose: () => {
|
||||
// Click backdrop, close, or escape
|
||||
resolve(null);
|
||||
},
|
||||
render: ({ hide }) =>
|
||||
Prompt({
|
||||
onCancel: () => {
|
||||
// Click cancel button within dialog
|
||||
resolve(null);
|
||||
hide();
|
||||
},
|
||||
onResult: (v) => {
|
||||
resolve(v);
|
||||
hide();
|
||||
},
|
||||
...props,
|
||||
}),
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
import type { FormInput, PromptTextRequest } from '@yaakapp-internal/plugins';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { DialogProps } from '../components/core/Dialog';
|
||||
import type { PromptProps } from '../components/core/Prompt';
|
||||
import { Prompt } from '../components/core/Prompt';
|
||||
import { showDialog } from './dialog';
|
||||
import { showPromptForm } from './prompt-form';
|
||||
|
||||
type PromptProps = Omit<PromptTextRequest, 'id' | 'title' | 'description'> & {
|
||||
description?: ReactNode;
|
||||
onCancel: () => void;
|
||||
onResult: (value: string | null) => void;
|
||||
};
|
||||
|
||||
type PromptArgs = Pick<DialogProps, 'title' | 'description'> &
|
||||
Omit<PromptProps, 'onClose' | 'onCancel' | 'onResult'> & { id: string };
|
||||
@@ -10,35 +16,26 @@ export async function showPrompt({
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
required = true,
|
||||
cancelText,
|
||||
confirmText,
|
||||
...props
|
||||
}: PromptArgs) {
|
||||
return new Promise((resolve: PromptProps['onResult']) => {
|
||||
showDialog({
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
hideX: true,
|
||||
size: 'sm',
|
||||
disableBackdropClose: true, // Prevent accidental dismisses
|
||||
onClose: () => {
|
||||
// Click backdrop, close, or escape
|
||||
resolve(null);
|
||||
},
|
||||
render: ({ hide }) =>
|
||||
Prompt({
|
||||
required,
|
||||
onCancel: () => {
|
||||
// Click cancel button within dialog
|
||||
resolve(null);
|
||||
hide();
|
||||
},
|
||||
onResult: (v) => {
|
||||
resolve(v);
|
||||
hide();
|
||||
},
|
||||
...props,
|
||||
}),
|
||||
});
|
||||
const inputs: FormInput[] = [
|
||||
{
|
||||
type: 'text',
|
||||
name: 'value',
|
||||
...props,
|
||||
},
|
||||
];
|
||||
|
||||
const result = await showPromptForm({
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
inputs,
|
||||
cancelText,
|
||||
confirmText,
|
||||
});
|
||||
|
||||
return result?.value ? String(result.value) : null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user