From d5c33a11839d45990a0da0d015de445bf0b59789 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Tue, 27 Jun 2023 23:07:12 +0800 Subject: [PATCH 1/7] fix: #2149 try to fix ChatAction style on ios mobile --- app/components/chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index ad38dd650..15303124a 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -310,7 +310,7 @@ function ChatAction(props: { } useEffect(() => { - updateWidth(); + setTimeout(updateWidth, 100); }, []); return ( From 38c8ee8cd2b9689ad7499a99cc79edf2374c17dd Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Tue, 27 Jun 2023 23:29:53 +0800 Subject: [PATCH 2/7] feat: improve message item buttons style --- app/components/chat.module.scss | 17 ++++++++++++----- app/components/chat.tsx | 22 +++++++++++----------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/components/chat.module.scss b/app/components/chat.module.scss index c3e7c619b..b908f2205 100644 --- a/app/components/chat.module.scss +++ b/app/components/chat.module.scss @@ -281,15 +281,13 @@ border: var(--border-in-light); position: relative; transition: all ease 0.3s; - min-width: 0; &:hover { - min-width: 330px; - .chat-message-actions { - height: 40px; opacity: 1; transform: translateY(0px); + max-width: 100%; + height: 40px; .chat-message-action-date { opacity: 0.3; @@ -299,7 +297,6 @@ .chat-message-actions { display: flex; - width: 100%; box-sizing: border-box; font-size: 12px; align-items: flex-end; @@ -308,11 +305,21 @@ transform: translateY(10px); opacity: 0; height: 0; + max-width: 0; + + .chat-input-actions { + display: flex; + flex-wrap: nowrap; + } } .chat-message-action-date { + white-space: nowrap; + transition: all ease 0.6s; color: var(--black); opacity: 0; + text-align: right; + margin-left: 20px; } } diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 15303124a..81dadd8d7 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -937,30 +937,30 @@ export function Chat() { /> ) : ( <> - } - onClick={() => onDelete(message.id ?? i)} - /> - } onClick={() => onResend(message.id ?? i)} /> + } + onClick={() => onDelete(message.id ?? i)} + /> + } onClick={() => onPinMessage(message)} /> + } + onClick={() => copyToClipboard(message.content)} + /> )} - } - onClick={() => copyToClipboard(message.content)} - />
From 6caf79121b7fa28c02400b7d26c260628cc61058 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Tue, 27 Jun 2023 23:39:27 +0800 Subject: [PATCH 3/7] feat: improve chat commands --- app/components/chat.tsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 81dadd8d7..32cab346c 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -515,14 +515,6 @@ export function Chat() { { leading: true, trailing: true }, ); - const onPromptSelect = (prompt: Prompt) => { - setTimeout(() => { - setPromptHints([]); - setUserInput(prompt.content); - inputRef.current?.focus(); - }, 30); - }; - // auto grow input const [inputRows, setInputRows] = useState(2); const measure = useDebouncedCallback( @@ -595,6 +587,23 @@ export function Chat() { setAutoScroll(true); }; + const onPromptSelect = (prompt: Prompt) => { + setTimeout(() => { + setPromptHints([]); + + const matchedChatCommand = chatCommands.match(prompt.content); + if (matchedChatCommand.matched) { + // if user is selecting a chat command, just trigger it + matchedChatCommand.invoke(); + setUserInput(""); + } else { + // or fill the prompt + setUserInput(prompt.content); + } + inputRef.current?.focus(); + }, 30); + }; + // stop response const onUserStop = (messageId: number) => { ChatControllerPool.stop(sessionIndex, messageId); From 1dd75b63de6745ece9de5df57663af751698c82d Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Wed, 28 Jun 2023 00:34:01 +0800 Subject: [PATCH 4/7] feat: [WIP] support webdav --- app/components/settings.tsx | 76 ++++++++++++++++++++++++++++++++ app/constant.ts | 1 + app/store/sync.ts | 87 +++++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 app/store/sync.ts diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 41fed620c..1d45a0c69 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -46,6 +46,7 @@ import { InputRange } from "./input-range"; import { useNavigate } from "react-router-dom"; import { Avatar, AvatarPicker } from "./emoji"; import { getClientConfig } from "../config/client"; +import { useSyncStore } from "../store/sync"; function EditPromptModal(props: { id: number; onClose: () => void }) { const promptStore = usePromptStore(); @@ -198,6 +199,78 @@ function UserPromptModal(props: { onClose?: () => void }) { ); } +function SyncItems() { + const syncStore = useSyncStore(); + const webdav = syncStore.webDavConfig; + + // not ready: https://github.com/Yidadaa/ChatGPT-Next-Web/issues/920#issuecomment-1609866332 + return null; + + return ( + + + } + text="同步" + onClick={() => { + syncStore.check().then(console.log); + }} + /> + + + + + + { + syncStore.update( + (config) => (config.server = e.currentTarget.value), + ); + }} + /> + + + + { + syncStore.update( + (config) => (config.username = e.currentTarget.value), + ); + }} + /> + + + + { + syncStore.update( + (config) => (config.password = e.currentTarget.value), + ); + }} + /> + + + ); +} + function formatVersionDate(t: string) { const d = new Date(+t); const year = d.getUTCFullYear(); @@ -556,6 +629,7 @@ export function Settings() { accessStore.updateOpenAiUrl(e.currentTarget.value) } @@ -596,6 +670,8 @@ export function Settings() { + + ; + check: () => Promise; + + path: (path: string) => string; + headers: () => { Authorization: string }; +} + +const FILE = { + root: "/chatgpt-next-web/", +}; + +export const useSyncStore = create()( + persist( + (set, get) => ({ + webDavConfig: { + server: "", + username: "", + password: "", + }, + + lastSyncTime: 0, + + update(updater) { + const config = { ...get().webDavConfig }; + updater(config); + set({ webDavConfig: config }); + }, + + async check() { + try { + const res = await fetch(this.path(""), { + method: "PROFIND", + headers: this.headers(), + }); + console.log(res); + return res.status === 207; + } catch (e) { + console.error("[Sync] ", e); + return false; + } + }, + + path(path: string) { + let url = get().webDavConfig.server; + + if (!url.endsWith("/")) { + url += "/"; + } + + if (path.startsWith("/")) { + path = path.slice(1); + } + + return url + path; + }, + + headers() { + const auth = btoa( + [get().webDavConfig.username, get().webDavConfig.password].join(":"), + ); + + return { + Authorization: `Basic ${auth}`, + }; + }, + }), + { + name: StoreKey.Sync, + version: 1, + }, + ), +); From bce74890dca87dbdab5f5171ecfb791a1f8c55be Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Wed, 28 Jun 2023 01:02:56 +0800 Subject: [PATCH 5/7] fix: #2149 try to fix chat action button style --- app/components/chat.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 32cab346c..d49a77e3d 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -294,8 +294,8 @@ function ChatAction(props: { const iconRef = useRef(null); const textRef = useRef(null); const [width, setWidth] = useState({ - full: 20, - icon: 20, + full: 16, + icon: 16, }); function updateWidth() { @@ -310,7 +310,13 @@ function ChatAction(props: { } useEffect(() => { - setTimeout(updateWidth, 100); + const onClick = () => setTimeout(updateWidth, 10); + onClick(); + + window.addEventListener("click", onClick); + return () => { + window.removeEventListener("click", onClick); + }; }, []); return ( From 5b1d45c1a9e4f2a5b65c35d96b678496a978557c Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Wed, 28 Jun 2023 01:09:25 +0800 Subject: [PATCH 6/7] fix: #2149 try to fix chat action button style --- app/components/chat.tsx | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index d49a77e3d..06b32147b 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -309,16 +309,6 @@ function ChatAction(props: { }); } - useEffect(() => { - const onClick = () => setTimeout(updateWidth, 10); - onClick(); - - window.addEventListener("click", onClick); - return () => { - window.removeEventListener("click", onClick); - }; - }, []); - return (
Date: Wed, 28 Jun 2023 01:15:55 +0800 Subject: [PATCH 7/7] fixup: #2149 chat action button style --- app/components/chat.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 06b32147b..6db5eb2b6 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -316,6 +316,8 @@ function ChatAction(props: { props.onClick(); setTimeout(updateWidth, 1); }} + onMouseEnter={updateWidth} + onTouchStart={updateWidth} style={ { "--icon-width": `${width.icon}px`,