init
This commit is contained in:
@@ -4,6 +4,7 @@ import DevChatInput from '../tools/dev_chatbot/ChatInput.jsx';
|
|||||||
import { marked } from 'marked';
|
import { marked } from 'marked';
|
||||||
marked.setOptions({ mangle:false, headerIds:false });
|
marked.setOptions({ mangle:false, headerIds:false });
|
||||||
import { fetchOpenAIChat, fetchOpenAIImage, classifyRequest } from '../services/openaiService';
|
import { fetchOpenAIChat, fetchOpenAIImage, classifyRequest } from '../services/openaiService';
|
||||||
|
import { useAuth } from '../context/AuthContext';
|
||||||
import { API_BASE_URL } from '../config';
|
import { API_BASE_URL } from '../config';
|
||||||
|
|
||||||
// === Chat History Panel 컴포넌트 추가 ===
|
// === Chat History Panel 컴포넌트 추가 ===
|
||||||
@@ -100,6 +101,7 @@ function FileSidebar() {
|
|||||||
|
|
||||||
export default function ChatPage() {
|
export default function ChatPage() {
|
||||||
const { selectedTool } = useTool();
|
const { selectedTool } = useTool();
|
||||||
|
const { user } = useAuth();
|
||||||
const [messages, setMessages] = useState(() => {
|
const [messages, setMessages] = useState(() => {
|
||||||
try {
|
try {
|
||||||
const toolIdInitial = selectedTool?.id || 'chatgpt';
|
const toolIdInitial = selectedTool?.id || 'chatgpt';
|
||||||
@@ -171,6 +173,10 @@ export default function ChatPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sendMessage = async () => {
|
const sendMessage = async () => {
|
||||||
|
if (!user) {
|
||||||
|
alert('로그인이 필요합니다');
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!input.trim()) return;
|
if (!input.trim()) return;
|
||||||
const userMsg = { type: 'user', content: input.trim(), time: new Date().toLocaleTimeString() };
|
const userMsg = { type: 'user', content: input.trim(), time: new Date().toLocaleTimeString() };
|
||||||
setMessages((prev) => [...prev, userMsg]);
|
setMessages((prev) => [...prev, userMsg]);
|
||||||
@@ -429,6 +435,7 @@ function DocTranslationSidebar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function DocTranslationChat() {
|
function DocTranslationChat() {
|
||||||
|
const { user } = useAuth();
|
||||||
const { selectedTool } = useTool();
|
const { selectedTool } = useTool();
|
||||||
const [messages, setMessages] = useState([]);
|
const [messages, setMessages] = useState([]);
|
||||||
const [input, setInput] = useState('');
|
const [input, setInput] = useState('');
|
||||||
@@ -450,6 +457,10 @@ function DocTranslationChat() {
|
|||||||
}, [messages]);
|
}, [messages]);
|
||||||
|
|
||||||
const sendMessage = async () => {
|
const sendMessage = async () => {
|
||||||
|
if (!user) {
|
||||||
|
alert('로그인이 필요합니다');
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!input.trim()) return;
|
if (!input.trim()) return;
|
||||||
const userMsg = { type: 'user', content: input.trim(), time: new Date().toLocaleTimeString() };
|
const userMsg = { type: 'user', content: input.trim(), time: new Date().toLocaleTimeString() };
|
||||||
setMessages((prev) => [...prev, userMsg, { type: 'loading', start: Date.now() }]);
|
setMessages((prev) => [...prev, userMsg, { type: 'loading', start: Date.now() }]);
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import React, { useState, useRef, useEffect } from 'react';
|
import React, { useState, useRef, useEffect } from 'react';
|
||||||
import { ChatHandler } from './ChatHandler';
|
import { ChatHandler } from './ChatHandler';
|
||||||
import { useTool } from '../../context/ToolContext';
|
import { useTool } from '../../context/ToolContext';
|
||||||
|
import { useAuth } from '../../context/AuthContext';
|
||||||
import { marked } from 'marked';
|
import { marked } from 'marked';
|
||||||
marked.setOptions({ mangle:false, headerIds:false });
|
marked.setOptions({ mangle:false, headerIds:false });
|
||||||
|
|
||||||
export default function DevChatInput() {
|
export default function DevChatInput() {
|
||||||
const { selectedTool } = useTool();
|
const { selectedTool } = useTool();
|
||||||
|
const { user } = useAuth();
|
||||||
const [inputText, setInputText] = useState('');
|
const [inputText, setInputText] = useState('');
|
||||||
const inputRef = useRef(null);
|
const inputRef = useRef(null);
|
||||||
const [selectedFiles, setSelectedFiles] = useState([]);
|
const [selectedFiles, setSelectedFiles] = useState([]);
|
||||||
@@ -40,6 +42,10 @@ export default function DevChatInput() {
|
|||||||
const handleFileRemove = (idx) => setSelectedFiles((prev) => prev.filter((_, i) => i !== idx));
|
const handleFileRemove = (idx) => setSelectedFiles((prev) => prev.filter((_, i) => i !== idx));
|
||||||
|
|
||||||
const handleSend = async () => {
|
const handleSend = async () => {
|
||||||
|
if (!user) {
|
||||||
|
alert('로그인이 필요합니다');
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!inputText && selectedFiles.length === 0) return;
|
if (!inputText && selectedFiles.length === 0) return;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const userMessage = { text: inputText, files: selectedFiles, sender: 'user', time: new Date().toLocaleTimeString() };
|
const userMessage = { text: inputText, files: selectedFiles, sender: 'user', time: new Date().toLocaleTimeString() };
|
||||||
|
|||||||
Reference in New Issue
Block a user