upgrade react 19, remove preact usage
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from "preact/hooks";
|
import { useState } from "react";
|
||||||
import { ChatStore } from "@/types/chatstore";
|
import { ChatStore } from "@/types/chatstore";
|
||||||
import { MessageDetail } from "@/chatgpt";
|
import { MessageDetail } from "@/chatgpt";
|
||||||
import { Tr } from "@/translate";
|
import { Tr } from "@/translate";
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
import { themeChange } from "theme-change";
|
import { themeChange } from "theme-change";
|
||||||
|
|
||||||
import { createRef } from "preact";
|
import { useRef } from "react";
|
||||||
import {
|
import { useContext, useEffect, useState, Dispatch } from "react";
|
||||||
StateUpdater,
|
|
||||||
useContext,
|
|
||||||
useEffect,
|
|
||||||
useState,
|
|
||||||
Dispatch,
|
|
||||||
} from "preact/hooks";
|
|
||||||
import { clearTotalCost, getTotalCost } from "@/utils/totalCost";
|
import { clearTotalCost, getTotalCost } from "@/utils/totalCost";
|
||||||
import {
|
import {
|
||||||
ChatStore,
|
ChatStore,
|
||||||
@@ -484,7 +478,7 @@ const Choice = (props: {
|
|||||||
export default (props: {
|
export default (props: {
|
||||||
chatStore: ChatStore;
|
chatStore: ChatStore;
|
||||||
setChatStore: (cs: ChatStore) => void;
|
setChatStore: (cs: ChatStore) => void;
|
||||||
setShow: Dispatch<StateUpdater<boolean>>;
|
setShow: Dispatch<boolean>;
|
||||||
selectedChatStoreIndex: number;
|
selectedChatStoreIndex: number;
|
||||||
templates: TemplateChatStore[];
|
templates: TemplateChatStore[];
|
||||||
setTemplates: (templates: TemplateChatStore[]) => void;
|
setTemplates: (templates: TemplateChatStore[]) => void;
|
||||||
@@ -515,7 +509,7 @@ export default (props: {
|
|||||||
link = link + `&dev=true`;
|
link = link + `&dev=true`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const importFileRef = createRef();
|
const importFileRef = useRef<any>(null);
|
||||||
const [totalCost, setTotalCost] = useState(getTotalCost());
|
const [totalCost, setTotalCost] = useState(getTotalCost());
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const { langCode, setLangCode } = useContext(langCodeContext);
|
const { langCode, setLangCode } = useContext(langCodeContext);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createRef } from "preact";
|
import { createRef } from "react";
|
||||||
|
|
||||||
import { ChatStore } from "@/types/chatstore";
|
import { ChatStore } from "@/types/chatstore";
|
||||||
import { StateUpdater, useEffect, useState, Dispatch } from "preact/hooks";
|
import { useEffect, useState, Dispatch } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
AudioWaveform,
|
AudioWaveform,
|
||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
const WhisperButton = (props: {
|
const WhisperButton = (props: {
|
||||||
chatStore: ChatStore;
|
chatStore: ChatStore;
|
||||||
inputMsg: string;
|
inputMsg: string;
|
||||||
setInputMsg: Dispatch<StateUpdater<string>>;
|
setInputMsg: Dispatch<string>;
|
||||||
}) => {
|
}) => {
|
||||||
const { chatStore, inputMsg, setInputMsg } = props;
|
const { chatStore, inputMsg, setInputMsg } = props;
|
||||||
const mediaRef = createRef();
|
const mediaRef = createRef();
|
||||||
@@ -25,7 +25,7 @@ const WhisperButton = (props: {
|
|||||||
size="icon"
|
size="icon"
|
||||||
className={`m-1 p-1 ${isRecording !== "Mic" ? "animate-pulse" : ""}`}
|
className={`m-1 p-1 ${isRecording !== "Mic" ? "animate-pulse" : ""}`}
|
||||||
disabled={isRecording === "Transcribing"}
|
disabled={isRecording === "Transcribing"}
|
||||||
ref={mediaRef}
|
ref={mediaRef as any}
|
||||||
onClick={async (event) => {
|
onClick={async (event) => {
|
||||||
event.preventDefault(); // Prevent the default behavior
|
event.preventDefault(); // Prevent the default behavior
|
||||||
|
|
||||||
|
|||||||
@@ -57,14 +57,18 @@ function Calendar({
|
|||||||
day_hidden: "invisible",
|
day_hidden: "invisible",
|
||||||
...classNames,
|
...classNames,
|
||||||
}}
|
}}
|
||||||
components={{
|
components={
|
||||||
IconLeft: ({ className, ...props }) => (
|
{
|
||||||
|
/*
|
||||||
|
IconLeft: ({ className, ...props }: any) => (
|
||||||
<ChevronLeft className={cn("h-4 w-4", className)} {...props} />
|
<ChevronLeft className={cn("h-4 w-4", className)} {...props} />
|
||||||
),
|
),
|
||||||
IconRight: ({ className, ...props }) => (
|
IconRight: ({ className, ...props }: any) => (
|
||||||
<ChevronRight className={cn("h-4 w-4", className)} {...props} />
|
<ChevronRight className={cn("h-4 w-4", className)} {...props} />
|
||||||
),
|
),
|
||||||
}}
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, StateUpdater, Dispatch } from "preact/hooks";
|
import { useState, useEffect, Dispatch } from "react";
|
||||||
import { Tr, langCodeContext, LANG_OPTIONS, tr } from "@/translate";
|
import { Tr, langCodeContext, LANG_OPTIONS, tr } from "@/translate";
|
||||||
import { ChatStore, ChatStoreMessage } from "@/types/chatstore";
|
import { ChatStore, ChatStoreMessage } from "@/types/chatstore";
|
||||||
import { EditMessageString } from "@/editMessageString";
|
import { EditMessageString } from "@/editMessageString";
|
||||||
@@ -18,7 +18,7 @@ interface EditMessageProps {
|
|||||||
chat: ChatStoreMessage;
|
chat: ChatStoreMessage;
|
||||||
chatStore: ChatStore;
|
chatStore: ChatStore;
|
||||||
showEdit: boolean;
|
showEdit: boolean;
|
||||||
setShowEdit: Dispatch<StateUpdater<boolean>>;
|
setShowEdit: Dispatch<boolean>;
|
||||||
setChatStore: (cs: ChatStore) => void;
|
setChatStore: (cs: ChatStore) => void;
|
||||||
}
|
}
|
||||||
export function EditMessage(props: EditMessageProps) {
|
export function EditMessage(props: EditMessageProps) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { themeChange } from "theme-change";
|
import { themeChange } from "theme-change";
|
||||||
import { render } from "preact";
|
import { createRoot } from "react-dom/client";
|
||||||
import { useState, useEffect } from "preact/hooks";
|
import { useState, useEffect } from "react";
|
||||||
import { App } from "@/pages/App";
|
import { App } from "@/pages/App";
|
||||||
import { Tr, langCodeContext, LANG_OPTIONS } from "@/translate";
|
import { Tr, langCodeContext, LANG_OPTIONS } from "@/translate";
|
||||||
import { SidebarProvider } from "@/components/ui/sidebar";
|
import { SidebarProvider } from "@/components/ui/sidebar";
|
||||||
@@ -60,4 +60,4 @@ function Base() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
render(<Base />, document.getElementById("app") as HTMLElement);
|
createRoot(document.getElementById("app") as HTMLElement).render(<Base />);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { XMarkIcon } from "@heroicons/react/24/outline";
|
import { XMarkIcon } from "@heroicons/react/24/outline";
|
||||||
import Markdown from "react-markdown";
|
import Markdown from "react-markdown";
|
||||||
import { useState, useEffect, StateUpdater } from "preact/hooks";
|
import { useState } from "react";
|
||||||
|
|
||||||
import { Tr, langCodeContext, LANG_OPTIONS } from "@/translate";
|
import { Tr, langCodeContext, LANG_OPTIONS } from "@/translate";
|
||||||
import { ChatStore, ChatStoreMessage } from "@/types/chatstore";
|
import { ChatStore, ChatStoreMessage } from "@/types/chatstore";
|
||||||
@@ -156,7 +156,9 @@ export default function Message(props: Props) {
|
|||||||
) : chat.role === "tool" ? (
|
) : chat.role === "tool" ? (
|
||||||
<MessageToolResp chat={chat} copyToClipboard={copyToClipboard} />
|
<MessageToolResp chat={chat} copyToClipboard={copyToClipboard} />
|
||||||
) : renderMarkdown ? (
|
) : renderMarkdown ? (
|
||||||
<Markdown>{getMessageText(chat)}</Markdown>
|
// [TODO] It is happening https://github.com/remarkjs/react-markdown/pull/879
|
||||||
|
// <Markdown>{getMessageText(chat)}</Markdown>
|
||||||
|
<></>
|
||||||
) : (
|
) : (
|
||||||
<div className="message-content">
|
<div className="message-content">
|
||||||
{chat.content &&
|
{chat.content &&
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { useState } from "preact/hooks";
|
import { Dispatch, useState } from "react";
|
||||||
import { Dispatch, StateUpdater } from "preact/hooks";
|
|
||||||
|
|
||||||
import { Tr } from "@/translate";
|
import { Tr } from "@/translate";
|
||||||
import { calculate_token_length } from "@/chatgpt";
|
import { calculate_token_length } from "@/chatgpt";
|
||||||
import { ChatStore } from "@/types/chatstore";
|
import { ChatStore } from "@/types/chatstore";
|
||||||
|
|
||||||
const AddToolMsg = (props: {
|
const AddToolMsg = (props: {
|
||||||
setShowAddToolMsg: Dispatch<StateUpdater<boolean>>;
|
setShowAddToolMsg: Dispatch<boolean>;
|
||||||
chatStore: ChatStore;
|
chatStore: ChatStore;
|
||||||
setChatStore: (cs: ChatStore) => void;
|
setChatStore: (cs: ChatStore) => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { openDB } from "idb";
|
import { openDB } from "idb";
|
||||||
import { useEffect, useState } from "preact/hooks";
|
import { useEffect, useState } from "react";
|
||||||
import "@/global.css";
|
import "@/global.css";
|
||||||
|
|
||||||
import { calculate_token_length } from "@/chatgpt";
|
import { calculate_token_length } from "@/chatgpt";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { IDBPDatabase } from "idb";
|
import { IDBPDatabase } from "idb";
|
||||||
import { createRef } from "preact";
|
import { useRef } from "react";
|
||||||
import { StateUpdater, useEffect, useState, Dispatch } from "preact/hooks";
|
import { useEffect, useState, Dispatch } from "react";
|
||||||
import { Tr, langCodeContext, LANG_OPTIONS } from "@/translate";
|
import { Tr, langCodeContext, LANG_OPTIONS } from "@/translate";
|
||||||
import {
|
import {
|
||||||
STORAGE_NAME_TEMPLATE,
|
STORAGE_NAME_TEMPLATE,
|
||||||
@@ -84,7 +84,7 @@ export default function ChatBOX(props: {
|
|||||||
chatStore: ChatStore;
|
chatStore: ChatStore;
|
||||||
setChatStore: (cs: ChatStore) => void;
|
setChatStore: (cs: ChatStore) => void;
|
||||||
selectedChatIndex: number;
|
selectedChatIndex: number;
|
||||||
setSelectedChatIndex: Dispatch<StateUpdater<number>>;
|
setSelectedChatIndex: Dispatch<number>;
|
||||||
}) {
|
}) {
|
||||||
const { chatStore, setChatStore } = props;
|
const { chatStore, setChatStore } = props;
|
||||||
// prevent error
|
// prevent error
|
||||||
@@ -109,9 +109,10 @@ export default function ChatBOX(props: {
|
|||||||
_setFollow(follow);
|
_setFollow(follow);
|
||||||
};
|
};
|
||||||
|
|
||||||
const messagesEndRef = createRef();
|
const messagesEndRef = useRef<HTMLElement>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (follow) {
|
if (follow) {
|
||||||
|
if (messagesEndRef.current === null) return;
|
||||||
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
||||||
}
|
}
|
||||||
}, [showRetry, showGenerating, generatingMessage]);
|
}, [showRetry, showGenerating, generatingMessage]);
|
||||||
@@ -470,7 +471,7 @@ export default function ChatBOX(props: {
|
|||||||
);
|
);
|
||||||
_setToolsTemplates(templateTools);
|
_setToolsTemplates(templateTools);
|
||||||
};
|
};
|
||||||
const userInputRef = createRef();
|
const userInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -746,7 +747,7 @@ export default function ChatBOX(props: {
|
|||||||
</Button>
|
</Button>
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<div ref={messagesEndRef}></div>
|
<div ref={messagesEndRef as any}></div>
|
||||||
</ChatMessageList>
|
</ChatMessageList>
|
||||||
{images.length > 0 && (
|
{images.length > 0 && (
|
||||||
<div className="flex flex-wrap">
|
<div className="flex flex-wrap">
|
||||||
@@ -780,7 +781,7 @@ export default function ChatBOX(props: {
|
|||||||
<form className="relative rounded-lg border bg-background focus-within:ring-1 focus-within:ring-ring p-1">
|
<form className="relative rounded-lg border bg-background focus-within:ring-1 focus-within:ring-ring p-1">
|
||||||
<ChatInput
|
<ChatInput
|
||||||
value={inputMsg}
|
value={inputMsg}
|
||||||
ref={userInputRef}
|
ref={userInputRef as any}
|
||||||
placeholder="Type your message here..."
|
placeholder="Type your message here..."
|
||||||
onChange={(event: any) => {
|
onChange={(event: any) => {
|
||||||
setInputMsg(event.target.value);
|
setInputMsg(event.target.value);
|
||||||
@@ -828,6 +829,7 @@ export default function ChatBOX(props: {
|
|||||||
disabled={showGenerating}
|
disabled={showGenerating}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
send(inputMsg, true);
|
send(inputMsg, true);
|
||||||
|
if (userInputRef.current === null) return;
|
||||||
userInputRef.current.value = "";
|
userInputRef.current.value = "";
|
||||||
autoHeight(userInputRef.current);
|
autoHeight(userInputRef.current);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { IDBPDatabase } from "idb";
|
import { IDBPDatabase } from "idb";
|
||||||
import { StateUpdater, useRef, useState, Dispatch } from "preact/hooks";
|
import { useRef, useState, Dispatch } from "react";
|
||||||
|
|
||||||
import { ChatStore } from "@/types/chatstore";
|
import { ChatStore } from "@/types/chatstore";
|
||||||
import { MessageDetail } from "./chatgpt";
|
import { MessageDetail } from "./chatgpt";
|
||||||
@@ -34,7 +34,7 @@ interface ChatStoreSearchResult {
|
|||||||
|
|
||||||
export default function Search(props: {
|
export default function Search(props: {
|
||||||
db: Promise<IDBPDatabase<ChatStore>>;
|
db: Promise<IDBPDatabase<ChatStore>>;
|
||||||
setSelectedChatIndex: Dispatch<StateUpdater<number>>;
|
setSelectedChatIndex: Dispatch<number>;
|
||||||
chatStore: ChatStore;
|
chatStore: ChatStore;
|
||||||
show: boolean;
|
show: boolean;
|
||||||
setShow: (show: boolean) => void;
|
setShow: (show: boolean) => void;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createContext } from "preact";
|
import { createContext } from "react";
|
||||||
import MAP_zh_CN from "@/translate/zh_CN";
|
import MAP_zh_CN from "@/translate/zh_CN";
|
||||||
|
|
||||||
interface LangOption {
|
interface LangOption {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { SpeakerWaveIcon } from "@heroicons/react/24/outline";
|
import { SpeakerWaveIcon } from "@heroicons/react/24/outline";
|
||||||
import { useMemo, useState } from "preact/hooks";
|
import { useMemo, useState } from "react";
|
||||||
|
|
||||||
import { addTotalCost } from "@/utils/totalCost";
|
import { addTotalCost } from "@/utils/totalCost";
|
||||||
import { ChatStore, ChatStoreMessage } from "@/types/chatstore";
|
import { ChatStore, ChatStoreMessage } from "@/types/chatstore";
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import preact from "@preact/preset-vite";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [preact()],
|
plugins: [],
|
||||||
base: "./",
|
base: "./",
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
|
|||||||
Reference in New Issue
Block a user