From f4c2d4965b070b10802058815b41d8e83ed67bd7 Mon Sep 17 00:00:00 2001 From: Chen Junda Date: Sat, 10 Aug 2024 15:16:59 +0800 Subject: [PATCH] use getExtensionRouteQuery for query --- libs/web/src/extensions/ExtensionPage.tsx | 16 ++++++---------- libs/web/src/extensions/common.ts | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/libs/web/src/extensions/ExtensionPage.tsx b/libs/web/src/extensions/ExtensionPage.tsx index c581417cbf..96e835ac2a 100644 --- a/libs/web/src/extensions/ExtensionPage.tsx +++ b/libs/web/src/extensions/ExtensionPage.tsx @@ -14,6 +14,7 @@ import { joinWithUrl } from "@scow/utils"; import { useRouter } from "next/router"; import React, { useEffect, useRef } from "react"; import { Head } from "src/components/head"; +import { getExtensionRouteQuery } from "src/extensions/common"; import { extensionEvents } from "src/extensions/events"; import { ExtensionManifestWithUrl, UiExtensionStoreData } from "src/extensions/UiExtensionStore"; import { UserInfo } from "src/layouts/base/types"; @@ -79,17 +80,12 @@ export const ExtensionPage: React.FC = ({ const darkMode = useDarkMode(); - const query = new URLSearchParams( - Object.fromEntries(Object.entries(rest).filter(([_, val]) => typeof val === "string")) as Record, - ); - - if (user) { - query.set("scowUserToken", user.token); - } - - query.set("scowDark", darkMode.dark ? "true" : "false"); + const extensionQuery = getExtensionRouteQuery(darkMode.dark, currentLanguageId, user?.token); - query.set("scowLangId", currentLanguageId); + const query = new URLSearchParams({ + ...Object.fromEntries(Object.entries(rest).filter(([_, val]) => typeof val === "string")), + ...extensionQuery, + }); const url = joinWithUrl(config.url, "extensions", ...pathParts) + "?" + query.toString(); diff --git a/libs/web/src/extensions/common.ts b/libs/web/src/extensions/common.ts index f5d19843a1..74310f1bc9 100644 --- a/libs/web/src/extensions/common.ts +++ b/libs/web/src/extensions/common.ts @@ -32,5 +32,5 @@ export function isUrl(input: string): boolean { export const getExtensionRouteQuery = (dark: boolean, languageId: string, userToken?: string) => ({ scowDark: dark ? "true" : "false", scowLangId: languageId, - scowUserToken: userToken, + ...userToken ? { scowUserToken: userToken } : {}, }) as ExtensionRouteQuery;