mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-23 01:49:13 +01:00
Fix prompt
This commit is contained in:
@@ -49,11 +49,18 @@ export const DialogProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
return <DialogContext.Provider value={state}>{children}</DialogContext.Provider>;
|
||||
};
|
||||
|
||||
function DialogInstance({ id, render, ...props }: DialogEntry) {
|
||||
function DialogInstance({ id, render, onClose, ...props }: DialogEntry) {
|
||||
const { actions } = useContext(DialogContext);
|
||||
const children = render({ hide: () => actions.hide(id) });
|
||||
return (
|
||||
<Dialog open onClose={() => actions.hide(id)} {...props}>
|
||||
<Dialog
|
||||
open
|
||||
onClose={() => {
|
||||
onClose?.();
|
||||
actions.hide(id);
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
@@ -75,6 +75,7 @@ export function GlobalHooks() {
|
||||
const setEnvironments = useSetAtom(environmentsAtom);
|
||||
|
||||
useListenToTauriEvent<ModelPayload>('upserted_model', ({ payload }) => {
|
||||
console.log('Upserted model', payload.model);
|
||||
const { model, windowLabel } = payload;
|
||||
const queryKey =
|
||||
model.model === 'http_response'
|
||||
@@ -132,6 +133,8 @@ export function GlobalHooks() {
|
||||
const { model, windowLabel } = payload;
|
||||
if (shouldIgnoreModel(model, windowLabel)) return;
|
||||
|
||||
console.log('Delete model', payload.model);
|
||||
|
||||
if (model.model === 'workspace') {
|
||||
setWorkspaces(removeById(model));
|
||||
} else if (model.model === 'plugin') {
|
||||
|
||||
@@ -7,12 +7,12 @@ import { HStack } from '../components/core/Stacks';
|
||||
|
||||
export type PromptProps = Omit<PromptTextRequest, 'id' | 'title' | 'description'> & {
|
||||
description?: ReactNode;
|
||||
onHide: () => void;
|
||||
onCancel: () => void;
|
||||
onResult: (value: string | null) => void;
|
||||
};
|
||||
|
||||
export function Prompt({
|
||||
onHide,
|
||||
onCancel,
|
||||
label,
|
||||
defaultValue,
|
||||
placeholder,
|
||||
@@ -25,10 +25,9 @@ export function Prompt({
|
||||
const handleSubmit = useCallback(
|
||||
(e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
onHide();
|
||||
onResult(value);
|
||||
},
|
||||
[onHide, onResult, value],
|
||||
[onResult, value],
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -46,7 +45,7 @@ export function Prompt({
|
||||
onChange={setValue}
|
||||
/>
|
||||
<HStack space={2} justifyContent="end">
|
||||
<Button onClick={onHide} variant="border" color="secondary">
|
||||
<Button onClick={onCancel} variant="border" color="secondary">
|
||||
{cancelText || 'Cancel'}
|
||||
</Button>
|
||||
<Button type="submit" color="primary">
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { PromptProps } from './Prompt';
|
||||
import { Prompt } from './Prompt';
|
||||
|
||||
type Props = Pick<DialogProps, 'title' | 'description'> &
|
||||
Omit<PromptProps, 'onClose' | 'onHide' | 'onResult'> & { id: string };
|
||||
Omit<PromptProps, 'onClose' | 'onCancel' | 'onResult'> & { id: string };
|
||||
|
||||
export function usePrompt() {
|
||||
const dialog = useDialog();
|
||||
@@ -16,11 +16,16 @@ export function usePrompt() {
|
||||
description,
|
||||
hideX: true,
|
||||
size: 'sm',
|
||||
onClose: () => {
|
||||
// Click backdrop, close, or escape
|
||||
resolve(null);
|
||||
},
|
||||
render: ({ hide }) =>
|
||||
Prompt({
|
||||
onHide: () => {
|
||||
hide();
|
||||
onCancel: () => {
|
||||
// Click cancel button within dialog
|
||||
resolve(null);
|
||||
hide();
|
||||
},
|
||||
onResult: resolve,
|
||||
...props,
|
||||
|
||||
Reference in New Issue
Block a user