mirror of
https://github.com/coaidev/coai.git
synced 2025-06-03 12:20:15 +09:00
feat: optimize mobile adaptation
This commit is contained in:
parent
dccc2f44ab
commit
f2bf2bdf76
@ -38,7 +38,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
max-width: calc(100vw - 64px);
|
max-width: 100%;
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
scrollbar-width: thin;
|
scrollbar-width: thin;
|
||||||
@ -63,6 +63,7 @@
|
|||||||
|
|
||||||
.content-wrapper {
|
.content-wrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
|
||||||
.message-toolbar {
|
.message-toolbar {
|
||||||
@ -100,6 +101,7 @@
|
|||||||
width: max-content;
|
width: max-content;
|
||||||
height: max-content;
|
height: max-content;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
margin-left: 3rem;
|
||||||
|
|
||||||
&.subscription {
|
&.subscription {
|
||||||
svg, span {
|
svg, span {
|
||||||
@ -142,26 +144,57 @@
|
|||||||
.message-avatar-wrapper {
|
.message-avatar-wrapper {
|
||||||
.message-avatar {
|
.message-avatar {
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 2.95rem;
|
width: 2.5rem;
|
||||||
height: 2.95rem;
|
height: 2.5rem;
|
||||||
border-radius: var(--radius);
|
border-radius: var(--radius);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 1rem;
|
font-size: 0.785rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
margin-left: 0.5rem;
|
margin-left: 0.5rem;
|
||||||
border-radius: var(--radius);
|
border-radius: var(--radius);
|
||||||
border: 1px solid hsl(var(--border));
|
border: 1px solid hsl(var(--border));
|
||||||
width: 2.95rem;
|
width: 2.5rem;
|
||||||
height: 2.95rem;
|
height: 2.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.user {
|
&.user {
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.content-wrapper {
|
||||||
|
flex-direction: column !important;
|
||||||
|
align-items: flex-start;
|
||||||
|
|
||||||
|
.message-avatar-wrapper {
|
||||||
|
margin-left: 0;
|
||||||
|
margin-right: 0;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-toolbar {
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-quota {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.user {
|
||||||
|
.content-wrapper {
|
||||||
|
align-items: flex-end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.user {
|
&.user {
|
||||||
|
.content-wrapper {
|
||||||
|
flex-direction: row-reverse;
|
||||||
|
}
|
||||||
|
|
||||||
.message-content {
|
.message-content {
|
||||||
background: hsl(var(--background));
|
background: hsl(var(--background));
|
||||||
border: 1px solid hsl(var(--border));
|
border: 1px solid hsl(var(--border));
|
||||||
@ -297,7 +330,7 @@
|
|||||||
width: max-content;
|
width: max-content;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
word-wrap: anywhere;
|
word-wrap: anywhere;
|
||||||
max-width: calc(100vw - 102px);
|
max-width: 100%;
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: 20px;
|
width: 20px;
|
||||||
|
@ -202,10 +202,6 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
|
|
||||||
.message {
|
|
||||||
max-width: calc(100vw - 2rem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
|
@ -33,6 +33,7 @@ import { useSelector } from "react-redux";
|
|||||||
import { selectUsername } from "@/store/auth.ts";
|
import { selectUsername } from "@/store/auth.ts";
|
||||||
import { appLogo } from "@/conf/env.ts";
|
import { appLogo } from "@/conf/env.ts";
|
||||||
import Icon from "@/components/utils/Icon.tsx";
|
import Icon from "@/components/utils/Icon.tsx";
|
||||||
|
import { useMobile } from "@/utils/device.ts";
|
||||||
|
|
||||||
type MessageProps = {
|
type MessageProps = {
|
||||||
index: number;
|
index: number;
|
||||||
@ -45,12 +46,13 @@ type MessageProps = {
|
|||||||
|
|
||||||
function MessageSegment(props: MessageProps) {
|
function MessageSegment(props: MessageProps) {
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
|
const mobile = useMobile();
|
||||||
const { message } = props;
|
const { message } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`message ${message.role}`} ref={ref}>
|
<div className={`message ${message.role}`} ref={ref}>
|
||||||
<MessageContent {...props} />
|
<MessageContent {...props} />
|
||||||
<MessageQuota message={message} />
|
{!mobile && <MessageQuota message={message} />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -96,6 +98,7 @@ function MessageQuota({ message }: MessageQuotaProps) {
|
|||||||
|
|
||||||
function MessageContent({ message, end, index, onEvent }: MessageProps) {
|
function MessageContent({ message, end, index, onEvent }: MessageProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const mobile = useMobile();
|
||||||
const isAssistant = message.role === "assistant";
|
const isAssistant = message.role === "assistant";
|
||||||
const isUser = message.role === "user";
|
const isUser = message.role === "user";
|
||||||
|
|
||||||
@ -107,12 +110,7 @@ function MessageContent({ message, end, index, onEvent }: MessageProps) {
|
|||||||
const [editedMessage, setEditedMessage] = useState<string | undefined>("");
|
const [editedMessage, setEditedMessage] = useState<string | undefined>("");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={"content-wrapper"}>
|
||||||
className={cn(
|
|
||||||
"content-wrapper",
|
|
||||||
!isUser ? "flex-row" : "flex-row-reverse",
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<EditorProvider
|
<EditorProvider
|
||||||
submittable={true}
|
submittable={true}
|
||||||
onSubmit={(value) => onEvent && onEvent("edit", index, value)}
|
onSubmit={(value) => onEvent && onEvent("edit", index, value)}
|
||||||
@ -145,10 +143,17 @@ function MessageContent({ message, end, index, onEvent }: MessageProps) {
|
|||||||
<Loader2 className={`h-5 w-5 m-1 animate-spin`} />
|
<Loader2 className={`h-5 w-5 m-1 animate-spin`} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className={`message-toolbar`}>
|
<div className={cn(`message-toolbar`, mobile && "w-full")}>
|
||||||
<DropdownMenu open={dropdown} onOpenChange={setDropdown}>
|
<DropdownMenu open={dropdown} onOpenChange={setDropdown}>
|
||||||
<DropdownMenuTrigger className={`outline-none`}>
|
<DropdownMenuTrigger
|
||||||
<MoreVertical className={`h-4 w-4 m-0.5`} />
|
className={cn(`flex flex-row outline-none`, mobile && "my-1.5")}
|
||||||
|
>
|
||||||
|
{mobile && <MessageQuota message={message} />}
|
||||||
|
{!mobile ? (
|
||||||
|
<MoreVertical className={`h-4 w-4 m-0.5`} />
|
||||||
|
) : (
|
||||||
|
<PencilLine className={cn(`h-6 w-6 p-1`, "ml-auto")} />
|
||||||
|
)}
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align={`end`}>
|
<DropdownMenuContent align={`end`}>
|
||||||
{isAssistant && end && (
|
{isAssistant && end && (
|
||||||
|
@ -19,6 +19,7 @@ type TipsProps = {
|
|||||||
trigger?: React.ReactNode;
|
trigger?: React.ReactNode;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
classNameTrigger?: string;
|
||||||
classNamePopup?: string;
|
classNamePopup?: string;
|
||||||
hideTimeout?: number;
|
hideTimeout?: number;
|
||||||
notHide?: boolean;
|
notHide?: boolean;
|
||||||
@ -33,6 +34,7 @@ function Tips({
|
|||||||
trigger,
|
trigger,
|
||||||
children,
|
children,
|
||||||
className,
|
className,
|
||||||
|
classNameTrigger,
|
||||||
classNamePopup,
|
classNamePopup,
|
||||||
hideTimeout,
|
hideTimeout,
|
||||||
notHide,
|
notHide,
|
||||||
@ -73,7 +75,12 @@ function Tips({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu open={drop} onOpenChange={setDrop}>
|
<DropdownMenu open={drop} onOpenChange={setDrop}>
|
||||||
<DropdownMenuTrigger className={`tips-trigger select-none outline-none`}>
|
<DropdownMenuTrigger
|
||||||
|
className={cn(
|
||||||
|
`tips-trigger select-none outline-none`,
|
||||||
|
classNameTrigger,
|
||||||
|
)}
|
||||||
|
>
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
<Tooltip open={tooltip} onOpenChange={setTooltip}>
|
<Tooltip open={tooltip} onOpenChange={setTooltip}>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
|
@ -36,7 +36,11 @@ func NewChatRequest(group string, props *adapter.ChatProps, hook globals.Hook) e
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PreflightCache(cache *redis.Client, hash string, buffer *utils.Buffer, hook globals.Hook) (int64, bool, error) {
|
func PreflightCache(cache *redis.Client, model string, hash string, buffer *utils.Buffer, hook globals.Hook) (int64, bool, error) {
|
||||||
|
if !utils.Contains(model, globals.CacheAcceptedModels) {
|
||||||
|
return 0, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
idx := utils.Intn64(globals.CacheAcceptedSize)
|
idx := utils.Intn64(globals.CacheAcceptedSize)
|
||||||
key := fmt.Sprintf("chat-cache:%d:%s", idx, hash)
|
key := fmt.Sprintf("chat-cache:%d:%s", idx, hash)
|
||||||
|
|
||||||
@ -76,7 +80,7 @@ func StoreCache(cache *redis.Client, hash string, index int64, buffer *utils.Buf
|
|||||||
|
|
||||||
func NewChatRequestWithCache(cache *redis.Client, buffer *utils.Buffer, group string, props *adapter.ChatProps, hook globals.Hook) (bool, error) {
|
func NewChatRequestWithCache(cache *redis.Client, buffer *utils.Buffer, group string, props *adapter.ChatProps, hook globals.Hook) (bool, error) {
|
||||||
hash := utils.Md5Encrypt(utils.Marshal(props))
|
hash := utils.Md5Encrypt(utils.Marshal(props))
|
||||||
idx, hit, err := PreflightCache(cache, hash, buffer, hook)
|
idx, hit, err := PreflightCache(cache, props.Model, hash, buffer, hook)
|
||||||
if hit {
|
if hit {
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user