Rename chatgptview to copilotchatview

This commit is contained in:
Logan Yang 2023-04-03 11:48:06 -07:00
parent 400f6641d6
commit 17ca753129
3 changed files with 21 additions and 25 deletions

View file

@ -4,7 +4,7 @@ import CopilotPlugin from "./main";
import axios from 'axios';
export default class ChatGPTView extends ItemView {
export default class CopilotChatView extends ItemView {
sharedState: SharedState;
plugin: CopilotPlugin;
model: string;
@ -32,7 +32,7 @@ export default class ChatGPTView extends ItemView {
// Return a unique identifier for this view
getViewType(): string {
return 'chat-gpt-view';
return 'copilot-chat-view';
}
// Return an icon for this view
@ -42,12 +42,12 @@ export default class ChatGPTView extends ItemView {
// Return a title for this view
getTitle(): string {
return 'ChatGPT';
return 'Copilot Chat';
}
// Implement the getDisplayText method
getDisplayText(): string {
return 'ChatGPT';
return 'Copilot Chat';
}
// Render the chat interface and add event listeners
@ -180,14 +180,14 @@ export default class ChatGPTView extends ItemView {
// Your ChatGPT API interaction logic here
console.log(`Sending message: ${message}`);
const {loadingMessageEl, dotInterval} = this.createLoadingDots(chatMessages);
// const {loadingMessageEl, dotInterval} = this.createLoadingDots(chatMessages);
// Get a response from the ChatGPT API
const chatGPTResponse = await this.getChatGPTResponse(message);
// Stop the running "..." effect
clearInterval(dotInterval);
if (loadingMessageEl.parentElement) {
loadingMessageEl.parentElement.remove();
}
// clearInterval(dotInterval);
// if (loadingMessageEl.parentElement) {
// loadingMessageEl.parentElement.remove();
// }
// After receiving a response from the ChatGPT API, append it to the chat interface
this.appendMessage(chatMessages, chatGPTResponse, this.model);
this.scrollToBottom(chatMessages);

View file

@ -1,9 +1,9 @@
import { App, Modal, Plugin } from 'obsidian';
import { CopilotSettingTab } from "./settings";
import ChatGPTView from './copilotView';
import CopilotChatView from './copilotView';
import { SharedState } from './sharedState';
const CHATGPT_VIEWTYPE = 'chat-gpt-view';
const CHAT_VIEWTYPE = 'copilot-chat-view';
interface CopilotSettings {
openAiApiKey: string;
@ -29,8 +29,8 @@ export default class CopilotPlugin extends Plugin {
// Register your custom View class
this.registerView(
'chat-gpt-view',
(leaf) => new ChatGPTView(leaf, this));
'copilot-chat-view',
(leaf) => new CopilotChatView(leaf, this));
this.addRibbonIcon('message-square', 'ChatGPT', (evt: MouseEvent) => {
// open or close the chatgpt view
@ -47,21 +47,21 @@ export default class CopilotPlugin extends Plugin {
}
toggleView() {
const leaves = this.app.workspace.getLeavesOfType(CHATGPT_VIEWTYPE);
const leaves = this.app.workspace.getLeavesOfType(CHAT_VIEWTYPE);
leaves.length > 0 ? this.deactivateView() : this.activateView();
}
async activateView() {
this.app.workspace.detachLeavesOfType(CHATGPT_VIEWTYPE);
this.app.workspace.detachLeavesOfType(CHAT_VIEWTYPE);
await this.app.workspace.getRightLeaf(false).setViewState({
type: CHATGPT_VIEWTYPE,
type: CHAT_VIEWTYPE,
active: true,
});
this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(CHATGPT_VIEWTYPE)[0]);
this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(CHAT_VIEWTYPE)[0]);
}
async deactivateView() {
this.app.workspace.detachLeavesOfType(CHATGPT_VIEWTYPE);
this.app.workspace.detachLeavesOfType(CHAT_VIEWTYPE);
}
onunload() {

View file

@ -118,17 +118,13 @@ If your plugin does not need CSS, delete this file.
background-color: rgba(58, 58, 58, 0.8);
color: #ffffff;
border-radius: 5px;
padding: 8px;
margin-top: 4px;
margin-bottom: 4px;
padding: 4px;
width: 100%;
}
.chat-message.chatgpt {
border-radius: 5px;
padding: 8px;
margin-top: 4px;
margin-bottom: 4px;
padding: 4px;
width: 100%;
}
@ -139,7 +135,7 @@ If your plugin does not need CSS, delete this file.
.chat-message-content {
display: inline;
line-height: 1.2;
line-height: 1.3;
}
.clipboard-button {