mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	feat: add SD page switching
This commit is contained in:
		@@ -1,5 +1,7 @@
 | 
				
			|||||||
"use client";
 | 
					"use client";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { Sd } from "@/app/components/sd";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require("../polyfill");
 | 
					require("../polyfill");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { useState, useEffect } from "react";
 | 
					import { useState, useEffect } from "react";
 | 
				
			||||||
@@ -159,6 +161,7 @@ function Screen() {
 | 
				
			|||||||
              <Route path={Path.NewChat} element={<NewChat />} />
 | 
					              <Route path={Path.NewChat} element={<NewChat />} />
 | 
				
			||||||
              <Route path={Path.Masks} element={<MaskPage />} />
 | 
					              <Route path={Path.Masks} element={<MaskPage />} />
 | 
				
			||||||
              <Route path={Path.Chat} element={<Chat />} />
 | 
					              <Route path={Path.Chat} element={<Chat />} />
 | 
				
			||||||
 | 
					              <Route path={Path.Sd} element={<Sd />} />
 | 
				
			||||||
              <Route path={Path.Settings} element={<Settings />} />
 | 
					              <Route path={Path.Settings} element={<Settings />} />
 | 
				
			||||||
            </Routes>
 | 
					            </Routes>
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										0
									
								
								app/components/sd-list.module.scss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								app/components/sd-list.module.scss
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										3
									
								
								app/components/sd-list.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								app/components/sd-list.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					export function SdList() {
 | 
				
			||||||
 | 
					  return <div>sd-list</div>;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										0
									
								
								app/components/sd.module.scss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								app/components/sd.module.scss
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										3
									
								
								app/components/sd.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								app/components/sd.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					export function Sd() {
 | 
				
			||||||
 | 
					  return <div>sd</div>;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -23,18 +23,24 @@ import {
 | 
				
			|||||||
  MIN_SIDEBAR_WIDTH,
 | 
					  MIN_SIDEBAR_WIDTH,
 | 
				
			||||||
  NARROW_SIDEBAR_WIDTH,
 | 
					  NARROW_SIDEBAR_WIDTH,
 | 
				
			||||||
  Path,
 | 
					  Path,
 | 
				
			||||||
 | 
					  PLUGINS,
 | 
				
			||||||
  REPO_URL,
 | 
					  REPO_URL,
 | 
				
			||||||
} from "../constant";
 | 
					} from "../constant";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Link, useNavigate } from "react-router-dom";
 | 
					import { Link, useLocation, useNavigate } from "react-router-dom";
 | 
				
			||||||
import { isIOS, useMobileScreen } from "../utils";
 | 
					import { isIOS, useMobileScreen } from "../utils";
 | 
				
			||||||
import dynamic from "next/dynamic";
 | 
					import dynamic from "next/dynamic";
 | 
				
			||||||
import { Selector, showConfirm, showToast } from "./ui-lib";
 | 
					import { Selector, showConfirm, showToast } from "./ui-lib";
 | 
				
			||||||
 | 
					import de from "@/app/locales/de";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, {
 | 
					const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, {
 | 
				
			||||||
  loading: () => null,
 | 
					  loading: () => null,
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const SdList = dynamic(async () => (await import("./sd-list")).SdList, {
 | 
				
			||||||
 | 
					  loading: () => null,
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function useHotKey() {
 | 
					function useHotKey() {
 | 
				
			||||||
  const chatStore = useChatStore();
 | 
					  const chatStore = useChatStore();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -141,9 +147,20 @@ export function SideBar(props: { className?: string }) {
 | 
				
			|||||||
    [isMobileScreen],
 | 
					    [isMobileScreen],
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
  const [showPluginSelector, setShowPluginSelector] = useState(false);
 | 
					  const [showPluginSelector, setShowPluginSelector] = useState(false);
 | 
				
			||||||
 | 
					  const location = useLocation();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  useHotKey();
 | 
					  useHotKey();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let bodyComponent: React.JSX.Element;
 | 
				
			||||||
 | 
					  let isChat: boolean;
 | 
				
			||||||
 | 
					  switch (location.pathname) {
 | 
				
			||||||
 | 
					    case Path.Sd:
 | 
				
			||||||
 | 
					      bodyComponent = <SdList />;
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    default:
 | 
				
			||||||
 | 
					      isChat = true;
 | 
				
			||||||
 | 
					      bodyComponent = <ChatList narrow={shouldNarrow} />;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div
 | 
					    <div
 | 
				
			||||||
      className={`${styles.sidebar} ${props.className} ${
 | 
					      className={`${styles.sidebar} ${props.className} ${
 | 
				
			||||||
@@ -192,12 +209,12 @@ export function SideBar(props: { className?: string }) {
 | 
				
			|||||||
      <div
 | 
					      <div
 | 
				
			||||||
        className={styles["sidebar-body"]}
 | 
					        className={styles["sidebar-body"]}
 | 
				
			||||||
        onClick={(e) => {
 | 
					        onClick={(e) => {
 | 
				
			||||||
          if (e.target === e.currentTarget) {
 | 
					          if (isChat && e.target === e.currentTarget) {
 | 
				
			||||||
            navigate(Path.Home);
 | 
					            navigate(Path.Home);
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }}
 | 
					        }}
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
        <ChatList narrow={shouldNarrow} />
 | 
					        {bodyComponent}
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      <div className={styles["sidebar-tail"]}>
 | 
					      <div className={styles["sidebar-tail"]}>
 | 
				
			||||||
@@ -254,11 +271,16 @@ export function SideBar(props: { className?: string }) {
 | 
				
			|||||||
              value: "-",
 | 
					              value: "-",
 | 
				
			||||||
              disable: true,
 | 
					              disable: true,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            { title: "Stable Diffusion", value: "sd" },
 | 
					            ...PLUGINS.map((item) => {
 | 
				
			||||||
 | 
					              return {
 | 
				
			||||||
 | 
					                title: item.name,
 | 
				
			||||||
 | 
					                value: item.path,
 | 
				
			||||||
 | 
					              };
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
          ]}
 | 
					          ]}
 | 
				
			||||||
          onClose={() => setShowPluginSelector(false)}
 | 
					          onClose={() => setShowPluginSelector(false)}
 | 
				
			||||||
          onSelection={(s) => {
 | 
					          onSelection={(s) => {
 | 
				
			||||||
            console.log("go to page: ", s);
 | 
					            navigate(s[0], { state: { fromHome: true } });
 | 
				
			||||||
          }}
 | 
					          }}
 | 
				
			||||||
        />
 | 
					        />
 | 
				
			||||||
      )}
 | 
					      )}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,7 @@ export enum Path {
 | 
				
			|||||||
  NewChat = "/new-chat",
 | 
					  NewChat = "/new-chat",
 | 
				
			||||||
  Masks = "/masks",
 | 
					  Masks = "/masks",
 | 
				
			||||||
  Auth = "/auth",
 | 
					  Auth = "/auth",
 | 
				
			||||||
 | 
					  Sd = "/sd",
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export enum ApiPath {
 | 
					export enum ApiPath {
 | 
				
			||||||
@@ -213,3 +214,5 @@ export const internalAllowedWebDavEndpoints = [
 | 
				
			|||||||
  "https://webdav.yandex.com",
 | 
					  "https://webdav.yandex.com",
 | 
				
			||||||
  "https://app.koofr.net/dav/Koofr",
 | 
					  "https://app.koofr.net/dav/Koofr",
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const PLUGINS = [{ name: "Stable Diffusion", path: Path.Sd }];
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user