Skip to content

Commit 7e4f4b5

Browse files
authored
feat: mobile terminal adaptation about style (#348)
* feat: mobile terminal adaptation * feat: mobile terminal adaptation * feat: mobile terminal adaptation * docs: update notes * chore: remove log
1 parent c053b55 commit 7e4f4b5

31 files changed

Lines changed: 139 additions & 88 deletions

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Information about release notes of Coco Server is provided here.
3838

3939
- feat: support multi websocket connections #314
4040
- feat: add support for embeddable web widget #277
41+
- feat: mobile terminal adaptation about style #348
4142

4243
### Bug fix
4344

src-tauri/src/search/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub async fn query_coco_fusion<R: Runtime>(
4141
timeout(timeout_duration, async {
4242
query_source_clone.search(query).await
4343
})
44-
.await
44+
.await
4545
}));
4646
}
4747

src/api/axiosRequest.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ export const Get = <T>(
5050
// console.log("baseURL", appStore.state?.endpoint_http)
5151

5252
let baseURL = appStore.state?.endpoint_http;
53+
const isDev = import.meta.env.DEV;
54+
5355
axios
54-
.get(baseURL + url, { params })
56+
.get(isDev ? url : baseURL + url, { params })
5557
.then((result) => {
5658
let res: FcResponse<T>;
5759
if (clearFn !== undefined) {
@@ -77,9 +79,10 @@ export const Post = <T>(
7779
// console.log("baseURL", appStore.state?.endpoint_http)
7880

7981
let baseURL = appStore.state?.endpoint_http;
82+
const isDev = import.meta.env.DEV;
8083

8184
axios
82-
.post(baseURL + url, data, {
85+
.post(isDev ? url : baseURL + url, data, {
8386
params,
8487
headers,
8588
} as any)

src/components/Assistant/ChatHeader.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { useChatStore } from "@/stores/chatStore";
3030
import type { Chat } from "./types";
3131
import { useConnectStore } from "@/stores/connectStore";
3232
import platformAdapter from "@/utils/platformAdapter";
33-
import { list_coco_servers } from "@/commands";
3433
import VisibleKey from "../Common/VisibleKey";
3534
import { useShortcutsStore } from "@/stores/shortcutsStore";
3635

@@ -86,7 +85,7 @@ export function ChatHeader({
8685

8786
const fetchServers = useCallback(
8887
async (resetSelection: boolean) => {
89-
list_coco_servers()
88+
platformAdapter.commands("list_coco_servers")
9089
.then((res: any) => {
9190
const enabledServers = (res as IServer[]).filter(
9291
(server) => server.enabled !== false

src/components/Assistant/FileList.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useTranslation } from "react-i18next";
77
import { useChatStore } from "@/stores/chatStore";
88
import { useConnectStore } from "@/stores/connectStore";
99
import FileIcon from "../Common/Icons/FileIcon";
10-
import { delete_attachment, upload_attachment } from "@/commands";
10+
import platformAdapter from "@/utils/platformAdapter";
1111

1212
interface FileListProps {
1313
sessionId: string;
@@ -39,11 +39,14 @@ const FileList = (props: FileListProps) => {
3939

4040
if (uploaded) continue;
4141

42-
const attachmentIds = await upload_attachment({
43-
serverId,
44-
sessionId,
45-
filePaths: [path],
46-
});
42+
const attachmentIds: any = await platformAdapter.commands(
43+
"upload_attachment",
44+
{
45+
serverId,
46+
sessionId,
47+
filePaths: [path],
48+
}
49+
);
4750

4851
if (!attachmentIds) continue;
4952

@@ -59,7 +62,10 @@ const FileList = (props: FileListProps) => {
5962
const deleteFile = async (id: string, attachmentId: string) => {
6063
setUploadFiles(uploadFiles.filter((file) => file.id !== id));
6164

62-
delete_attachment({ serverId, id: attachmentId });
65+
platformAdapter.commands("delete_attachment", {
66+
serverId,
67+
id: attachmentId,
68+
});
6369
};
6470

6571
return (

src/components/Assistant/SessionFile.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { useTranslation } from "react-i18next";
77
import { useConnectStore } from "@/stores/connectStore";
88
import Checkbox from "@/components/Common/Checkbox";
99
import FileIcon from "@/components/Common/Icons/FileIcon";
10-
import { delete_attachment, get_attachment } from "@/commands";
1110
import { AttachmentHit } from "@/types/commands";
1211
import { useAppStore } from "@/stores/appStore";
12+
import platformAdapter from "@/utils/platformAdapter";
1313

1414
interface SessionFileProps {
1515
sessionId: string;
@@ -37,7 +37,10 @@ const SessionFile = (props: SessionFileProps) => {
3737

3838
const getUploadedFiles = async () => {
3939
if (isTauri) {
40-
const response = await get_attachment({ serverId, sessionId });
40+
const response: any = await platformAdapter.commands("get_attachment", {
41+
serverId,
42+
sessionId,
43+
});
4144

4245
setUploadedFiles(response.hits.hits);
4346
} else {
@@ -47,7 +50,10 @@ const SessionFile = (props: SessionFileProps) => {
4750
const handleDelete = async (id: string) => {
4851
let result;
4952
if (isTauri) {
50-
result = await delete_attachment({ serverId, id });
53+
result = await platformAdapter.commands("delete_attachment", {
54+
serverId,
55+
id,
56+
});
5157
} else {
5258
}
5359
if (!result) return;

src/components/AudioRecording/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import RecordPlugin from "wavesurfer.js/dist/plugins/record.esm.js";
1111

1212
import { useConnectStore } from "@/stores/connectStore";
1313
import { useShortcutsStore } from "@/stores/shortcutsStore";
14-
import { transcription } from "@/commands";
1514
import VisibleKey from "@/components/Common/VisibleKey";
1615
import { useAppStore } from "@/stores/appStore";
16+
import platformAdapter from "@/utils/platformAdapter";
1717

1818
interface AudioRecordingProps {
1919
onChange?: (text: string) => void;
@@ -78,7 +78,7 @@ const AudioRecording: FC<AudioRecordingProps> = (props) => {
7878
reader.onloadend = async () => {
7979
const base64Audio = (reader.result as string).split(",")[1];
8080

81-
const response = await transcription({
81+
const response: any = await platformAdapter.commands("transcription", {
8282
serverId: currentService.id,
8383
audioType: "mp3",
8484
audioContent: base64Audio,

src/components/ChatMessage/FetchSource.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface ISourceData {
3434
url: string;
3535
}
3636

37-
export const FetchSource = ({ Detail, ChunkData }: FetchSourceProps) => {
37+
export const FetchSource = ({ Detail, ChunkData, loading }: FetchSourceProps) => {
3838
const { t } = useTranslation();
3939
const [isSourceExpanded, setIsSourceExpanded] = useState(false);
4040

@@ -51,30 +51,34 @@ export const FetchSource = ({ Detail, ChunkData }: FetchSourceProps) => {
5151
useEffect(() => {
5252
if (!ChunkData?.message_chunk) return;
5353

54-
try {
55-
const match = ChunkData.message_chunk.match(
56-
/\u003cPayload total=(\d+)\u003e/
57-
);
58-
if (match) {
59-
setTotal(Number(match[1]));
60-
}
54+
if (!loading) {
55+
try {
56+
const match = ChunkData.message_chunk.match(
57+
// /\u003cPayload total=(\d+)\u003e/
58+
/<Payload total=(\d+)>/
59+
);
60+
if (match) {
61+
setTotal(Number(match[1]));
62+
}
6163

62-
const jsonMatch = ChunkData.message_chunk.match(/\[(.*)\]/s);
63-
if (jsonMatch) {
64-
const jsonData = JSON.parse(jsonMatch[0]);
65-
setData(jsonData);
64+
// const jsonMatch = ChunkData.message_chunk.match(/\[(.*)\]/s);
65+
const jsonMatch = ChunkData.message_chunk.match(/\[([\s\S]*)\]/);
66+
if (jsonMatch) {
67+
const jsonData = JSON.parse(jsonMatch[0]);
68+
setData(jsonData);
69+
}
70+
} catch (e) {
71+
console.error("Failed to parse fetch source data:", e);
6672
}
67-
} catch (e) {
68-
console.error("Failed to parse fetch source data:", e);
6973
}
70-
}, [ChunkData?.message_chunk]);
74+
}, [ChunkData?.message_chunk, loading]);
7175

7276
// Must be after hooks !!!
7377
if (!ChunkData && !Detail) return null;
7478

7579
return (
7680
<div
77-
className={`mt-2 mb-2 w-[610px] ${
81+
className={`mt-2 mb-2 max-w-full w-full md:w-[610px] ${
7882
isSourceExpanded
7983
? "rounded-lg overflow-hidden border border-[#E6E6E6] dark:border-[#272626]"
8084
: ""
@@ -120,13 +124,13 @@ export const FetchSource = ({ Detail, ChunkData }: FetchSourceProps) => {
120124
className="group flex items-center p-2 hover:bg-[#F7F7F7] dark:hover:bg-[#2C2C2C] border-b border-[#E6E6E6] dark:border-[#272626] last:border-b-0 cursor-pointer transition-colors"
121125
>
122126
<div className="w-full flex items-center gap-2">
123-
<div className="w-[75%] flex items-center gap-1">
127+
<div className="w-full md:w-[75%] flex items-center gap-1">
124128
<Globe className="w-3 h-3 flex-shrink-0" />
125129
<div className="text-xs text-[#333333] dark:text-[#D8D8D8] truncate font-normal group-hover:text-[#0072FF] dark:group-hover:text-[#0072FF]">
126130
{item.title || item.category}
127131
</div>
128132
</div>
129-
<div className="w-[25%] flex items-center justify-end gap-2">
133+
<div className="hidden md:flex w-[25%] items-center justify-end gap-2">
130134
<span className="text-xs text-[#999999] dark:text-[#999999] truncate">
131135
{item.source?.name}
132136
</span>

src/components/ChatMessage/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ export const ChatMessage = memo(function ChatMessage({
125125
}`}
126126
>
127127
<div
128-
className={`space-y-2 ${isAssistant ? "text-left" : "text-right"}`}
128+
className={`w-full space-y-2 ${isAssistant ? "text-left" : "text-right"}`}
129129
>
130-
<p className="flex items-center gap-1 font-semibold text-sm text-[#333] dark:text-[#d8d8d8]">
130+
<p className="w-full flex items-center gap-1 font-semibold text-sm text-[#333] dark:text-[#d8d8d8]">
131131
{isAssistant ? (
132132
<img
133133
src={logoImg}
@@ -137,8 +137,8 @@ export const ChatMessage = memo(function ChatMessage({
137137
) : null}
138138
{isAssistant ? t("assistant.message.aiName") : ""}
139139
</p>
140-
<div className="prose dark:prose-invert prose-sm max-w-none">
141-
<div className="pl-7 text-[#333] dark:text-[#d8d8d8] leading-relaxed">
140+
<div className="w-full prose dark:prose-invert prose-sm max-w-none">
141+
<div className="w-full pl-7 text-[#333] dark:text-[#d8d8d8] leading-relaxed">
142142
{renderContent()}
143143
</div>
144144
</div>

src/components/Common/UI/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default function Footer({
9999
<Copyright />
100100
)}
101101

102-
<div className="flex items-center gap-3">
102+
<div className="hidden md:flex items-center gap-3">
103103
<div className="gap-1 flex items-center text-[#666] dark:text-[#666] text-xs">
104104
<span className="mr-1.5">{t("search.footer.select")}:</span>
105105
<kbd className="coco-modal-footer-commands-key pr-1">

0 commit comments

Comments
 (0)