Skip to content

Commit

Permalink
fix: persist query params after redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
breeg554 committed Oct 11, 2024
1 parent 1799dda commit f6d9baf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import type { LoaderFunctionArgs, MetaFunction } from '@remix-run/node';
import { json } from '@remix-run/node';
import { useLoaderData, useNavigate } from '@remix-run/react';
import { useLoaderData, useNavigate, useSearchParams } from '@remix-run/react';
import type { OnConnect } from '@buildel/buildel';
import invariant from 'tiny-invariant';

Expand All @@ -10,6 +10,7 @@ import { chatSize } from '~/components/chat/chat.types';
import { Webchat } from '~/components/chat/Webchat';
import { loaderBuilder } from '~/utils.server';
import { metaWithDefaults } from '~/utils/metadata';
import { routes } from '~/utils/routes.utils';

export async function loader(args: LoaderFunctionArgs) {
return loaderBuilder(async ({ params, request }, { fetch }) => {
Expand Down Expand Up @@ -37,6 +38,7 @@ export async function loader(args: LoaderFunctionArgs) {

export default function WebsiteChat() {
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const {
pipelineId,
organizationId,
Expand All @@ -48,7 +50,17 @@ export default function WebsiteChat() {
} = useLoaderData<typeof loader>();

const onConnect: OnConnect = (config) => {
navigate(config.id.toString(), { replace: true });
navigate(
routes.chatPreviewRun(
organizationId,
pipelineId,
config.id,
Object.fromEntries(searchParams.entries()),
),
{
replace: true,
},
);
};

return (
Expand Down
5 changes: 3 additions & 2 deletions apps/web-remix/app/utils/routes.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,14 @@ export const routes = {
`/webchats${routes.pipeline(organizationId, pipelineId)}`,
params,
),
voiceChatPreview: (
chatPreviewRun: (
organizationId: OrganizationId,
pipelineId: PipelineId,
runId: RunId,
params: RouteParam = {},
) =>
buildUrlWithParams(
`/voice-chat${routes.pipeline(organizationId, pipelineId)}`,
`${routes.chatPreview(organizationId, pipelineId)}/${runId}`,
params,
),
formPreview: (
Expand Down

0 comments on commit f6d9baf

Please sign in to comment.