diff --git a/app/containers/Chat/index.tsx b/app/containers/Chat/index.tsx
index 4d39f1c0d..4d5c789cc 100644
--- a/app/containers/Chat/index.tsx
+++ b/app/containers/Chat/index.tsx
@@ -7,7 +7,6 @@ import {
import { useAppConfig, useChatStore } from "@/app/store";
import Locale from "@/app/locales";
-import { useLocation, useNavigate } from "react-router-dom";
import { Path } from "@/app/constant";
import { useEffect } from "react";
@@ -18,6 +17,7 @@ import MenuLayout from "@/app/components/MenuLayout";
import Panel from "./ChatPanel";
import Modal from "@/app/components/Modal";
import SessionItem from "./components/SessionItem";
+import { usePathname, useRouter } from "next/navigation";
export default MenuLayout(function SessionList(props) {
const { setShowPanel } = props;
@@ -30,17 +30,16 @@ export default MenuLayout(function SessionList(props) {
state.moveSession,
],
);
- const navigate = useNavigate();
const config = useAppConfig();
const { isMobileScreen } = config;
const chatStore = useChatStore();
- const { pathname: currentPath } = useLocation();
-
+ const router = useRouter();
+ const pathname = usePathname();
useEffect(() => {
- setShowPanel?.(currentPath === Path.Chat);
- }, [currentPath]);
+ setShowPanel?.(pathname === Path.Chat);
+ }, [pathname]);
const onDragEnd: OnDragEndResponder = (result) => {
const { destination, source } = result;
@@ -77,13 +76,15 @@ export default MenuLayout(function SessionList(props) {
{
if (config.dontShowMaskSplashScreen) {
chatStore.newSession();
- navigate(Path.Chat);
+ // navigate(Path.Chat);
+ router.push(Path.Chat);
} else {
- navigate(Path.NewChat);
+ // navigate(Path.NewChat);
+ router.push(Path.NewChat);
}
}}
>
@@ -116,8 +117,9 @@ export default MenuLayout(function SessionList(props) {
index={i}
selected={i === selectedIndex}
onClick={() => {
- navigate(Path.Chat);
+ // navigate(Path.Chat);
selectSession(i);
+ router.push(Path.Chat);
}}
onDelete={async () => {
if (
diff --git a/app/containers/Sidebar/index.tsx b/app/containers/Sidebar/index.tsx
index 8a3c53391..dd54aeb7e 100644
--- a/app/containers/Sidebar/index.tsx
+++ b/app/containers/Sidebar/index.tsx
@@ -14,13 +14,14 @@ import AssistantMobileInactive from "@/app/icons/assistantMobileInactive.svg";
import { useAppConfig } from "@/app/store";
import { Path, REPO_URL } from "@/app/constant";
-import { useNavigate, useLocation } from "react-router-dom";
import useHotKey from "@/app/hooks/useHotKey";
import ActionsBar from "@/app/components/ActionsBar";
+import { usePathname, useRouter } from "next/navigation";
export function SideBar(props: { className?: string }) {
- const navigate = useNavigate();
- const loc = useLocation();
+ // const navigate = useNavigate();
+ const pathname = usePathname();
+ const router = useRouter();
const config = useAppConfig();
const { isMobileScreen } = config;
@@ -28,8 +29,7 @@ export function SideBar(props: { className?: string }) {
useHotKey();
let selectedTab: string;
-
- switch (loc.pathname) {
+ switch (pathname) {
case Path.Masks:
case Path.NewChat:
selectedTab = Path.Masks;
@@ -40,6 +40,7 @@ export function SideBar(props: { className?: string }) {
default:
selectedTab = Path.Home;
}
+ console.log("======", selectedTab);
return (
(null);
+ const [deviceType, setDeviceType] = useState(null);
+ useEffect(() => {
+ const userAgent = navigator.userAgent.toLowerCase();
+
+ if (/iphone|ipad|ipod/.test(userAgent)) {
+ setSystemInfo("iOS");
+ }
+ }, []);
+
+ useEffect(() => {
+ const onResize = () => {
+ setDeviceInfo({
+ width: window.innerWidth,
+ height: window.innerHeight,
+ });
+ };
+
+ if (window.innerWidth < 600) {
+ setDeviceType("mobile");
+ } else {
+ setDeviceType("desktop");
+ }
+
+ window.addEventListener("resize", onResize);
+
+ return () => {
+ window.removeEventListener("resize", onResize);
+ };
+ }, []);
+
+ return {
+ windowSize: deviceInfo,
+ systemInfo,
+ deviceType,
+ };
+}
diff --git a/app/hooks/useRelativePosition.ts b/app/hooks/useRelativePosition.ts
index 90f532be4..edb3718cd 100644
--- a/app/hooks/useRelativePosition.ts
+++ b/app/hooks/useRelativePosition.ts
@@ -32,7 +32,7 @@ interface Position {
}
export default function useRelativePosition({
- containerRef = { current: window.document.body },
+ containerRef = { current: null },
delay = 100,
offsetDistance = 0,
}: Options) {
diff --git a/app/hooks/useWindowSize.ts b/app/hooks/useWindowSize.ts
index a4dbf2ef9..6a3424258 100644
--- a/app/hooks/useWindowSize.ts
+++ b/app/hooks/useWindowSize.ts
@@ -1,4 +1,4 @@
-import { useLayoutEffect, useRef, useState } from "react";
+import { useEffect, useLayoutEffect, useRef, useState } from "react";
type Size = {
width: number;
@@ -10,10 +10,14 @@ export function useWindowSize(callback?: (size: Size) => void) {
callbackRef.current = callback;
- const [size, setSize] = useState({
- width: window.innerWidth,
- height: window.innerHeight,
- });
+ const [size, setSize] = useState({});
+
+ useEffect(() => {
+ setSize({
+ width: window.innerWidth,
+ height: window.innerHeight,
+ });
+ }, []);
useLayoutEffect(() => {
const onResize = () => {
diff --git a/app/utils.ts b/app/utils.ts
index d42233c7f..c10d6d0e8 100644
--- a/app/utils.ts
+++ b/app/utils.ts
@@ -291,18 +291,16 @@ export function getMessageImages(message: RequestMessage): string[] {
}
export function isVisionModel(model: string) {
-
// Note: This is a better way using the TypeScript feature instead of `&&` or `||` (ts v5.5.0-dev.20240314 I've been using)
- const visionKeywords = [
- "vision",
- "claude-3",
- "gemini-1.5-pro",
- ];
+ const visionKeywords = ["vision", "claude-3", "gemini-1.5-pro"];
- const isGpt4Turbo = model.includes("gpt-4-turbo") && !model.includes("preview");
+ const isGpt4Turbo =
+ model.includes("gpt-4-turbo") && !model.includes("preview");
- return visionKeywords.some((keyword) => model.includes(keyword)) || isGpt4Turbo;
+ return (
+ visionKeywords.some((keyword) => model.includes(keyword)) || isGpt4Turbo
+ );
}
export function getTime(dateTime: string) {