forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: Add Settings Intercepting Routes (lobehub#2346)
* ♻️ refactor: Refactor Setting Layout * ♻️ refactor: Update useQueryRoute and add test * ✅ test: Update test * ✨ feat: Add Settings Intercepting Routes * ♻️ refactor: Refactor Setting Layout * ♻️ refactor: Update useQueryRoute and add test * ✅ test: Update test * 🐛 fix: Fix i18n * 💄 style: Fix style * 🐛 fix: Fix review problem * 🐛 fix: Fix review problem * ✅ test: Add useInterceptingRoutes.test * 🐛 fix: Fix config * 🐛 fix: Fix some merge problem * 🐛 fix: Fix modal layout * 🐛 fix: Fix cubox * 🐛 fix: Fix cubox * ✅ test: Fix test * 🐛 fix: Fix redirect * 🐛 fix: Fix review problem --------- Co-authored-by: Arvin Xu <arvinx@foxmail.com>
- Loading branch information
1 parent
12e103f
commit 1274fe6
Showing
53 changed files
with
683 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use client'; | ||
|
||
import { useLayoutEffect } from 'react'; | ||
|
||
import { useQueryRoute } from '@/hooks/useQueryRoute'; | ||
|
||
/** | ||
* @description: Chat Settings Modal (intercepting routes fallback when hard refresh) | ||
* @example: /chat/settings/modal?tab=prompt => /chat/settings | ||
* @refs: https://github.com/lobehub/lobe-chat/discussions/2295#discussioncomment-9290942 | ||
*/ | ||
|
||
const ChatSettingsModalFallback = () => { | ||
const router = useQueryRoute(); | ||
|
||
useLayoutEffect(() => { | ||
router.replace('/chat/settings', { query: { tab: '' } }); | ||
}, []); | ||
|
||
return null; | ||
}; | ||
|
||
export default ChatSettingsModalFallback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use client'; | ||
|
||
import { useLayoutEffect } from 'react'; | ||
import urlJoin from 'url-join'; | ||
|
||
import { useQuery } from '@/hooks/useQuery'; | ||
import { useQueryRoute } from '@/hooks/useQueryRoute'; | ||
import { SettingsTabs } from '@/store/global/initialState'; | ||
|
||
/** | ||
* @description: Settings Modal (intercepting routes fallback when hard refresh) | ||
* @example: /settings/modal?tab=common => /settings/common | ||
* @refs: https://github.com/lobehub/lobe-chat/discussions/2295#discussioncomment-9290942 | ||
*/ | ||
|
||
const SettingsModalFallback = () => { | ||
const { tab = SettingsTabs.Common } = useQuery(); | ||
const router = useQueryRoute(); | ||
|
||
useLayoutEffect(() => { | ||
router.replace(urlJoin('/settings', tab as SettingsTabs), { query: { tab: '' } }); | ||
}, []); | ||
|
||
return null; | ||
}; | ||
|
||
export default SettingsModalFallback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use client'; | ||
|
||
import dynamic from 'next/dynamic'; | ||
import { memo } from 'react'; | ||
|
||
import { useQuery } from '@/hooks/useQuery'; | ||
import { SettingsTabs } from '@/store/global/initialState'; | ||
|
||
import Skeleton from './loading'; | ||
|
||
const loading = () => <Skeleton />; | ||
|
||
const Common = dynamic(() => import('@/app/(main)/settings/common'), { loading, ssr: false }); | ||
const About = dynamic(() => import('@/app/(main)/settings/about'), { loading, ssr: false }); | ||
const LLM = dynamic(() => import('@/app/(main)/settings/llm'), { loading, ssr: false }); | ||
const TTS = dynamic(() => import('@/app/(main)/settings/tts'), { loading, ssr: false }); | ||
const Agent = dynamic(() => import('@/app/(main)/settings/agent'), { loading, ssr: false }); | ||
const Sync = dynamic(() => import('@/app/(main)/settings/sync'), { loading, ssr: false }); | ||
|
||
interface SettingsModalProps { | ||
browser?: string; | ||
mobile?: boolean; | ||
os?: string; | ||
} | ||
|
||
const SettingsModal = memo<SettingsModalProps>(({ browser, os, mobile }) => { | ||
const { tab = SettingsTabs.Common } = useQuery(); | ||
return ( | ||
<> | ||
{tab === SettingsTabs.Common && <Common />} | ||
{tab === SettingsTabs.Sync && <Sync browser={browser} mobile={mobile} os={os} />} | ||
{tab === SettingsTabs.LLM && <LLM />} | ||
{tab === SettingsTabs.TTS && <TTS />} | ||
{tab === SettingsTabs.Agent && <Agent />} | ||
{tab === SettingsTabs.About && <About mobile={mobile} />} | ||
</> | ||
); | ||
}); | ||
|
||
export default SettingsModal; |
Oops, something went wrong.