mirror of
https://github.com/ChatGPTNextWeb/NextChat.git
synced 2026-03-03 00:25:02 +08:00
refactor: init switching to nextjs router
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useEffect } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
// import { useSearchParams } from "react-router-dom";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import Locale from "./locales";
|
||||
|
||||
type Command = (param: string) => void;
|
||||
@@ -14,22 +15,23 @@ interface Commands {
|
||||
export function useCommand(commands: Commands = {}) {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
|
||||
useEffect(() => {
|
||||
let shouldUpdate = false;
|
||||
searchParams.forEach((param, name) => {
|
||||
const commandName = name as keyof Commands;
|
||||
if (typeof commands[commandName] === "function") {
|
||||
commands[commandName]!(param);
|
||||
searchParams.delete(name);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
});
|
||||
// fixme: update commands
|
||||
// useEffect(() => {
|
||||
// let shouldUpdate = false;
|
||||
// searchParams.forEach((param, name) => {
|
||||
// const commandName = name as keyof Commands;
|
||||
// if (typeof commands[commandName] === "function") {
|
||||
// commands[commandName]!(param);
|
||||
// searchParams.delete(name);
|
||||
// shouldUpdate = true;
|
||||
// }
|
||||
// });
|
||||
|
||||
if (shouldUpdate) {
|
||||
setSearchParams(searchParams);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [searchParams, commands]);
|
||||
// if (shouldUpdate) {
|
||||
// setSearchParams(searchParams);
|
||||
// }
|
||||
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
// }, [searchParams, commands]);
|
||||
}
|
||||
|
||||
interface ChatCommands {
|
||||
|
||||
Reference in New Issue
Block a user