fix: keep query params state when navigating to different conversation

This commit is contained in:
abdou6666 2025-04-04 11:01:57 +01:00
parent 3da57c3725
commit 73681948d3
2 changed files with 16 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import { useConfig } from "@/hooks/useConfig";
import { useTranslate } from "@/hooks/useTranslate";
import { Title } from "@/layout/content/Title";
import { EntityType, RouterType } from "@/services/types";
import { extractQueryParamsUrl } from "@/utils/URL";
import { getAvatarSrc } from "../helpers/mapMessages";
import { useChat } from "../hooks/ChatContext";
@ -64,7 +65,10 @@ export const SubscribersList = (props: {
<Conversation
onClick={() => {
chat.setSubscriberId(subscriber.id);
push(`/${RouterType.INBOX}/subscribers/${subscriber.id}`);
push({
pathname: `/${RouterType.INBOX}/subscribers/${subscriber.id}`,
query: extractQueryParamsUrl(window.location.href),
});
}}
className="changeColor"
key={subscriber.id}

View File

@ -6,6 +6,8 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
import qs from "qs";
export const getFromQuery = ({
key,
search,
@ -57,3 +59,12 @@ export const isAbsoluteUrl = (value: string = ""): boolean => {
return false;
}
};
// todo: in the future we might need to extract this logic into a hook
export const extractQueryParamsUrl = (fullUrl: string): string => {
const extractedQueryParams = qs.parse(new URL(fullUrl).search, {
ignoreQueryPrefix: true,
});
return qs.stringify(extractedQueryParams);
};