Skip to content

Commit

Permalink
use getExtensionRouteQuery for query
Browse files Browse the repository at this point in the history
  • Loading branch information
ddadaal committed Aug 10, 2024
1 parent ac6bd58 commit f4c2d49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions libs/web/src/extensions/ExtensionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -79,17 +80,12 @@ export const ExtensionPage: React.FC<Props> = ({

const darkMode = useDarkMode();

const query = new URLSearchParams(
Object.fromEntries(Object.entries(rest).filter(([_, val]) => typeof val === "string")) as Record<string, string>,
);

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();
Expand Down
2 changes: 1 addition & 1 deletion libs/web/src/extensions/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit f4c2d49

Please sign in to comment.