mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 22:34:00 +01:00
parent
0b412cf7ad
commit
a3149dc00e
|
@ -16,6 +16,8 @@ import useSubmit from '@hooks/useSubmit';
|
||||||
|
|
||||||
import { MessageInterface } from '@type/chat';
|
import { MessageInterface } from '@type/chat';
|
||||||
|
|
||||||
|
import PopupModal from '@components/PopupModal';
|
||||||
|
|
||||||
const MessageContent = ({
|
const MessageContent = ({
|
||||||
role,
|
role,
|
||||||
content,
|
content,
|
||||||
|
@ -286,6 +288,7 @@ const EditView = ({
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const [_content, _setContent] = useState<string>(content);
|
const [_content, _setContent] = useState<string>(content);
|
||||||
|
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
|
||||||
const textareaRef = React.createRef<HTMLTextAreaElement>();
|
const textareaRef = React.createRef<HTMLTextAreaElement>();
|
||||||
|
|
||||||
const handleInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
const handleInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
|
@ -318,17 +321,22 @@ const EditView = ({
|
||||||
setMessages(updatedMessages);
|
setMessages(updatedMessages);
|
||||||
};
|
};
|
||||||
|
|
||||||
// only for sticky forms
|
|
||||||
const { handleSubmit } = useSubmit();
|
const { handleSubmit } = useSubmit();
|
||||||
const handleSaveAndSubmit = () => {
|
const handleSaveAndSubmit = () => {
|
||||||
if (!sticky) return;
|
|
||||||
if (_content == '') return;
|
if (_content == '') return;
|
||||||
const updatedMessages: MessageInterface[] = JSON.parse(
|
const updatedMessages: MessageInterface[] = JSON.parse(
|
||||||
JSON.stringify(messages)
|
JSON.stringify(messages)
|
||||||
);
|
);
|
||||||
|
if (sticky) {
|
||||||
updatedMessages.push({ role: inputRole, content: _content });
|
updatedMessages.push({ role: inputRole, content: _content });
|
||||||
_setContent('');
|
_setContent('');
|
||||||
setMessages(updatedMessages);
|
setMessages(updatedMessages);
|
||||||
|
} else {
|
||||||
|
updatedMessages[messageIndex].content = _content;
|
||||||
|
const _updatedMessages = updatedMessages.slice(0, messageIndex + 1);
|
||||||
|
setMessages(_updatedMessages);
|
||||||
|
setIsEdit(false);
|
||||||
|
}
|
||||||
handleSubmit();
|
handleSubmit();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -357,11 +365,11 @@ const EditView = ({
|
||||||
<div className='text-center mt-2 flex justify-center'>
|
<div className='text-center mt-2 flex justify-center'>
|
||||||
{sticky && (
|
{sticky && (
|
||||||
<button
|
<button
|
||||||
className='btn relative btn-primary mr-2'
|
className='btn relative mr-2 btn-primary'
|
||||||
onClick={handleSaveAndSubmit}
|
onClick={handleSaveAndSubmit}
|
||||||
>
|
>
|
||||||
<div className='flex items-center justify-center gap-2'>
|
<div className='flex items-center justify-center gap-2'>
|
||||||
Save and Submit
|
Save & Submit
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
@ -375,6 +383,19 @@ const EditView = ({
|
||||||
<div className='flex items-center justify-center gap-2'>Save</div>
|
<div className='flex items-center justify-center gap-2'>Save</div>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
{sticky || (
|
||||||
|
<button
|
||||||
|
className='btn relative mr-2 btn-neutral'
|
||||||
|
onClick={() => {
|
||||||
|
setIsModalOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className='flex items-center justify-center gap-2'>
|
||||||
|
Save & Submit
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
|
||||||
{sticky || (
|
{sticky || (
|
||||||
<button
|
<button
|
||||||
className='btn relative btn-neutral'
|
className='btn relative btn-neutral'
|
||||||
|
@ -384,6 +405,14 @@ const EditView = ({
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
{isModalOpen && (
|
||||||
|
<PopupModal
|
||||||
|
setIsModalOpen={setIsModalOpen}
|
||||||
|
title='Warning'
|
||||||
|
message='Please be advised that by submitting this message, all subsequent messages will be deleted!'
|
||||||
|
handleConfirm={handleSaveAndSubmit}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
1
src/components/PopupModal/index.ts
Normal file
1
src/components/PopupModal/index.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export { default } from './PopupModal';
|
|
@ -22,7 +22,8 @@
|
||||||
"@store/*": ["./src/store/*"],
|
"@store/*": ["./src/store/*"],
|
||||||
"@hooks/*": ["./src/hooks/*"],
|
"@hooks/*": ["./src/hooks/*"],
|
||||||
"@constants/*": ["./src/constants/*"],
|
"@constants/*": ["./src/constants/*"],
|
||||||
"@api/*": ["./src/api/*"]
|
"@api/*": ["./src/api/*"],
|
||||||
|
"@components/*": ["./src/components/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
|
|
|
@ -12,6 +12,7 @@ export default defineConfig({
|
||||||
'@hooks/': new URL('./src/hooks/', import.meta.url).pathname,
|
'@hooks/': new URL('./src/hooks/', import.meta.url).pathname,
|
||||||
'@constants/': new URL('./src/constants/', import.meta.url).pathname,
|
'@constants/': new URL('./src/constants/', import.meta.url).pathname,
|
||||||
'@api/': new URL('./src/api/', import.meta.url).pathname,
|
'@api/': new URL('./src/api/', import.meta.url).pathname,
|
||||||
|
'@components/': new URL('./src/components/', import.meta.url).pathname,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue