Skip to content

Commit

Permalink
Make sources refresh client side
Browse files Browse the repository at this point in the history
  • Loading branch information
MytsV authored and maany committed Nov 15, 2024
1 parent f3e226e commit e7f87d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/app/_components/list-research-contexts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
import type { Signal } from "~/lib/core/entity/signals";
import { useRouter } from "next/navigation";
import type { SelectableSourceDataRow } from "node_modules/@maany_shr/rage-ui-kit/dist/components/table/SelectableSourceDataAGGrid";
import type { RemoteFile } from "~/lib/core/entity/file";
import { createResearchContextMutation, DEFAULT_RETRIES, DEFAULT_RETRY_DELAY, queryResearchContexts } from "~/app/queries";
import { createResearchContextMutation, DEFAULT_RETRIES, DEFAULT_RETRY_DELAY, queryResearchContexts, querySources } from "~/app/queries";
import { TListSourceDataViewModel } from "~/lib/core/view-models/list-source-data-view-models";

export function ListResearchContextsClientPage(props: { viewModel: TListResearchContextsViewModel; clientSourceData: RemoteFile[] }) {
const [listResearchContextsViewModel, setListResearchContextsViewModel] = useState<TListResearchContextsViewModel>(props.viewModel);
export function ListResearchContextsClientPage(props: { researchContextsViewModel: TListResearchContextsViewModel; sourceDataViewModel: TListSourceDataViewModel }) {
const [listResearchContextsViewModel, setListResearchContextsViewModel] = useState<TListResearchContextsViewModel>(props.researchContextsViewModel);
const [createResearchContextViewModel, setCreateResearchContextViewModel] = useState<TCreateResearchContextViewModel>({
status: "request",
researchContextName: "",
} as TCreateResearchContextViewModel);
const [listSourceDataViewModel, setListSourceDataViewModel] = useState<TListSourceDataViewModel>(props.sourceDataViewModel);

const router = useRouter();
const queryClient = useQueryClient();

useQuery<Signal<TListSourceDataViewModel>>({
queryKey: ["list-source-data"],
queryFn: querySources(setListSourceDataViewModel),
});

useQuery<Signal<TListResearchContextsViewModel>>({
queryKey: ["list-research-contexts"],
queryFn: queryResearchContexts(setListResearchContextsViewModel),
Expand Down Expand Up @@ -63,11 +69,15 @@ export function ListResearchContextsClientPage(props: { viewModel: TListResearch
listComponent = <ListResearchContextCard items={cards} />;
}

if (listSourceDataViewModel.status !== "success") {
throw Error("Couldn't load the sources");
}

return (
<>
{listComponent}
<CreateResearchContextDialog
clientFiles={props.clientSourceData}
clientFiles={listSourceDataViewModel.sourceData}
onSubmit={(researchContextName: string, researchContextDescription: string, sourceData: SelectableSourceDataRow[]) => {
createMutation.mutate({
title: researchContextName,
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default async function ListResearchContextsServerPage() {

return (
<div className="flex grow flex-col gap-4">
<ListResearchContextsClientPage viewModel={response.value} clientSourceData={listSourceDataForClientResponse.value.sourceData} />
<ListResearchContextsClientPage researchContextsViewModel={response.value} sourceDataViewModel={listSourceDataForClientResponse.value} />
</div>
);
}

0 comments on commit e7f87d0

Please sign in to comment.