Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#959 from Yidadaa/0420-mask
Browse files Browse the repository at this point in the history
refactor: close ChatGPTNextWeb#643 use react router
  • Loading branch information
Yidadaa authored Apr 20, 2023
2 parents ee0f847 + 82ad057 commit a62bca4
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 184 deletions.
39 changes: 29 additions & 10 deletions app/components/chat-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
import { useChatStore } from "../store";

import Locale from "../locales";
import { Link, useNavigate } from "react-router-dom";
import { Path } from "../constant";

export function ChatItem(props: {
onClick?: () => void;
Expand All @@ -20,6 +22,7 @@ export function ChatItem(props: {
selected: boolean;
id: number;
index: number;
narrow?: boolean;
}) {
return (
<Draggable draggableId={`${props.id}`} index={props.index}>
Expand All @@ -33,13 +36,20 @@ export function ChatItem(props: {
{...provided.draggableProps}
{...provided.dragHandleProps}
>
<div className={styles["chat-item-title"]}>{props.title}</div>
<div className={styles["chat-item-info"]}>
<div className={styles["chat-item-count"]}>
{Locale.ChatItem.ChatItemCount(props.count)}
</div>
<div className={styles["chat-item-date"]}>{props.time}</div>
</div>
{props.narrow ? (
<div className={styles["chat-item-narrow"]}>{props.count}</div>
) : (
<>
<div className={styles["chat-item-title"]}>{props.title}</div>
<div className={styles["chat-item-info"]}>
<div className={styles["chat-item-count"]}>
{Locale.ChatItem.ChatItemCount(props.count)}
</div>
<div className={styles["chat-item-date"]}>{props.time}</div>
</div>
</>
)}

<div className={styles["chat-item-delete"]} onClick={props.onDelete}>
<DeleteIcon />
</div>
Expand All @@ -49,7 +59,7 @@ export function ChatItem(props: {
);
}

export function ChatList() {
export function ChatList(props: { narrow?: boolean }) {
const [sessions, selectedIndex, selectSession, removeSession, moveSession] =
useChatStore((state) => [
state.sessions,
Expand All @@ -59,6 +69,7 @@ export function ChatList() {
state.moveSession,
]);
const chatStore = useChatStore();
const navigate = useNavigate();

const onDragEnd: OnDragEndResponder = (result) => {
const { destination, source } = result;
Expand Down Expand Up @@ -94,8 +105,16 @@ export function ChatList() {
id={item.id}
index={i}
selected={i === selectedIndex}
onClick={() => selectSession(i)}
onDelete={() => chatStore.deleteSession(i)}
onClick={() => {
navigate(Path.Chat);
selectSession(i);
}}
onDelete={() => {
if (!props.narrow || confirm(Locale.Home.DeleteChat)) {
chatStore.deleteSession(i);
}
}}
narrow={props.narrow}
/>
))}
{provided.placeholder}
Expand Down
14 changes: 7 additions & 7 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import styles from "./home.module.scss";
import chatStyle from "./chat.module.scss";

import { Input, Modal, showModal } from "./ui-lib";
import { useNavigate } from "react-router-dom";
import { Path } from "../constant";

const Markdown = dynamic(
async () => memo((await import("./markdown")).Markdown),
Expand Down Expand Up @@ -418,10 +420,7 @@ export function ChatActions(props: {
);
}

export function Chat(props: {
showSideBar?: () => void;
sideBarShowing?: boolean;
}) {
export function Chat() {
type RenderMessage = Message & { preview?: boolean };

const chatStore = useChatStore();
Expand All @@ -439,6 +438,7 @@ export function Chat(props: {
const { scrollRef, setAutoScroll, scrollToBottom } = useScrollToBottom();
const [hitBottom, setHitBottom] = useState(false);
const isMobileScreen = useMobileScreen();
const navigate = useNavigate();

const onChatBodyScroll = (e: HTMLElement) => {
const isTouchBottom = e.scrollTop + e.clientHeight >= e.scrollHeight - 20;
Expand Down Expand Up @@ -641,7 +641,7 @@ export function Chat(props: {

// Auto focus
useEffect(() => {
if (props.sideBarShowing && isMobileScreen) return;
if (isMobileScreen) return;
inputRef.current?.focus();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand All @@ -666,7 +666,7 @@ export function Chat(props: {
icon={<ReturnIcon />}
bordered
title={Locale.Chat.Actions.ChatList}
onClick={props?.showSideBar}
onClick={() => navigate(Path.Home)}
/>
</div>
<div className={styles["window-action-button"]}>
Expand Down Expand Up @@ -830,7 +830,7 @@ export function Chat(props: {
setAutoScroll(false);
setTimeout(() => setPromptHints([]), 500);
}}
autoFocus={!props?.sideBarShowing}
autoFocus
rows={inputRows}
/>
<IconButton
Expand Down
69 changes: 68 additions & 1 deletion app/components/home.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
flex-direction: column;
box-shadow: inset -2px 0px 2px 0px rgb(0, 0, 0, 0.05);
position: relative;
transition: width ease 0.1s;
transition: width ease 0.05s;
}

.sidebar-drag {
Expand Down Expand Up @@ -126,11 +126,13 @@
.sidebar-title {
font-size: 20px;
font-weight: bold;
animation: slide-in ease 0.3s;
}

.sidebar-sub-title {
font-size: 12px;
font-weight: 400px;
animation: slide-in ease 0.3s;
}

.sidebar-body {
Expand Down Expand Up @@ -171,6 +173,7 @@
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
animation: slide-in ease 0.3s;
}

.chat-item-delete {
Expand All @@ -197,6 +200,7 @@
color: rgb(166, 166, 166);
font-size: 12px;
margin-top: 8px;
animation: slide-in ease 0.3s;
}

.chat-item-count,
Expand All @@ -206,6 +210,69 @@
white-space: nowrap;
}

.narrow-sidebar {
.sidebar-title,
.sidebar-sub-title {
display: none;
}
.sidebar-logo {
position: relative;
display: flex;
justify-content: center;
}

.chat-item {
padding: 0;
min-height: 50px;
display: flex;
justify-content: center;
align-items: center;
transition: all ease 0.3s;

&:hover {
.chat-item-narrow {
transform: scale(0.7) translateX(-50%);
}
}
}

.chat-item-narrow {
font-weight: bolder;
font-size: 24px;
line-height: 0;
font-weight: lighter;
color: var(--black);
transform: translateX(0);
transition: all ease 0.3s;
opacity: 0.1;
padding: 4px;
}

.chat-item-delete {
top: 15px;
}

.chat-item:hover > .chat-item-delete {
opacity: 0.5;
right: 5px;
}

.sidebar-tail {
flex-direction: column;
align-items: center;

.sidebar-actions {
flex-direction: column;
align-items: center;

.sidebar-action {
margin-right: 0;
margin-bottom: 15px;
}
}
}
}

.sidebar-tail {
display: flex;
justify-content: space-between;
Expand Down
Loading

0 comments on commit a62bca4

Please sign in to comment.