Skip to content

Commit

Permalink
refactor(pageData): remove unused query and queryParams (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom authored Oct 16, 2024
1 parent 5353091 commit 9456490
Showing 1 changed file with 21 additions and 38 deletions.
59 changes: 21 additions & 38 deletions src/utils/pageData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientPerspective, QueryParams } from "@sanity/client";
import { ClientPerspective } from "@sanity/client";
import { QueryResponseInitial } from "@sanity/react-loader";

import { CompanyLocation } from "studio/lib/interfaces/companyDetails";
Expand Down Expand Up @@ -28,8 +28,6 @@ import { loadSharedQuery } from "studioShared/lib/store";
import { customerCaseID } from "studioShared/schemas/documents/customerCase";

type PageFromParams<D, T> = {
query: string;
queryParams: QueryParams;
queryResponse: D;
docType: T;
};
Expand All @@ -45,21 +43,18 @@ async function fetchDynamicPage({
if (path.length === 0) {
return null;
}
const queryParams = {
slug: path[0],
language,
};
const pageResult = await loadStudioQuery<PageBuilder | null>(
PAGE_BY_SLUG_QUERY,
queryParams,
{
slug: path[0],
language,
},
{ perspective },
);
if (pageResult.data === null) {
return null;
}
return {
query: PAGE_BY_SLUG_QUERY,
queryParams,
queryResponse: {
...pageResult,
data: pageResult.data,
Expand All @@ -83,14 +78,13 @@ async function fetchCompensationsPage({
if (path.length !== 1) {
return null;
}
const queryParams = {
slug: path[0],
language,
};
const compensationsPageResult =
await loadStudioQuery<CompensationsPage | null>(
COMPENSATIONS_PAGE_BY_SLUG_QUERY,
queryParams,
{
slug: path[0],
language,
},
{
perspective,
},
Expand All @@ -115,8 +109,6 @@ async function fetchCompensationsPage({
return null;
}
return {
query: COMPENSATIONS_PAGE_BY_SLUG_QUERY,
queryParams,
queryResponse: {
compensationsPage: {
...compensationsPageResult,
Expand Down Expand Up @@ -147,37 +139,33 @@ async function fetchCustomerCase({
if (path.length === 0) {
return null;
}
const customerCasesPageParams = {
slug: path[0],
language,
};
const customerCasesPageResult =
await loadStudioQuery<CustomerCasePage | null>(
CUSTOMER_CASES_PAGE_QUERY,
customerCasesPageParams,
{
slug: path[0],
language,
},
{ perspective },
);
if (customerCasesPageResult.data === null) {
return null;
}
if (path.length === 1) {
return {
query: CUSTOMER_CASES_PAGE_QUERY,
queryParams: customerCasesPageParams,
queryResponse: {
...customerCasesPageResult,
data: customerCasesPageResult.data,
},
docType: customerCasesPageID,
};
}
const customerCaseParams = {
slug: path[1],
language,
};
const customerCaseResult = await loadSharedQuery<CustomerCase | null>(
CUSTOMER_CASE_QUERY,
customerCaseParams,
{
slug: path[1],
language,
},
{
perspective,
},
Expand All @@ -186,8 +174,6 @@ async function fetchCustomerCase({
return null;
}
return {
query: CUSTOMER_CASE_QUERY,
queryParams: customerCaseParams,
queryResponse: {
...customerCaseResult,
data: customerCaseResult.data,
Expand All @@ -207,13 +193,12 @@ async function fetchLegalDocument({
if (path.length !== 1) {
return null;
}
const queryParams = {
slug: path[0],
language,
};
const queryResponse = await loadStudioQuery<LegalDocument | null>(
LEGAL_DOCUMENT_BY_SLUG_AND_LANG_QUERY,
queryParams,
{
slug: path[0],
language,
},
{
perspective,
},
Expand All @@ -222,8 +207,6 @@ async function fetchLegalDocument({
return null;
}
return {
query: LEGAL_DOCUMENT_BY_SLUG_AND_LANG_QUERY,
queryParams,
queryResponse: {
...queryResponse,
data: queryResponse.data,
Expand Down

0 comments on commit 9456490

Please sign in to comment.