From 48e8c0a194bcf19a55524e5b301329f3486c2770 Mon Sep 17 00:00:00 2001 From: butterfly Date: Fri, 26 Apr 2024 01:31:03 +0800 Subject: [PATCH] feat: optiminize --- app/components/ActionsBar/index.tsx | 4 +- app/components/Card/index.tsx | 16 ++--- app/components/Imgs/index.tsx | 14 +---- app/components/Input/index.tsx | 2 +- app/components/List/index.tsx | 25 +++----- app/components/Loading/index.tsx | 17 +++--- app/components/MenuLayout/index.tsx | 36 ++++++----- app/components/Popover/index.tsx | 2 +- app/components/Screen/index.tsx | 33 +++++----- app/components/Select/index.tsx | 8 +-- app/components/SlideRange/index.tsx | 26 ++++---- app/components/Switch/index.tsx | 2 +- app/containers/Chat/ChatActions.tsx | 39 ++++++------ app/containers/Chat/ChatHeader.tsx | 41 +++++++------ app/containers/Chat/ChatInputPanel.tsx | 46 ++++++++------ app/containers/Chat/ChatMessagePanel.tsx | 2 +- app/containers/Chat/ChatPanel.tsx | 12 ++-- app/containers/Chat/ClearContextDivider.tsx | 9 +-- app/containers/Chat/MessageActions.tsx | 2 +- app/containers/Chat/index.tsx | 67 +++++++++++++-------- app/containers/Settings/AppSetting.tsx | 4 +- app/containers/Settings/SettingHeader.tsx | 34 +++++------ app/containers/Settings/SettingPanel.tsx | 25 ++++---- app/containers/Settings/index.tsx | 37 ++++++------ app/containers/Sidebar/index.tsx | 24 ++++---- app/icons/deleteChatIcon.svg | 4 ++ app/styles/globals.css | 2 + package.json | 1 + tailwind.config.js | 21 ++++--- yarn.lock | 12 ++++ 30 files changed, 304 insertions(+), 263 deletions(-) create mode 100644 app/icons/deleteChatIcon.svg diff --git a/app/components/ActionsBar/index.tsx b/app/components/ActionsBar/index.tsx index 045459c4c..3c6132f7f 100644 --- a/app/components/ActionsBar/index.tsx +++ b/app/components/ActionsBar/index.tsx @@ -76,7 +76,7 @@ export default function ActionsBar(props: ActionsBarProps) { return (
{title && (
{title}
diff --git a/app/components/Imgs/index.tsx b/app/components/Imgs/index.tsx index bf09df795..6b06cc059 100644 --- a/app/components/Imgs/index.tsx +++ b/app/components/Imgs/index.tsx @@ -4,33 +4,23 @@ import { RequestMessage } from "@/app/client/api"; interface ImgsProps { message: RequestMessage; - isMobileScreen?: boolean; } export default function Imgs(props: ImgsProps) { - const { message, isMobileScreen } = props; + const { message } = props; const imgSrcs = getMessageImages(message); if (imgSrcs.length < 1) { return <>; } - let imgVars = { + const imgVars = { "--imgs-width": `calc(var(--max-message-width) - ${ imgSrcs.length - 1 }*0.25rem)`, "--img-width": `calc(var(--imgs-width)/ ${imgSrcs.length})`, }; - if (isMobileScreen) { - imgVars = { - "--imgs-width": `calc(var(--max-message-width) - ${ - imgSrcs.length - 1 - }*0.25rem)`, - "--img-width": `calc(var(--imgs-width)/ ${imgSrcs.length})`, - }; - } - return (
{type == "password" && ( -
setShow((pre) => !pre)}> +
setShow((pre) => !pre)}> {show ? : }
)} diff --git a/app/components/List/index.tsx b/app/components/List/index.tsx index 91b97019c..94c9af655 100644 --- a/app/components/List/index.tsx +++ b/app/components/List/index.tsx @@ -52,20 +52,13 @@ export function ListItem(props: ListItemProps) { const context = useContext(ListContext); - const [childrenMeta, setMeta] = useState({}); + const [childrenType, setMeta] = useState("unknown"); - const { isMobileScreen, inputNextLine, rangeNextLine } = context; - - let containerClassName = "py-3"; - let titleClassName = ""; - if (isMobileScreen) { - containerClassName = "py-2"; - titleClassName = ""; - } + const { inputNextLine, rangeNextLine } = context; let internalNextLine; - switch (childrenMeta.type) { + switch (childrenType) { case "input": internalNextLine = !!(nextline || inputNextLine); break; @@ -76,20 +69,18 @@ export function ListItem(props: ListItemProps) { internalNextLine = false; } - const update = useCallback((m: ChildrenMeta) => { - setMeta(m); + const updateType = useCallback((m: ChildrenMeta) => { + setMeta(m.type); }, []); return (
-
+
{title}
@@ -97,7 +88,7 @@ export function ListItem(props: ListItemProps) {
{subTitle}
)}
- +
{!noLogo && } diff --git a/app/components/MenuLayout/index.tsx b/app/components/MenuLayout/index.tsx index fb20728f3..d5355aa9d 100644 --- a/app/components/MenuLayout/index.tsx +++ b/app/components/MenuLayout/index.tsx @@ -59,23 +59,20 @@ export default function MenuLayout< ), }); - let containerClassName = "flex h-[100%] w-[100%]"; - let listClassName = - "relative basis-sidebar h-[calc(100%-1.25rem)] pb-6 max-md:px-4 max-md:pb-4 rounded-md my-2.5 bg-menu"; - let panelClassName = "flex-1 h-[100%] w-page"; - - if (isMobileScreen) { - containerClassName = "h-[100%] w-[100%] relative bg-center"; - listClassName = `h-[100%] w-[100%] flex-1 px-4`; - panelClassName = `transition-all duration-300 absolute top-0 max-h-[100vh] w-[100%] ${ - showPanel ? "left-0" : "left-[101%]" - } z-10`; - } - return ( -
+
{ if (e.target === e.currentTarget) { navigate(Path.Home); @@ -101,7 +98,14 @@ export default function MenuLayout<
)}
-
+
{content} diff --git a/app/components/Screen/index.tsx b/app/components/Screen/index.tsx index c1ec1ca9f..2f7a7b19c 100644 --- a/app/components/Screen/index.tsx +++ b/app/components/Screen/index.tsx @@ -25,20 +25,13 @@ export default function Screen(props: ScreenProps) { useListenWinResize(); - let containerClassName = "flex h-[100%] w-[100%] bg-center overflow-hidden"; - let sidebarClassName = "flex-0 overflow-hidden"; - let pageClassName = "flex-1 h-[100%] min-w-0 overflow-hidden"; - - if (isMobileScreen) { - containerClassName = - "relative flex flex-col-reverse h-[100%] w-[100%] bg-center"; - sidebarClassName = "absolute w-[100%] bottom-0 z-10"; - pageClassName = "w-[100%] h-[100%]"; - } - return (
-
+
{props.sidebar}
{props.children} diff --git a/app/components/Select/index.tsx b/app/components/Select/index.tsx index 09f39ce1f..f58f34b92 100644 --- a/app/components/Select/index.tsx +++ b/app/components/Select/index.tsx @@ -52,13 +52,13 @@ const Select = (props: SearchProps) => { const content = (
{options?.map((o) => (
{ onSelect?.(o.value); }} @@ -79,13 +79,13 @@ const Select = (props: SearchProps) => { placement={ position?.poi.relativePosition[1] !== Orientation.bottom ? "rb" : "rt" } - popoverClassName="border border-select-popover rounded-md shadow-select-popover-shadow w-actions-popover bg-select-popover-panel dark:bg-select-popover-panel-dark" + popoverClassName="border border-select-popover rounded-lg shadow-select-popover-shadow w-actions-popover bg-select-popover-panel dark:bg-select-popover-panel-dark" onShow={(e) => { getRelativePosition(contentRef.current!, ""); }} >
diff --git a/app/components/SlideRange/index.tsx b/app/components/SlideRange/index.tsx index fabd6442d..d5f269519 100644 --- a/app/components/SlideRange/index.tsx +++ b/app/components/SlideRange/index.tsx @@ -1,5 +1,6 @@ import { useContext, useEffect, useRef } from "react"; -import { ListContext } from "../List"; +import { ListContext } from "@/app/components/List"; +import useResizeObserver from "use-resize-observer"; interface SlideRangeProps { className?: string; @@ -30,11 +31,15 @@ export default function SlideRange(props: SlideRangeProps) { const slideRef = useRef(null); + const { ref, width = 1 } = useResizeObserver(); + + ref(slideRef.current); + const transformToWidth = (x: number = start) => { const abs = x - start; - const maxWidth = (slideRef.current?.clientWidth || 1) - margin * 2; - const radio = stroke / maxWidth; - return abs / radio; + const maxWidth = width - margin * 2; + const result = (abs / stroke) * maxWidth; + return result; }; const setProperty = (value?: number) => { @@ -44,37 +49,36 @@ export default function SlideRange(props: SlideRangeProps) { `${initWidth + margin}px`, ); }; - useEffect(() => { setProperty(value); update?.({ type: "range" }); - }, []); + }, [width]); return (
{!!description && ( -
+
{description}
)}
-
+
 
{value}
: , placement: "left", }, - { - onClick: nextTheme, - text: Locale.Chat.InputActions.Theme[theme], - isShow: true, - icon: ( - <> - {theme === Theme.Auto ? ( - - ) : theme === Theme.Light ? ( - - ) : theme === Theme.Dark ? ( - - ) : null} - - ), - placement: "left", - }, + // { + // onClick: nextTheme, + // text: Locale.Chat.InputActions.Theme[theme], + // isShow: true, + // icon: ( + // <> + // {theme === Theme.Auto ? ( + // + // ) : theme === Theme.Light ? ( + // + // ) : theme === Theme.Dark ? ( + // + // ) : null} + // + // ), + // placement: "left", + // }, { onClick: props.showPromptHints, text: Locale.Chat.InputActions.Prompt, @@ -201,6 +201,7 @@ export function ChatActions(props: { placement="rt" noArrow popoverClassName="border border-chat-actions-popover-mobile rounded-md shadow-chat-actions-popover-mobile w-actions-popover bg-chat-actions-popover-panel-mobile " + className=" cursor-pointer" > @@ -222,7 +223,7 @@ export function ChatActions(props: { placement={ind ? "t" : "lt"} >
{act.icon} @@ -242,7 +243,7 @@ export function ChatActions(props: { placement={ind === arr.length - 1 ? "rt" : "t"} >
{act.icon} diff --git a/app/containers/Chat/ChatHeader.tsx b/app/containers/Chat/ChatHeader.tsx index 88c8e9f53..c858d7619 100644 --- a/app/containers/Chat/ChatHeader.tsx +++ b/app/containers/Chat/ChatHeader.tsx @@ -30,21 +30,13 @@ export default function ChatHeader(props: ChatHeaderProps) { const currentModel = chatStore.currentSession().mask.modelConfig.model; - let containerClassName = ""; - let titleClassName = "mr-4"; - let mainTitleClassName = ""; - let subTitleClassName = ""; - - if (isMobileScreen) { - containerClassName = "h-menu-title-mobile"; - titleClassName = "flex flex-col items-center justify-center gap-0.5 text"; - mainTitleClassName = "text-sm-title h-[19px] leading-5"; - subTitleClassName = "text-sm-mobile-tab leading-4"; - } - return (
{isMobileScreen ? ( -
navigate(Path.Home)}> +
navigate(Path.Home)}>
) : ( )} -
+
setIsEditingMessage(true)} > {!session.topic ? DEFAULT_TOPIC : session.topic}
{isMobileScreen ? (
showModelSelector(true)} > {currentModel} @@ -86,6 +90,7 @@ export default function ChatHeader(props: ChatHeaderProps) {
{ setShowExport(true); }} diff --git a/app/containers/Chat/ChatInputPanel.tsx b/app/containers/Chat/ChatInputPanel.tsx index d57e3b239..069a7f261 100644 --- a/app/containers/Chat/ChatInputPanel.tsx +++ b/app/containers/Chat/ChatInputPanel.tsx @@ -203,29 +203,28 @@ export default forwardRef( emitImages: setAttachImages, setUploading, }); - let containerClassName = "border-t border-chat-input-top"; - let inputClassName = " flex flex-col px-5 pb-5"; - let actionsClassName = "py-2.5"; - let labelClassName = "rounded-md p-4 gap-4"; - let textarea = "min-h-chat-input"; - - if (isMobileScreen) { - containerClassName = "rounded-tl-md rounded-tr-md"; - inputClassName = "flex flex-row-reverse items-center gap-2 p-3"; - actionsClassName = ""; - labelClassName = " rounded-chat-input p-3 gap-3 flex-1"; - textarea = "h-chat-input-mobile"; - } return ( -
+
-
+
( setUserInput("/"); onSearch(""); }} - className={actionsClassName} + className={` + md:py-2.5 + `} isMobileScreen={isMobileScreen} />