Skip to content

Commit bab98d4

Browse files
authored
feat: add web login (#967)
* feat: add web login * refactor: update * refactor: update
1 parent 6067fa7 commit bab98d4

16 files changed

Lines changed: 489 additions & 123 deletions

src/api/axiosRequest.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,11 @@ export const Post = <T>(
112112
}
113113

114114
axios
115-
.post(
116-
baseURL + url,
117-
data,
118-
{
119-
params,
120-
headers,
121-
withCredentials: true,
122-
} as any
123-
)
115+
.post(baseURL + url, data, {
116+
params,
117+
headers,
118+
withCredentials: true,
119+
} as any)
124120
.then((result) => {
125121
resolve([null, result.data as FcResponse<T>]);
126122
})

src/components/Assistant/ChatContent.tsx

Lines changed: 94 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { useConnectStore } from "@/stores/connectStore";
1010
// import SessionFile from "./SessionFile";
1111
import ScrollToBottom from "@/components/Common/ScrollToBottom";
1212
import { useChatStore } from "@/stores/chatStore";
13+
import { useWebConfigStore } from "@/stores/webConfigStore";
14+
import { useAppStore } from "@/stores/appStore";
15+
import { NoResults } from "../Common/UI/NoResults";
1316

1417
interface ChatContentProps {
1518
activeChat?: Chat;
@@ -97,87 +100,100 @@ export const ChatContent = ({
97100
setIsAtBottom(isAtBottom);
98101
};
99102

103+
const { isTauri } = useAppStore();
104+
const { disabled } = useWebConfigStore();
105+
100106
return (
101107
<div className="flex-1 overflow-hidden flex flex-col justify-between relative user-select-text">
102-
<div
103-
ref={scrollRef}
104-
className="flex-1 w-full overflow-x-hidden overflow-y-auto border-t border-[rgba(0,0,0,0.1)] dark:border-[rgba(255,255,255,0.15)] custom-scrollbar relative"
105-
onScroll={handleScroll}
106-
>
107-
{(!activeChat || activeChat?.messages?.length === 0) &&
108-
!visibleStartPage && <Greetings />}
109-
110-
{activeChat?.messages?.map((message, index) => (
111-
<ChatMessage
112-
key={message._id + index}
113-
message={message}
114-
isTyping={false}
115-
onResend={handleSendMessage}
116-
/>
117-
))}
118-
119-
{(!curChatEnd ||
120-
query_intent ||
121-
tools ||
122-
fetch_source ||
123-
pick_source ||
124-
deep_read ||
125-
think ||
126-
response) &&
127-
activeChat?._source?.id ? (
128-
<ChatMessage
129-
key={"current"}
130-
message={{
131-
_id: "current",
132-
_source: {
133-
type: "assistant",
134-
assistant_id:
135-
allMessages[allMessages.length - 1]?._source?.assistant_id,
136-
message: "",
137-
question: Question,
138-
},
139-
}}
140-
onResend={handleSendMessage}
141-
isTyping={!curChatEnd}
142-
query_intent={query_intent}
143-
tools={tools}
144-
fetch_source={fetch_source}
145-
pick_source={pick_source}
146-
deep_read={deep_read}
147-
think={think}
148-
response={response}
149-
loadingStep={loadingStep}
150-
formatUrl={formatUrl}
151-
/>
152-
) : null}
153-
154-
{timedoutShow ? (
155-
<ChatMessage
156-
key={"timedout"}
157-
message={{
158-
_id: "timedout",
159-
_source: {
160-
type: "assistant",
161-
message: t("assistant.chat.timedout"),
162-
question: Question,
163-
},
164-
}}
165-
onResend={handleSendMessage}
166-
isTyping={false}
167-
/>
168-
) : null}
169-
<div ref={messagesEndRef} />
170-
</div>
171-
172-
{uploadAttachments.length > 0 && (
173-
<div key={currentSessionId} className="max-h-[120px] overflow-auto p-2">
174-
<AttachmentList />
175-
</div>
108+
{!isTauri && disabled ? (
109+
<NoResults />
110+
) : (
111+
<>
112+
<div
113+
ref={scrollRef}
114+
className="flex-1 w-full overflow-x-hidden overflow-y-auto border-t border-[rgba(0,0,0,0.1)] dark:border-[rgba(255,255,255,0.15)] custom-scrollbar relative"
115+
onScroll={handleScroll}
116+
>
117+
{(!activeChat || activeChat?.messages?.length === 0) &&
118+
!visibleStartPage && <Greetings />}
119+
120+
{activeChat?.messages?.map((message, index) => (
121+
<ChatMessage
122+
key={message._id + index}
123+
message={message}
124+
isTyping={false}
125+
onResend={handleSendMessage}
126+
/>
127+
))}
128+
129+
{(!curChatEnd ||
130+
query_intent ||
131+
tools ||
132+
fetch_source ||
133+
pick_source ||
134+
deep_read ||
135+
think ||
136+
response) &&
137+
activeChat?._source?.id ? (
138+
<ChatMessage
139+
key={"current"}
140+
message={{
141+
_id: "current",
142+
_source: {
143+
type: "assistant",
144+
assistant_id:
145+
allMessages[allMessages.length - 1]?._source
146+
?.assistant_id,
147+
message: "",
148+
question: Question,
149+
},
150+
}}
151+
onResend={handleSendMessage}
152+
isTyping={!curChatEnd}
153+
query_intent={query_intent}
154+
tools={tools}
155+
fetch_source={fetch_source}
156+
pick_source={pick_source}
157+
deep_read={deep_read}
158+
think={think}
159+
response={response}
160+
loadingStep={loadingStep}
161+
formatUrl={formatUrl}
162+
/>
163+
) : null}
164+
165+
{timedoutShow ? (
166+
<ChatMessage
167+
key={"timedout"}
168+
message={{
169+
_id: "timedout",
170+
_source: {
171+
type: "assistant",
172+
message: t("assistant.chat.timedout"),
173+
question: Question,
174+
},
175+
}}
176+
onResend={handleSendMessage}
177+
isTyping={false}
178+
/>
179+
) : null}
180+
<div ref={messagesEndRef} />
181+
</div>
182+
183+
{uploadAttachments.length > 0 && (
184+
<div
185+
key={currentSessionId}
186+
className="max-h-[120px] overflow-auto p-2"
187+
>
188+
<AttachmentList />
189+
</div>
190+
)}
191+
192+
{/* {currentSessionId && <SessionFile sessionId={currentSessionId} />} */}
193+
194+
<ScrollToBottom scrollRef={scrollRef} isAtBottom={isAtBottom} />
195+
</>
176196
)}
177-
178-
{/* {currentSessionId && <SessionFile sessionId={currentSessionId} />} */}
179-
180-
<ScrollToBottom scrollRef={scrollRef} isAtBottom={isAtBottom} />
181197
</div>
182198
);
183199
};

src/components/Common/UI/Footer.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useTranslation } from "react-i18next";
44
import clsx from "clsx";
55

66
import CommonIcon from "@/components/Common/Icons/CommonIcon";
7-
import Copyright from "@/components/Common/Copyright";
87
import logoImg from "@/assets/icon.svg";
98
import { useAppStore } from "@/stores/appStore";
109
import { useSearchStore } from "@/stores/searchStore";
@@ -17,6 +16,7 @@ import { useThemeStore } from "@/stores/themeStore";
1716
import platformAdapter from "@/utils/platformAdapter";
1817
import FontIcon from "../Icons/FontIcon";
1918
import TogglePin from "../TogglePin";
19+
import WebFooter from "./WebFooter";
2020

2121
interface FooterProps {
2222
setIsPinnedWeb?: (value: boolean) => void;
@@ -49,7 +49,7 @@ export default function Footer({ setIsPinnedWeb }: FooterProps) {
4949
return updateInfo && !skipVersions.includes(updateInfo.version);
5050
}, [updateInfo, skipVersions]);
5151

52-
const renderLeft = () => {
52+
const renderTauriLeft = () => {
5353
if (sourceData?.source?.name) {
5454
return (
5555
<div className="flex items-center gap-2">
@@ -116,12 +116,17 @@ export default function Footer({ setIsPinnedWeb }: FooterProps) {
116116
return (
117117
<div
118118
data-tauri-drag-region={isTauri}
119-
className="px-4 z-999 mx-[1px] h-8 absolute bottom-0 left-0 right-0 border-t border-gray-200 dark:border-gray-700 flex items-center justify-between rounded-md rounded-t-none overflow-hidden"
119+
className={clsx(
120+
"px-4 z-999 mx-[1px] h-8 absolute bottom-0 left-0 right-0 border-t border-gray-200 dark:border-gray-700 flex items-center justify-between rounded-md rounded-t-none",
121+
{
122+
"overflow-hidden": isTauri,
123+
}
124+
)}
120125
>
121126
{isTauri ? (
122127
<div className="flex items-center">
123128
<div className="flex items-center space-x-2">
124-
{renderLeft()}
129+
{renderTauriLeft()}
125130

126131
<TogglePin
127132
className={clsx({
@@ -132,7 +137,7 @@ export default function Footer({ setIsPinnedWeb }: FooterProps) {
132137
</div>
133138
</div>
134139
) : (
135-
<Copyright />
140+
<WebFooter />
136141
)}
137142

138143
<div className={`flex mobile:hidden items-center gap-3`}>

src/components/Common/UI/NoResults.tsx

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,78 @@ import { useShortcutsStore } from "@/stores/shortcutsStore";
55
import clsx from "clsx";
66
import { formatKey } from "@/utils/keyboardUtils";
77
import SearchEmpty from "../SearchEmpty";
8+
import FontIcon from "../Icons/FontIcon";
9+
import WebLoginButton from "./WebLoginButton";
10+
import WebRefreshButton from "./WebRefreshButton";
11+
import { useWebConfigStore } from "@/stores/webConfigStore";
12+
import { useAppStore } from "@/stores/appStore";
813

914
export const NoResults = () => {
1015
const { t } = useTranslation();
1116

1217
const modifierKey = useShortcutsStore((state) => state.modifierKey);
1318
const modeSwitch = useShortcutsStore((state) => state.modeSwitch);
1419

20+
const { isTauri } = useAppStore();
21+
const { disabled } = useWebConfigStore();
22+
23+
const renderContent = () => {
24+
if (!isTauri && disabled) {
25+
return (
26+
<div className="flex flex-col items-center gap-4 text-sm">
27+
<FontIcon
28+
name="font_coco-logo-line"
29+
className="size-20 text-[#999]"
30+
/>
31+
32+
<div className="text-center">
33+
<p>{t("webLogin.hints.welcome")}</p>
34+
<p>{t("webLogin.hints.pleaseLogin")}</p>
35+
</div>
36+
37+
<div className="flex gap-2">
38+
<WebLoginButton />
39+
40+
<WebRefreshButton className="size-8" />
41+
</div>
42+
</div>
43+
);
44+
}
45+
46+
return (
47+
<>
48+
<SearchEmpty />
49+
50+
<div
51+
className={`flex mobile:hidden mt-10 text-sm text-[#333] dark:text-[#D8D8D8]`}
52+
>
53+
{t("search.main.askCoco")}
54+
55+
<span
56+
className={clsx(
57+
"ml-3 h-5 min-w-5 rounded-md border border-[#D8D8D8] flex justify-center items-center",
58+
{
59+
"px-1": !isMac,
60+
}
61+
)}
62+
>
63+
{formatKey(modifierKey)}
64+
</span>
65+
66+
<span className="ml-1 w-5 h-5 rounded-[6px] border border-[#D8D8D8] flex justify-center items-center">
67+
{modeSwitch}
68+
</span>
69+
</div>
70+
</>
71+
);
72+
};
73+
1574
return (
1675
<div
1776
data-tauri-drag-region
1877
className="h-full w-full flex flex-col justify-center items-center"
1978
>
20-
<SearchEmpty />
21-
22-
<div
23-
className={`flex mobile:hidden mt-10 text-sm text-[#333] dark:text-[#D8D8D8]`}
24-
>
25-
{t("search.main.askCoco")}
26-
27-
<span
28-
className={clsx(
29-
"ml-3 h-5 min-w-5 rounded-md border border-[#D8D8D8] flex justify-center items-center",
30-
{
31-
"px-1": !isMac,
32-
}
33-
)}
34-
>
35-
{formatKey(modifierKey)}
36-
</span>
37-
38-
<span className="ml-1 w-5 h-5 rounded-[6px] border border-[#D8D8D8] flex justify-center items-center">
39-
{modeSwitch}
40-
</span>
41-
</div>
79+
{renderContent()}
4280
</div>
4381
);
4482
};

0 commit comments

Comments
 (0)