mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-11-12 13:02:54 -05:00
fix: Handling request error on provider error
This commit is contained in:
@ -43,6 +43,7 @@ qt_add_qml_module(QodeAssistChatView
|
|||||||
ChatSerializer.hpp ChatSerializer.cpp
|
ChatSerializer.hpp ChatSerializer.cpp
|
||||||
ChatView.hpp ChatView.cpp
|
ChatView.hpp ChatView.cpp
|
||||||
ChatData.hpp
|
ChatData.hpp
|
||||||
|
QML_FILES qml/parts/ErrorToast.qml
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(QodeAssistChatView
|
target_link_libraries(QodeAssistChatView
|
||||||
|
|||||||
@ -132,6 +132,11 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
&Utils::BaseAspect::changed,
|
&Utils::BaseAspect::changed,
|
||||||
this,
|
this,
|
||||||
&ChatRootView::textFormatChanged);
|
&ChatRootView::textFormatChanged);
|
||||||
|
connect(m_clientInterface, &ClientInterface::errorOccurred, this, [this](const QString &error) {
|
||||||
|
this->setRequestProgressStatus(false);
|
||||||
|
m_lastErrorMessage = error;
|
||||||
|
emit lastErrorMessageChanged();
|
||||||
|
});
|
||||||
|
|
||||||
updateInputTokensCount();
|
updateInputTokensCount();
|
||||||
}
|
}
|
||||||
@ -622,4 +627,9 @@ void ChatRootView::setRequestProgressStatus(bool state)
|
|||||||
emit isRequestInProgressChanged();
|
emit isRequestInProgressChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ChatRootView::lastErrorMessage() const
|
||||||
|
{
|
||||||
|
return m_lastErrorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QodeAssist::Chat
|
} // namespace QodeAssist::Chat
|
||||||
|
|||||||
@ -45,6 +45,7 @@ class ChatRootView : public QQuickItem
|
|||||||
Q_PROPERTY(int textFormat READ textFormat NOTIFY textFormatChanged FINAL)
|
Q_PROPERTY(int textFormat READ textFormat NOTIFY textFormatChanged FINAL)
|
||||||
Q_PROPERTY(
|
Q_PROPERTY(
|
||||||
bool isRequestInProgress READ isRequestInProgress NOTIFY isRequestInProgressChanged FINAL)
|
bool isRequestInProgress READ isRequestInProgress NOTIFY isRequestInProgressChanged FINAL)
|
||||||
|
Q_PROPERTY(QString lastErrorMessage READ lastErrorMessage NOTIFY lastErrorMessageChanged FINAL)
|
||||||
|
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
|
|
||||||
@ -97,6 +98,8 @@ public:
|
|||||||
bool isRequestInProgress() const;
|
bool isRequestInProgress() const;
|
||||||
void setRequestProgressStatus(bool state);
|
void setRequestProgressStatus(bool state);
|
||||||
|
|
||||||
|
QString lastErrorMessage() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void sendMessage(const QString &message);
|
void sendMessage(const QString &message);
|
||||||
void copyToClipboard(const QString &text);
|
void copyToClipboard(const QString &text);
|
||||||
@ -120,6 +123,8 @@ signals:
|
|||||||
void chatRequestStarted();
|
void chatRequestStarted();
|
||||||
void isRequestInProgressChanged();
|
void isRequestInProgressChanged();
|
||||||
|
|
||||||
|
void lastErrorMessageChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString getChatsHistoryDir() const;
|
QString getChatsHistoryDir() const;
|
||||||
QString getSuggestedFileName() const;
|
QString getSuggestedFileName() const;
|
||||||
@ -136,6 +141,7 @@ private:
|
|||||||
bool m_isSyncOpenFiles;
|
bool m_isSyncOpenFiles;
|
||||||
QList<Core::IEditor *> m_currentEditors;
|
QList<Core::IEditor *> m_currentEditors;
|
||||||
bool m_isRequestInProgress;
|
bool m_isRequestInProgress;
|
||||||
|
QString m_lastErrorMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QodeAssist::Chat
|
} // namespace QodeAssist::Chat
|
||||||
|
|||||||
@ -263,6 +263,20 @@ ChatRootView {
|
|||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorToast {
|
||||||
|
id: errorToast
|
||||||
|
z: 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: root
|
||||||
|
function onLastErrorMessageChanged() {
|
||||||
|
if (root.lastErrorMessage.length > 0) {
|
||||||
|
errorToast.show(root.lastErrorMessage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
messageInput.forceActiveFocus()
|
messageInput.forceActiveFocus()
|
||||||
}
|
}
|
||||||
|
|||||||
100
ChatView/qml/parts/ErrorToast.qml
Normal file
100
ChatView/qml/parts/ErrorToast.qml
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import QtQuick
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: errorToast
|
||||||
|
|
||||||
|
property string errorText: ""
|
||||||
|
property int displayDuration: 5000
|
||||||
|
|
||||||
|
width: Math.min(parent.width - 40, errorTextItem.implicitWidth + radius)
|
||||||
|
height: visible ? (errorTextItem.implicitHeight + 12) : 0
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.topMargin: 10
|
||||||
|
|
||||||
|
color: "#d32f2f"
|
||||||
|
radius: height / 2
|
||||||
|
border.color: "#b71c1c"
|
||||||
|
border.width: 1
|
||||||
|
visible: false
|
||||||
|
opacity: 0
|
||||||
|
|
||||||
|
TextEdit {
|
||||||
|
id: errorTextItem
|
||||||
|
|
||||||
|
anchors.centerIn: parent
|
||||||
|
anchors.margins: 6
|
||||||
|
text: errorToast.errorText
|
||||||
|
color: "#ffffff"
|
||||||
|
font.pixelSize: 13
|
||||||
|
wrapMode: TextEdit.Wrap
|
||||||
|
width: Math.min(implicitWidth, errorToast.parent.width - 60)
|
||||||
|
horizontalAlignment: TextEdit.AlignHCenter
|
||||||
|
readOnly: true
|
||||||
|
selectByMouse: true
|
||||||
|
selectByKeyboard: true
|
||||||
|
selectionColor: "#b71c1c"
|
||||||
|
}
|
||||||
|
|
||||||
|
function show(message) {
|
||||||
|
errorText = message
|
||||||
|
visible = true
|
||||||
|
showAnimation.start()
|
||||||
|
hideTimer.restart()
|
||||||
|
}
|
||||||
|
|
||||||
|
function hide() {
|
||||||
|
hideAnimation.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
NumberAnimation {
|
||||||
|
id: showAnimation
|
||||||
|
|
||||||
|
target: errorToast
|
||||||
|
property: "opacity"
|
||||||
|
from: 0
|
||||||
|
to: 1
|
||||||
|
duration: 200
|
||||||
|
easing.type: Easing.OutQuad
|
||||||
|
}
|
||||||
|
|
||||||
|
NumberAnimation {
|
||||||
|
id: hideAnimation
|
||||||
|
|
||||||
|
target: errorToast
|
||||||
|
property: "opacity"
|
||||||
|
from: 1
|
||||||
|
to: 0
|
||||||
|
duration: 200
|
||||||
|
easing.type: Easing.InQuad
|
||||||
|
onFinished: errorToast.visible = false
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: hideTimer
|
||||||
|
|
||||||
|
interval: errorToast.displayDuration
|
||||||
|
running: false
|
||||||
|
repeat: false
|
||||||
|
onTriggered: errorToast.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user