mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 00:23:17 +00:00
(feat:chunks) update iff changed
This commit is contained in:
@@ -154,6 +154,10 @@ const DocumentChunks: React.FC<DocumentChunksProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleAddChunk = (title: string, text: string) => {
|
const handleAddChunk = (title: string, text: string) => {
|
||||||
|
if (!text.trim()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const metadata = {
|
const metadata = {
|
||||||
source: path || documentName,
|
source: path || documentName,
|
||||||
@@ -182,6 +186,18 @@ const DocumentChunks: React.FC<DocumentChunksProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleUpdateChunk = (title: string, text: string, chunk: ChunkType) => {
|
const handleUpdateChunk = (title: string, text: string, chunk: ChunkType) => {
|
||||||
|
|
||||||
|
if (!text.trim()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const originalTitle = chunk.metadata?.title || '';
|
||||||
|
const originalText = chunk.text || '';
|
||||||
|
|
||||||
|
if (title === originalTitle && text === originalText) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
userService
|
userService
|
||||||
.updateChunk(
|
.updateChunk(
|
||||||
@@ -326,11 +342,23 @@ const DocumentChunks: React.FC<DocumentChunksProps> = ({
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleUpdateChunk(editingTitle, editingText, editingChunk);
|
if (editingText.trim()) {
|
||||||
setIsEditing(false);
|
const hasChanges = editingTitle !== (editingChunk?.metadata?.title || '') ||
|
||||||
setEditingChunk(null);
|
editingText !== (editingChunk?.text || '');
|
||||||
|
|
||||||
|
if (hasChanges) {
|
||||||
|
handleUpdateChunk(editingTitle, editingText, editingChunk);
|
||||||
|
}
|
||||||
|
setIsEditing(false);
|
||||||
|
setEditingChunk(null);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
className="bg-purple-30 hover:bg-violets-are-blue rounded-full px-3 py-1 text-sm text-white transition-all"
|
disabled={!editingText.trim() || (editingTitle === (editingChunk?.metadata?.title || '') && editingText === (editingChunk?.text || ''))}
|
||||||
|
className={`rounded-full px-3 py-1 text-sm text-white transition-all ${
|
||||||
|
editingText.trim() && (editingTitle !== (editingChunk?.metadata?.title || '') || editingText !== (editingChunk?.text || ''))
|
||||||
|
? 'bg-purple-30 hover:bg-violets-are-blue cursor-pointer'
|
||||||
|
: 'bg-gray-400 cursor-not-allowed'
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
{t('modals.chunk.update')}
|
{t('modals.chunk.update')}
|
||||||
</button>
|
</button>
|
||||||
@@ -349,10 +377,17 @@ const DocumentChunks: React.FC<DocumentChunksProps> = ({
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleAddChunk(editingTitle, editingText);
|
if (editingText.trim()) {
|
||||||
setIsAddingChunk(false);
|
handleAddChunk(editingTitle, editingText);
|
||||||
|
setIsAddingChunk(false);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
className="bg-purple-30 hover:bg-violets-are-blue rounded-full px-3 py-1 text-sm text-white transition-all"
|
disabled={!editingText.trim()}
|
||||||
|
className={`rounded-full px-3 py-1 text-sm text-white transition-all ${
|
||||||
|
editingText.trim()
|
||||||
|
? 'bg-purple-30 hover:bg-violets-are-blue cursor-pointer'
|
||||||
|
: 'bg-gray-400 cursor-not-allowed'
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
{t('modals.chunk.add')}
|
{t('modals.chunk.add')}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user