Skip to content

Commit

Permalink
fix(GoalsPage): sync client and server fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
awinogradov committed Jun 27, 2023
1 parent f621d8b commit 4109d7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/components/GoalsPage/GoalsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export const GoalsPage = ({ user, ssrTime }: ExternalPageProps) => {
[pages],
);
const meta = data?.pages?.[0].meta;
const userFilters = trpc.filter.getUserFilters.useQuery();
const userFilters = trpc.filter.getUserFilters.useQuery(undefined, {
keepPreviousData: true,
staleTime: refreshInterval,
});
const shadowPreset = userFilters.data?.filter((f) => f.params === queryString)[0];

useEffect(() => {
Expand Down
18 changes: 10 additions & 8 deletions src/pages/goals/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { GoalsPage } from '../../components/GoalsPage/GoalsPage';
import { declareSsrProps } from '../../utils/declareSsrProps';
// import { parseFilterValues } from '../../hooks/useUrlFilterParams';
import { parseFilterValues } from '../../hooks/useUrlFilterParams';

const pageSize = 20;

export const getServerSideProps = declareSsrProps(
async ({ query, ssrHelpers }) => {
// const preset =
typeof query.filter === 'string' ? await ssrHelpers.filter.getById.fetch(query.filter) : undefined;
const preset =
typeof query.filter === 'string' ? await ssrHelpers.filter.getById.fetch(query.filter) : undefined;

await ssrHelpers.goal.getBatch.fetchInfinite({ limit: 20 });
await ssrHelpers.goal.getBatch.fetchInfinite({
limit: pageSize,
query: parseFilterValues(preset ? Object.fromEntries(new URLSearchParams(preset.params)) : query),
});

// await ssrHelpers.filter.getUserFilters.fetch();
// await ssrHelpers.goal.getUserGoals.fetch(
// parseFilterValues(preset ? Object.fromEntries(new URLSearchParams(preset.params)) : query),
// );
await ssrHelpers.filter.getUserFilters.fetch();
},
{
private: true,
Expand Down

0 comments on commit 4109d7a

Please sign in to comment.