From 83381519cb7fc0364c1cad74c3816302cc16dda4 Mon Sep 17 00:00:00 2001 From: DirkSchlossmacher <62424946+DirkSchlossmacher@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:27:23 +0200 Subject: [PATCH] x --- app/components/sidebar.tsx | 112 +++++-------------------------------- 1 file changed, 13 insertions(+), 99 deletions(-) diff --git a/app/components/sidebar.tsx b/app/components/sidebar.tsx index c427ce62b..4983b4c5d 100644 --- a/app/components/sidebar.tsx +++ b/app/components/sidebar.tsx @@ -2,17 +2,23 @@ import React, { useEffect, useRef, useMemo, useState, Fragment } from "react"; import styles from "./home.module.scss"; +import { IconButton } from "./button"; +import SettingsIcon from "../icons/settings.svg"; +import GithubIcon from "../icons/github.svg"; +import ChatGptIcon from "../icons/chatgpt.svg"; import AddIcon from "../icons/add.svg"; import CloseIcon from "../icons/close.svg"; -import DragIcon from "../icons/drag.svg"; -import GithubIcon from "../icons/github.svg"; +import DeleteIcon from "../icons/delete.svg"; import MaskIcon from "../icons/mask.svg"; +import DragIcon from "../icons/drag.svg"; import DiscoveryIcon from "../icons/discovery.svg"; import Locale from "../locales"; import { useAppConfig, useChatStore } from "../store"; + + import { DEFAULT_SIDEBAR_WIDTH, MAX_SIDEBAR_WIDTH, @@ -27,8 +33,11 @@ import { signOut } from "next-auth/react"; import dynamic from "next/dynamic"; import { Link, useNavigate } from "react-router-dom"; import { isIOS, useMobileScreen } from "../utils"; +import dynamic from "next/dynamic"; import { showConfirm, Selector } from "./ui-lib"; + + const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, { loading: () => null, }); @@ -70,101 +79,6 @@ export function useDragSideBar() { }); }; - const onDragStart = (e: MouseEvent) => { - // Remembers the initial width each time the mouse is pressed - startX.current = e.clientX; - startDragWidth.current = config.sidebarWidth; - const dragStartTime = Date.now(); - - const handleDragMove = (e: MouseEvent) => { - if (Date.now() < lastUpdateTime.current + 20) { - return; - } - lastUpdateTime.current = Date.now(); - const d = e.clientX - startX.current; - const nextWidth = limit(startDragWidth.current + d); - config.update((config) => { - if (nextWidth < MIN_SIDEBAR_WIDTH) { - config.sidebarWidth = NARROW_SIDEBAR_WIDTH; - } else { - config.sidebarWidth = nextWidth; - } - }); - }; - - const handleDragEnd = () => { - // In useRef the data is non-responsive, so `config.sidebarWidth` can't get the dynamic sidebarWidth - window.removeEventListener("pointermove", handleDragMove); - window.removeEventListener("pointerup", handleDragEnd); - - // if user click the drag icon, should toggle the sidebar - const shouldFireClick = Date.now() - dragStartTime < 300; - if (shouldFireClick) { - toggleSideBar(); - } - }; - - window.addEventListener("pointermove", handleDragMove); - window.addEventListener("pointerup", handleDragEnd); - }; - - const isMobileScreen = useMobileScreen(); - const shouldNarrow = - !isMobileScreen && config.sidebarWidth < MIN_SIDEBAR_WIDTH; - - useEffect(() => { - const barWidth = shouldNarrow - ? NARROW_SIDEBAR_WIDTH - : limit(config.sidebarWidth ?? DEFAULT_SIDEBAR_WIDTH); - const sideBarWidth = isMobileScreen ? "100vw" : `${barWidth}px`; - document.documentElement.style.setProperty("--sidebar-width", sideBarWidth); - }, [config.sidebarWidth, isMobileScreen, shouldNarrow]); - - return { - onDragStart, - shouldNarrow, - }; -} -export function SideBarContainer(props: { - children: React.ReactNode; - onDragStart: (e: MouseEvent) => void; - shouldNarrow: boolean; - className?: string; -}) { - const isMobileScreen = useMobileScreen(); - const isIOSMobile = useMemo( - () => isIOS() && isMobileScreen, - [isMobileScreen], - ); - const { children, className, onDragStart, shouldNarrow } = props; - return ( -