Skip to content

Commit d530d61

Browse files
authored
🐛 Page display logic fix in speed mode and page jump logic fix in full mode
2 parents cf4a232 + 6a75b9b commit d530d61

File tree

8 files changed

+46
-23
lines changed

8 files changed

+46
-23
lines changed

frontend/app/[locale]/chat/components/chatHeader.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export function ChatHeader({ title, onRename }: ChatHeaderProps) {
5050
const inputRef = useRef<HTMLInputElement>(null);
5151
const { t } = useTranslation("common");
5252
const { currentLanguage, handleLanguageChange } = useLanguageSwitch();
53-
const { user } = useAuth();
54-
const isAdmin = user?.role === USER_ROLES.ADMIN;
53+
const { user, isSpeedMode } = useAuth();
54+
const isAdmin = isSpeedMode || user?.role === USER_ROLES.ADMIN;
5555

5656
const goToModelSetup = () => {
5757
router.push(`/${currentLanguage}/setup/models`);

frontend/app/[locale]/chat/internal/chatInterface.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const getI18nKeyByType = (type: string): string => {
6161

6262
export function ChatInterface() {
6363
const router = useRouter();
64-
const { user } = useAuth(); // Get user information
64+
const { user, isSpeedMode } = useAuth(); // Get user information
6565
const [input, setInput] = useState("");
6666
// Replace the original messages state
6767
const [sessionMessages, setSessionMessages] = useState<{
@@ -1578,8 +1578,8 @@ export function ChatInterface() {
15781578
// Both admin and regular users now use dropdown menus
15791579
};
15801580

1581-
// Settings menu items based on user role
1582-
const settingsMenuItems = user?.role === "admin" ? [
1581+
// Settings menu items based on user role (speed mode is treated as admin)
1582+
const settingsMenuItems = (isSpeedMode || user?.role === "admin") ? [
15831583
// Admin has three options
15841584
{
15851585
key: "models",

frontend/app/[locale]/chat/internal/memory/memoryManageModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ const MemoryManageModal: React.FC<MemoryManageModalProps> = ({
4545
userRole,
4646
}) => {
4747
// Get user role from authentication context
48-
const { user } = useAuth();
48+
const { user, isSpeedMode } = useAuth();
4949
const { message } = App.useApp();
5050
const role: (typeof USER_ROLES)[keyof typeof USER_ROLES] = (userRole ??
51-
(user?.role === USER_ROLES.ADMIN ? USER_ROLES.ADMIN : USER_ROLES.USER)) as (typeof USER_ROLES)[keyof typeof USER_ROLES];
51+
(isSpeedMode || user?.role === USER_ROLES.ADMIN ? USER_ROLES.ADMIN : USER_ROLES.USER)) as (typeof USER_ROLES)[keyof typeof USER_ROLES];
5252

5353
// Get user role from other hooks / context
5454
const currentUserId = "user1";

frontend/app/[locale]/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default function Home() {
7777

7878
// Handle operations that require login
7979
const handleAuthRequired = (e: React.MouseEvent) => {
80-
if (!user) {
80+
if (!isSpeedMode && !user) {
8181
e.preventDefault();
8282
setLoginPromptOpen(true);
8383
}
@@ -102,7 +102,7 @@ export default function Home() {
102102

103103
// Handle operations that require admin privileges
104104
const handleAdminRequired = (e: React.MouseEvent) => {
105-
if (user?.role !== "admin") {
105+
if (!isSpeedMode && user?.role !== "admin") {
106106
e.preventDefault();
107107
setAdminRequiredPromptOpen(true);
108108
}
@@ -244,15 +244,15 @@ export default function Home() {
244244
transition={{ duration: 0.8, delay: 0.4 }}
245245
className="flex flex-col sm:flex-row gap-4"
246246
>
247-
<Link href={user ? "/chat" : "#"} onClick={handleAuthRequired}>
247+
<Link href={isSpeedMode || user ? "/chat" : "#"} onClick={handleAuthRequired}>
248248
<Button className="bg-blue-600 hover:bg-blue-700 text-white px-8 py-6 rounded-full text-lg font-medium shadow-lg hover:shadow-xl transition-all duration-300 group">
249249
<Bot className="mr-2 h-5 w-5 group-hover:animate-pulse" />
250250
{t("page.startChat")}
251251
</Button>
252252
</Link>
253253

254254
<Link
255-
href={user?.role === "admin" ? "/setup" : "#"}
255+
href={isSpeedMode || user?.role === "admin" ? "/setup" : "#"}
256256
onClick={handleAdminRequired}
257257
>
258258
<Button className="bg-blue-600 hover:bg-blue-700 text-white px-8 py-6 rounded-full text-lg font-medium shadow-lg hover:shadow-xl transition-all duration-300 group">

frontend/app/[locale]/setup/agents/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ export default function AgentSetupPage() {
108108
duration: 0.4,
109109
};
110110

111+
// Prevent rendering if user doesn't have permission (full mode)
112+
if (!isSpeedMode && !userLoading && (!user || user.role !== USER_ROLES.ADMIN)) {
113+
return null;
114+
}
115+
111116
return (
112117
<SetupLayout
113118
connectionStatus={connectionStatus}

frontend/app/[locale]/setup/knowledges/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default function KnowledgeSetupPage() {
123123

124124
// Handle back button click
125125
const handleBack = () => {
126-
if (user?.role === USER_ROLES.ADMIN) {
126+
if (isSpeedMode || user?.role === USER_ROLES.ADMIN) {
127127
router.push("/setup/models");
128128
} else {
129129
message.error(t("setup.page.error.adminOnly"));
@@ -152,8 +152,8 @@ export default function KnowledgeSetupPage() {
152152
duration: 0.4,
153153
};
154154

155-
// Determine which button to show based on user role
156-
const isAdmin = user?.role === USER_ROLES.ADMIN;
155+
// Determine which button to show based on user role (speed mode is treated as admin)
156+
const isAdmin = isSpeedMode || user?.role === USER_ROLES.ADMIN;
157157

158158
return (
159159
<SetupLayout

frontend/app/[locale]/setup/models/page.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import modelEngineService from "@/services/modelEngineService";
1212
import {configStore} from "@/lib/config";
1313
import { configService } from "@/services/configService";
1414
import {
15+
USER_ROLES,
1516
CONNECTION_STATUS,
1617
ConnectionStatus,
1718
MODEL_STATUS,
@@ -51,7 +52,13 @@ export default function ModelSetupPage() {
5152
openLoginModal();
5253
return;
5354
}
54-
}, [isSpeedMode, user, userLoading, openLoginModal]);
55+
56+
// Only admin users can access this page (full mode)
57+
if (!isSpeedMode && user && user.role !== USER_ROLES.ADMIN) {
58+
router.push("/setup/knowledges");
59+
return;
60+
}
61+
}, [isSpeedMode, user, userLoading, openLoginModal, router]);
5562

5663
// Check the connection status when the page is initialized
5764
useEffect(() => {
@@ -206,6 +213,11 @@ export default function ModelSetupPage() {
206213
duration: 0.4,
207214
};
208215

216+
// Prevent rendering if user doesn't have permission (full mode)
217+
if (!isSpeedMode && !userLoading && (!user || user.role !== USER_ROLES.ADMIN)) {
218+
return null;
219+
}
220+
209221
return (
210222
<SetupLayout
211223
connectionStatus={connectionStatus}

frontend/app/[locale]/setup/page.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@ import {USER_ROLES} from "@/const/modelConfig";
77

88
export default function SetupPage() {
99
const router = useRouter();
10-
const { user, isLoading: userLoading } = useAuth();
10+
const { user, isLoading: userLoading, isSpeedMode } = useAuth();
1111

1212
useEffect(() => {
13-
if (!userLoading && user) {
14-
// Redirect based on user role
15-
if (user.role === USER_ROLES.ADMIN) {
13+
if (!userLoading) {
14+
if (isSpeedMode) {
15+
// In speed mode, go directly to models page
1616
router.push("/setup/models");
17+
} else if (user) {
18+
// Redirect based on user role
19+
if (user.role === USER_ROLES.ADMIN) {
20+
router.push("/setup/models");
21+
} else {
22+
router.push("/setup/knowledges");
23+
}
1724
} else {
18-
router.push("/setup/knowledges");
25+
// Full mode without login, redirect to home
26+
router.push("/");
1927
}
20-
} else if (!userLoading && !user) {
21-
router.push("/");
2228
}
23-
}, [user, userLoading, router]);
29+
}, [user, userLoading, isSpeedMode, router]);
2430
return null;
2531
}

0 commit comments

Comments
 (0)