Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

โœจ feat: Add Settings Intercepting Routes #2346

Merged
merged 26 commits into from
May 4, 2024

Conversation

canisminor1990
Copy link
Member

@canisminor1990 canisminor1990 commented May 2, 2024

๐Ÿ’ป ๅ˜ๆ›ด็ฑปๅž‹ | Change Type

  • โœจ feat
  • ๐Ÿ› fix
  • โ™ป๏ธ refactor
  • ๐Ÿ’„ style
  • ๐Ÿ”จ chore
  • โšก๏ธ perf
  • ๐Ÿ“ docs

๐Ÿ”€ ๅ˜ๆ›ด่ฏดๆ˜Ž | Description of Change

่ฎพ็ฝฎๅผน็ช—ๆ‹ฆๆˆช่ทฏ็”ฑๆ”นๅŠจ่ฏดๆ˜Ž

NextJS ๆ–‡ๆกฃไป‹็ป๏ผšhttps://nextjs.org/docs/app/building-your-application/routing/intercepting-routes

็›ฎๆ ‡

  • ๆกŒ้ข็ซฏไฝฟ็”จ ๅผน็ช— ๅผ€ๅฏ่ฎพ็ฝฎ้ขๆฟๅ…จๅฑ€่ฎพ็ฝฎๅ’Œไผš่ฏ่ฎพ็ฝฎ (ๅ•้กต้ข๏ผ‰
  • ็งปๅŠจ็ซฏไฝฟ ้กต้ข ๅฑ•็คบ (ๅคš้กต้ข)
้€š็”จ่ฎพ็ฝฎ ่ง’่‰ฒ่ฎพ็ฝฎ
image image
image image

่ƒŒๆ™ฏ๏ผˆ็›ฎๅ‰้—็•™็š„็คพๅŒบ้—ฎ้ข˜๏ผ‰

image

ๆ‹ฆๆˆช่ทฏ็”ฑๆ— ๆณ•ๅ—ๆŽง๏ผŒไธ่ƒฝ่‡ช็”ฑๅฎšไน‰ไป€ไนˆๆƒ…ๅ†ตไธ‹ๅผ€ๅฏๆ‹ฆๆˆชไป€ไนˆๆƒ…ๅ†ตไธ‹ๅ…ณ้—ญๆ‹ฆๆˆช๏ผŒ็ช็ ด้™ๅˆถ็š„ๆ–นๅผๅชๆœ‰้€š่ฟ‡ redirect ็กฌๅˆทๆ–ฐ

https://www.reddit.com/r/nextjs/comments/174m3xf/how_to_stop_intercepting_routes_for_some_specific/

"use server";
import { redirect } from "next/navigation";

export default async function redirectHard(uri: string) {
  redirect(uri);
}

Warning

ไฝ†ๆต‹่ฏ•ๅŽๅ‘็Žฐๅœจ ios ่ฎพๅˆซไธŠๅ“ๅบ”ๅพˆๆ…ข๏ผŒๆœ‰ๆ—ถๅ€™็”š่‡ณๆ— ๆณ•ๅ“ๅบ”

่ฎพ่ฎกๆ€่ทฏ

ๅฝ“ๅ‰็š„่ฎพ่ฎกๆ€่ทฏๆ˜ฏ้€š่ฟ‡่ทฏ็”ฑ่ฟ›่กŒๅ—ๆŽง๏ผŒไพ‹ๅฆ‚ๆƒณๅฎž็Žฐ /settings ๅ—ๆŽง

  • ไฝฟ็”จๅผน็ช—ๆ‹ฆๆˆช๏ผš/settings/modal?tab=common
  • ไธๆ˜ฏ็”จๅผน็ช—ๆ‹ฆๆˆช๏ผš/settings/common

ไผš่ฏ่ฎพ็ฝฎๅŒ็†

  • ไฝฟ็”จๅผน็ช—ๆ‹ฆๆˆช๏ผš/chat/settings/modal
  • ไธๆ˜ฏ็”จๅผน็ช—ๆ‹ฆๆˆช๏ผš/chat/settings

ๆ–‡ไปถ็ป“ๆž„็คบๆ„

โ””โ”€โ”€ app
    โ”œโ”€โ”€ @modal
    โ”‚   โ””โ”€โ”€ (.)settings
    โ”‚       โ””โ”€โ”€ modal
    โ”‚           โ””โ”€โ”€ page.tsx  # ๅผน็ช—ๅ†…ๅฎน
    โ””โ”€โ”€ (main)
        โ””โ”€โ”€ settings
            โ””โ”€โ”€ modal
                โ””โ”€โ”€ page.tsx  # ๆ‹ฆๆˆชไธญๅฆ‚ๆžœ็กฌๅˆทๆ–ฐ๏ผŒFallback ๅˆฐ้žๆ‹ฆๆˆช่ทฏ็”ฑ

Fallback ่ทฏ็”ฑ็คบๆ„: app/(main)/settings/modal/page.tsx

'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
 */

const SettingsModalFallback = () => {
  const { tab = SettingsTabs.Common } = useQuery();
  const router = useQueryRoute();

  useLayoutEffect(() => {
    router.replace(urlJoin('/settings', tab as string), { query: { tab: '' } });
  }, []);

  return null;
};

export default SettingsModalFallback;

ๅทฅๅ…ท hook

็”ฑไบŽๆ‹ฆๆˆชๅˆคๆ–ญๆกไปถๆฏ”่พƒๅคๆ‚๏ผŒๅŒ…่ฃ…ไธบไธคไธช hook ๆ–นๆณ•ๆ–นไพฟไฝฟ็”จ

ๆ‰“ๅผ€่ฎพ็ฝฎ้ขๆฟ๏ผšuseOpenSettings

import { useOpenSettings } from '@/hooks/useInterceptingRoutes';

export const useOpenSettings = (tab: SettingsTabs = SettingsTabs.Common) => {
  const router = useQueryRoute();
  const mobile = useIsMobile();

  return useMemo(() => {
    if (mobile) {
      return () => router.push(urlJoin('/settings', tab));
    } else {
      // use Intercepting Routes on Desktop
      return () => router.push('/settings/modal', { query: { tab } });
    }
  }, [mobile, tab]);
};

ๆ‰“ๅผ€่ง’่‰ฒ่ฎพ็ฝฎ้ขๆฟ๏ผšuseOpenChatSettings

import { useOpenChatSettings} from '@/hooks/useInterceptingRoutes';

export const useOpenChatSettings = (
  isInbox?: boolean,
  tab: ChatSettingsTabs = ChatSettingsTabs.Meta,
) => {
  const globalSettings = useOpenSettings(SettingsTabs.Agent);
  const router = useQueryRoute();
  const mobile = useIsMobile();

  return useMemo(() => {
    if (isInbox) {
      useGlobalStore.setState({
        sidebarKey: SidebarTabKey.Setting,
      });
      return globalSettings;
    }
    if (mobile) {
      return () => router.push('/chat/settings');
    } else {
      // use Intercepting Routes on Desktop
      return () => router.push('/chat/settings/modal', { query: { tab } });
    }
  }, [globalSettings, mobile, isInbox, tab]);
};

Copy link

vercel bot commented May 2, 2024

The latest updates on your projects. Learn more about Vercel for Git โ†—๏ธŽ

Name Status Preview Comments Updated (UTC)
lobe-chat-community โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback May 4, 2024 6:09am

@lobehubbot
Copy link
Member

๐Ÿ‘ @canisminor1990

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
้žๅธธๆ„Ÿ่ฐขๆ‚จๆๅ‡บๆ‹‰ๅ–่ฏทๆฑ‚ๅนถไธบๆˆ‘ไปฌ็š„็คพๅŒบๅšๅ‡บ่ดก็Œฎ๏ผŒ่ฏท็กฎไฟๆ‚จๅทฒ็ป้ตๅพชไบ†ๆˆ‘ไปฌ็š„่ดก็ŒฎๆŒ‡ๅ—๏ผŒๆˆ‘ไปฌไผšๅฐฝๅฟซๅฎกๆŸฅๅฎƒใ€‚
ๅฆ‚ๆžœๆ‚จ้‡ๅˆฐไปปไฝ•้—ฎ้ข˜๏ผŒ่ฏท้šๆ—ถไธŽๆˆ‘ไปฌ่”็ณปใ€‚

Copy link

codecov bot commented May 2, 2024

Codecov Report

All modified and coverable lines are covered by tests โœ…

Project coverage is 92.89%. Comparing base (27095f5) to head (5eb3ffd).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2346      +/-   ##
==========================================
+ Coverage   92.87%   92.89%   +0.02%     
==========================================
  Files         296      297       +1     
  Lines       16872    16928      +56     
  Branches     1948     1218     -730     
==========================================
+ Hits        15670    15726      +56     
  Misses       1202     1202              

โ˜” View full report in Codecov by Sentry.
๐Ÿ“ข Have feedback on the report? Share it here.

Copy link
Contributor

@arvinxx arvinxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

็œ‹ๅฎŒไบ†๏ผŒๆˆ‘ๅ†ๆต‹ไธ‹ๅŠŸ่ƒฝ

src/app/(main)/chat/settings/modal/page.tsx Show resolved Hide resolved
src/app/(main)/settings/modal/page.tsx Show resolved Hide resolved
src/app/@modal/(.)settings/modal/index.tsx Outdated Show resolved Hide resolved
src/app/@modal/(.)settings/modal/layout.tsx Outdated Show resolved Hide resolved
src/app/@modal/_layout/SettingModalLayout.tsx Show resolved Hide resolved
src/app/@modal/chat/(.)settings/modal/page.tsx Outdated Show resolved Hide resolved
src/hooks/useInterceptingRoutes.ts Outdated Show resolved Hide resolved
@arvinxx
Copy link
Contributor

arvinxx commented May 2, 2024

ๅค็Žฐๆ–นๅผ๏ผšๅผ€ไธ€ไธช่‡ชๅฎšไน‰ๅŠฉๆ‰‹๏ผŒ็„ถๅŽๆ‰“ๅผ€่ฎพ็ฝฎ

bug.mp4

@arvinxx
Copy link
Contributor

arvinxx commented May 2, 2024

้œ€่ฆๅŠ ้—ด่ท

image

@arvinxx
Copy link
Contributor

arvinxx commented May 2, 2024

ๆˆชๅ›พๅŽๅฐฑ่‡ชๅŠจๅ…ณ้—ญไบ†๏ผˆๆŒ‰ไบ†ๅ›ž่ฝฆ้”ฎ๏ผ‰๏ผš

default.mp4

Base automatically changed from refactor/setting-layout to main May 2, 2024 15:09
@canisminor1990
Copy link
Member Author

canisminor1990 commented May 2, 2024

ๆˆชๅ›พๅŽๅฐฑ่‡ชๅŠจๅ…ณ้—ญไบ†๏ผˆๆŒ‰ไบ†ๅ›ž่ฝฆ้”ฎ๏ผ‰๏ผš

่ฟ™ๆ˜ฏไธช antd ็š„ triggle ๅง๏ผŸ

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. ๐Ÿ‘ฏ๐Ÿ‘ญ๐Ÿป๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘๐Ÿ‘ซ๐Ÿง‘๐Ÿฟโ€๐Ÿคโ€๐Ÿง‘๐Ÿป๐Ÿ‘ฉ๐Ÿพโ€๐Ÿคโ€๐Ÿ‘จ๐Ÿฟ๐Ÿ‘ฌ๐Ÿฟ


It closes automatically after taking the screenshot (press the Enter key):
Is this an antd triggle?

src/app/(main)/settings/modal/page.tsx Outdated Show resolved Hide resolved
@canisminor1990
Copy link
Member Author

image

@canisminor1990 canisminor1990 merged commit 29b6442 into main May 4, 2024
9 of 10 checks passed
@canisminor1990 canisminor1990 deleted the feat/intercepting-settings-routes branch May 4, 2024 06:09
@lobehubbot
Copy link
Member

โค๏ธ Great PR @canisminor1990 โค๏ธ

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.
้กน็›ฎ็š„ๆˆ้•ฟ็ฆปไธๅผ€็”จๆˆทๅ้ฆˆๅ’Œ่ดก็Œฎ๏ผŒๆ„Ÿ่ฐขๆ‚จ็š„่ดก็Œฎ! ๅฆ‚ๆžœๆ‚จๅฏน LobeHub ๅผ€ๅ‘่€…็คพๅŒบๆ„Ÿๅ…ด่ถฃ๏ผŒ่ฏทๅŠ ๅ…ฅๆˆ‘ไปฌ็š„ discord๏ผŒ็„ถๅŽ็งไฟก @arvinxx ๆˆ– @canisminor1990ใ€‚ไป–ไปฌไผš้‚€่ฏทๆ‚จๅŠ ๅ…ฅๆˆ‘ไปฌ็š„็งๅฏ†ๅผ€ๅ‘่€…้ข‘้“ใ€‚ๆˆ‘ไปฌๅฐ†ไผš่ฎจ่ฎบๅ…ณไบŽ Lobe Chat ็š„ๅผ€ๅ‘๏ผŒๅˆ†ไบซๅ’Œ่ฎจ่ฎบๅ…จ็ƒ่Œƒๅ›ดๅ†…็š„ AI ๆถˆๆฏใ€‚

github-actions bot pushed a commit that referenced this pull request May 4, 2024
## [Version 0.153.0](v0.152.12...v0.153.0)
<sup>Released on **2024-05-04**</sup>

#### โœจ Features

- **misc**: Add Settings Intercepting Routes.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Add Settings Intercepting Routes, closes [#2346](#2346) ([29b6442](29b6442))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Member

๐ŸŽ‰ This PR is included in version 0.153.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

github-actions bot pushed a commit to bentwnghk/lobe-chat that referenced this pull request May 4, 2024
## [Version&nbsp;1.33.0](v1.32.2...v1.33.0)
<sup>Released on **2024-05-04**</sup>

#### โœจ Features

- **misc**: Add Settings Intercepting Routes.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Add Settings Intercepting Routes, closes [lobehub#2346](https://github.com/bentwnghk/lobe-chat/issues/2346) ([29b6442](29b6442))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
TheNameIsNigel pushed a commit to TheNameIsNigel/lobe-chat that referenced this pull request May 15, 2024
* โ™ป๏ธ 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>
TheNameIsNigel pushed a commit to TheNameIsNigel/lobe-chat that referenced this pull request May 15, 2024
## [Version&nbsp;0.153.0](lobehub/lobe-chat@v0.152.12...v0.153.0)
<sup>Released on **2024-05-04**</sup>

#### โœจ Features

- **misc**: Add Settings Intercepting Routes.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Add Settings Intercepting Routes, closes [lobehub#2346](lobehub#2346) ([29b6442](lobehub@29b6442))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
ipoly pushed a commit to ipoly/lobe-chat that referenced this pull request Jul 29, 2024
* โ™ป๏ธ 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>
ipoly pushed a commit to ipoly/lobe-chat that referenced this pull request Jul 29, 2024
## [Version&nbsp;0.153.0](lobehub/lobe-chat@v0.152.12...v0.153.0)
<sup>Released on **2024-05-04**</sup>

#### โœจ Features

- **misc**: Add Settings Intercepting Routes.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Add Settings Intercepting Routes, closes [lobehub#2346](lobehub#2346) ([29b6442](lobehub@29b6442))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants