Skip to content

Commit

Permalink
Add New chat confirm modal, restructure components dir (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
logancyang authored Nov 27, 2024
1 parent a5b39ff commit 2b1aa23
Show file tree
Hide file tree
Showing 27 changed files with 98 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LanguageModal } from "@/components/LanguageModal";
import { ToneModal } from "@/components/ToneModal";
import { LanguageModal } from "@/components/modals/LanguageModal";
import { ToneModal } from "@/components/modals/ToneModal";
import CopilotPlugin from "@/main";
import { Editor, Notice } from "obsidian";
import { COMMAND_IDS } from "./constants";
Expand Down
7 changes: 4 additions & 3 deletions src/components/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import ChainManager from "@/LLMProviders/chainManager";
import { useAIState } from "@/aiState";
import { updateChatMemory } from "@/chatUtils";
import ChatInput from "@/components/ChatComponents/ChatInput";
import ChatMessages from "@/components/ChatComponents/ChatMessages";
import ChatInput from "@/components/chat-components/ChatInput";
import ChatMessages from "@/components/chat-components/ChatMessages";
import { ABORT_REASON, AI_SENDER, EVENT_NAMES, LOADING_MESSAGES, USER_SENDER } from "@/constants";
import { AppContext } from "@/context";
import { ContextProcessor } from "@/contextProcessor";
import { CustomPromptProcessor } from "@/customPromptProcessor";
import { getAIResponse } from "@/langchainStream";
import ChainManager from "@/LLMProviders/chainManager";
import CopilotPlugin from "@/main";
import { Mention } from "@/mentions/Mention";
import { useSettingsValueContext } from "@/settings/contexts/SettingsValueContext";
Expand Down Expand Up @@ -658,6 +658,7 @@ ${chatContent}`;
selectedImages={selectedImages}
onAddImage={(files: File[]) => setSelectedImages((prev) => [...prev, ...files])}
setSelectedImages={setSelectedImages}
chatHistory={chatHistory}
debug={debug}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { App, Notice } from "obsidian";
import React, { useEffect, useState } from "react";

import { ChainType } from "@/chainFactory";
import { AddContextNoteModal } from "@/components/AddContextNoteModal";
import { TooltipActionButton } from "@/components/ChatComponents/TooltipActionButton";
import { TooltipActionButton } from "@/components/chat-components/TooltipActionButton";
import { AddContextNoteModal } from "@/components/modals/AddContextNoteModal";
import { useSettingsValueContext } from "@/settings/contexts/SettingsValueContext";
import { stringToChainType } from "@/utils";
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
import { ChevronDown, Download, MessageCirclePlus, Puzzle } from "lucide-react";

import { NewChatConfirmModal } from "@/components/modals/NewChatConfirmModal";
import { ChatMessage } from "@/sharedState";
import { TFile } from "obsidian";
import { ChatContextMenu } from "./ChatContextMenu";

Expand All @@ -29,6 +31,7 @@ interface ChatControlsProps {
setIncludeActiveNote: React.Dispatch<React.SetStateAction<boolean>>;
contextUrls: string[];
onRemoveUrl: (url: string) => void;
chatHistory: ChatMessage[];
debug?: boolean;
}

Expand All @@ -46,6 +49,7 @@ const ChatControls: React.FC<ChatControlsProps> = ({
setIncludeActiveNote,
contextUrls,
onRemoveUrl,
chatHistory,
debug,
}) => {
const [selectedChain, setSelectedChain] = useState<ChainType>(currentChain);
Expand Down Expand Up @@ -159,7 +163,13 @@ const ChatControls: React.FC<ChatControlsProps> = ({
<div className="chat-icons-right">
<TooltipActionButton
onClick={() => {
onNewChat(false);
if (!settings.autosaveChat && chatHistory.length > 0) {
new NewChatConfirmModal(app, () => {
onNewChat(false);
}).open();
} else {
onNewChat(false);
}
}}
Icon={<MessageCirclePlus className="icon-scaler" />}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { CustomModel, SetChainOptions } from "@/aiParams";
import { ChainType } from "@/chainFactory";
import { ListPromptModal } from "@/components/ListPromptModal";
import { NoteTitleModal } from "@/components/NoteTitleModal";
import { AddImageModal } from "@/components/modals/AddImageModal";
import { ListPromptModal } from "@/components/modals/ListPromptModal";
import { NoteTitleModal } from "@/components/modals/NoteTitleModal";
import { ContextProcessor } from "@/contextProcessor";
import { CustomPromptProcessor } from "@/customPromptProcessor";
import { COPILOT_TOOL_NAMES } from "@/LLMProviders/intentAnalyzer";
import { Mention } from "@/mentions/Mention";
import { useSettingsValueContext } from "@/settings/contexts/SettingsValueContext";
import { ChatMessage } from "@/sharedState";
import { getToolDescription } from "@/tools/toolManager";
import { extractNoteTitles } from "@/utils";
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
import { ArrowBigUp, ChevronUp, Command, CornerDownLeft, Image, StopCircle } from "lucide-react";
import { App, Platform, TFile } from "obsidian";
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
import { AddImageModal } from "../AddImageModal";
import ChatControls from "./ChatControls";
import { TooltipActionButton } from "./TooltipActionButton";

Expand Down Expand Up @@ -41,6 +42,7 @@ interface ChatInputProps {
selectedImages: File[];
onAddImage: (files: File[]) => void;
setSelectedImages: React.Dispatch<React.SetStateAction<File[]>>;
chatHistory: ChatMessage[];
debug?: boolean;
}

Expand Down Expand Up @@ -72,6 +74,7 @@ const ChatInput = forwardRef<{ focus: () => void }, ChatInputProps>(
selectedImages,
onAddImage,
setSelectedImages,
chatHistory,
debug,
},
ref
Expand Down Expand Up @@ -392,6 +395,7 @@ const ChatInput = forwardRef<{ focus: () => void }, ChatInputProps>(
setIncludeActiveNote={setIncludeActiveNote}
contextUrls={contextUrls}
onRemoveUrl={(url: string) => setContextUrls((prev) => prev.filter((u) => u !== url))}
chatHistory={chatHistory}
debug={debug}
/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChainType } from "@/chainFactory";
import ChatSingleMessage from "@/components/ChatComponents/ChatSingleMessage";
import { SuggestedPrompts } from "@/components/ChatComponents/SuggestedPrompts";
import ChatSingleMessage from "@/components/chat-components/ChatSingleMessage";
import { SuggestedPrompts } from "@/components/chat-components/SuggestedPrompts";
import { ChatMessage } from "@/sharedState";
import { App } from "obsidian";
import React, { useEffect, useState } from "react";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChatButtons } from "@/components/ChatComponents/ChatButtons";
import { SourcesModal } from "@/components/SourcesModal";
import { ChatButtons } from "@/components/chat-components/ChatButtons";
import { SourcesModal } from "@/components/modals/SourcesModal";
import { USER_SENDER } from "@/constants";
import { ChatMessage } from "@/sharedState";
import { Bot, User } from "lucide-react";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
60 changes: 60 additions & 0 deletions src/components/modals/NewChatConfirmModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { App, Modal } from "obsidian";

export class NewChatConfirmModal extends Modal {
private onConfirm: () => void;

constructor(app: App, onConfirm: () => void) {
super(app);
this.onConfirm = onConfirm;
}

onOpen() {
const { contentEl } = this;
contentEl.empty();

contentEl.createEl("h2", { text: "Start New Chat" });

const warningText = contentEl.createEl("p");
warningText.appendChild(
document.createTextNode(
"Starting a new chat will clear the current chat history. Any unsaved messages will be lost."
)
);

const buttonContainer = contentEl.createEl("div");
buttonContainer.style.display = "flex";
buttonContainer.style.justifyContent = "space-between";
buttonContainer.style.gap = "10px";
buttonContainer.style.marginTop = "20px";

const confirmButton = buttonContainer.createEl("button", {
text: "Continue",
});
confirmButton.style.padding = "8px 16px";
confirmButton.style.borderRadius = "4px";
confirmButton.style.cursor = "pointer";
confirmButton.style.minWidth = "100px";
confirmButton.style.backgroundColor = "var(--interactive-accent)";
confirmButton.style.color = "var(--text-on-accent)";
confirmButton.addEventListener("click", () => {
this.onConfirm();
this.close();
});

const cancelButton = buttonContainer.createEl("button", {
text: "Cancel",
});
cancelButton.style.padding = "8px 16px";
cancelButton.style.borderRadius = "4px";
cancelButton.style.cursor = "pointer";
cancelButton.style.minWidth = "100px";
cancelButton.addEventListener("click", () => {
this.close();
});
}

onClose() {
const { contentEl } = this;
contentEl.empty();
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App, Modal, Notice, Setting } from "obsidian";
import CopilotPlugin from "../main";
import CopilotPlugin from "../../main";

export class OramaSearchModal extends Modal {
plugin: CopilotPlugin;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { CustomModel, LangChainParams, SetChainOptions } from "@/aiParams";
import { ChainType } from "@/chainFactory";
import { parseChatContent, updateChatMemory } from "@/chatUtils";
import { registerBuiltInCommands } from "@/commands";
import { AddPromptModal } from "@/components/AddPromptModal";
import { AdhocPromptModal } from "@/components/AdhocPromptModal";
import CopilotView from "@/components/CopilotView";
import { IndexedFilesModal } from "@/components/IndexedFilesModal";
import { ListPromptModal } from "@/components/ListPromptModal";
import { LoadChatHistoryModal } from "@/components/LoadChatHistoryModal";
import { OramaSearchModal } from "@/components/OramaSearchModal";
import { SimilarNotesModal } from "@/components/SimilarNotesModal";
import { AddPromptModal } from "@/components/modals/AddPromptModal";
import { AdhocPromptModal } from "@/components/modals/AdhocPromptModal";
import { IndexedFilesModal } from "@/components/modals/IndexedFilesModal";
import { ListPromptModal } from "@/components/modals/ListPromptModal";
import { LoadChatHistoryModal } from "@/components/modals/LoadChatHistoryModal";
import { OramaSearchModal } from "@/components/modals/OramaSearchModal";
import { SimilarNotesModal } from "@/components/modals/SimilarNotesModal";
import {
BUILTIN_CHAT_MODELS,
BUILTIN_EMBEDDING_MODELS,
Expand Down

0 comments on commit 2b1aa23

Please sign in to comment.