Skip to content

Commit

Permalink
move all siteSettings related queries to siteSetting.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
anemne committed Sep 27, 2024
1 parent 2c70fec commit 96f7a3c
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 102 deletions.
10 changes: 6 additions & 4 deletions src/app/(main)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
COMPANY_INFO_QUERY,
LEGAL_DOCUMENTS_BY_LANG_QUERY,
} from "studio/lib/queries/admin";
import { BRAND_ASSETS_QUERY } from "studio/lib/queries/brandAssets";
import { NAV_QUERY } from "studio/lib/queries/navigation";
import { SOMEPROFILES_QUERY } from "studio/lib/queries/socialMediaProfiles";
import {
BRAND_ASSETS_QUERY,
NAV_QUERY,
SOME_PROFILES_QUERY,
} from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

import styles from "./layout.module.css";
Expand All @@ -39,7 +41,7 @@ export default async function Layout({
loadStudioQuery<Navigation>(NAV_QUERY, {}, { perspective }),
loadStudioQuery<CompanyInfo>(COMPANY_INFO_QUERY, {}, { perspective }),
loadStudioQuery<SocialMediaProfiles | null>(
SOMEPROFILES_QUERY,
SOME_PROFILES_QUERY,
{},
{ perspective },
),
Expand Down
2 changes: 1 addition & 1 deletion src/app/(main)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import SectionRenderer from "src/utils/renderSection";
import { fetchSeoData, generateMetadataFromSeo } from "src/utils/seo";
import { LinkType } from "studio/lib/interfaces/navigation";
import { PageBuilder } from "studio/lib/interfaces/pages";
import { LANDING_PAGE_REF_QUERY } from "studio/lib/queries/navigation";
import { PAGE_QUERY, SEO_PAGE_QUERY } from "studio/lib/queries/page";
import { LANDING_PAGE_REF_QUERY } from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

export async function generateMetadata(): Promise<Metadata> {
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { draftMode } from "next/headers";
import { generateMetadataFromSeo } from "src/utils/seo";
import { LanguageObject } from "studio/lib/interfaces/supportedLanguages";
import LiveVisualEditing from "studio/lib/loaders/AutomaticVisualEditing";
import { DEFAULT_LANGUAGE_QUERY } from "studio/lib/queries/languages";
import { DEFAULT_LANGUAGE_QUERY } from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

import "src/styles/global.css";
Expand Down
2 changes: 1 addition & 1 deletion src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { client } from "studio/lib/client";
import { DocumentWithSlug } from "studio/lib/interfaces/global";
import { PageBuilder } from "studio/lib/interfaces/pages";
import { DOCUMENTS_WITH_SLUG_QUERY } from "studio/lib/queries/document";
import { LANDING_PAGE_QUERY } from "studio/lib/queries/navigation";
import { LANDING_PAGE_QUERY } from "studio/lib/queries/siteSettings";
import { token } from "studio/lib/token";

import { readBaseUrl } from "./env";
Expand Down
2 changes: 1 addition & 1 deletion src/blog/components/legal/LegalPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { QueryResponseInitial, useQuery } from "@sanity/react-loader";

import { LegalDocument } from "studio/lib/interfaces/legalDocuments";
import { NAV_QUERY } from "studio/lib/queries/navigation";
import { NAV_QUERY } from "studio/lib/queries/siteSettings";

import Legal from "./Legal";

Expand Down
10 changes: 6 additions & 4 deletions src/components/navigation/footer/FooterPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { CompanyInfo } from "studio/lib/interfaces/companyDetails";
import { Navigation } from "studio/lib/interfaces/navigation";
import { SocialMediaProfiles } from "studio/lib/interfaces/socialMedia";
import { COMPANY_INFO_QUERY } from "studio/lib/queries/admin";
import { BRAND_ASSETS_QUERY } from "studio/lib/queries/brandAssets";
import { NAV_QUERY } from "studio/lib/queries/navigation";
import { SOMEPROFILES_QUERY } from "studio/lib/queries/socialMediaProfiles";
import {
BRAND_ASSETS_QUERY,
NAV_QUERY,
SOME_PROFILES_QUERY,
} from "studio/lib/queries/siteSettings";

import Footer from "./Footer";

Expand All @@ -34,7 +36,7 @@ export default function FooterPreview({
const newNav = useInitialData(NAV_QUERY, initialNav);
const newCompanyInfo = useInitialData(COMPANY_INFO_QUERY, initialCompanyInfo);
const newBrandAssets = useInitialData(BRAND_ASSETS_QUERY, initialBrandAssets);
const newSoMedata = useInitialData(SOMEPROFILES_QUERY, initialSoMe);
const newSoMedata = useInitialData(SOME_PROFILES_QUERY, initialSoMe);
// TODO: add legal preview
return (
newNav &&
Expand Down
3 changes: 1 addition & 2 deletions src/components/navigation/header/HeaderPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { QueryResponseInitial, useQuery } from "@sanity/react-loader";

import { BrandAssets } from "studio/lib/interfaces/brandAssets";
import { Navigation } from "studio/lib/interfaces/navigation";
import { BRAND_ASSETS_QUERY } from "studio/lib/queries/brandAssets";
import { NAV_QUERY } from "studio/lib/queries/navigation";
import { BRAND_ASSETS_QUERY, NAV_QUERY } from "studio/lib/queries/siteSettings";

import { Header } from "./Header";

Expand Down
2 changes: 1 addition & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from "next/server";

import { RedirectDestinationSlugPage } from "studio/lib/interfaces/redirect";
import { REDIRECT_BY_SOURCE_SLUG_QUERY } from "studio/lib/queries/redirects";
import { REDIRECT_BY_SOURCE_SLUG_QUERY } from "studio/lib/queries/siteSettings";

import { readBaseUrl } from "./app/env";
import { HTTP_STATUSES } from "./utils/http";
Expand Down
6 changes: 4 additions & 2 deletions src/utils/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { BrandAssets } from "studio/lib/interfaces/brandAssets";
import { CompanyInfo } from "studio/lib/interfaces/companyDetails";
import { DefaultSeo } from "studio/lib/interfaces/defaultSeo";
import { COMPANY_INFO_QUERY } from "studio/lib/queries/admin";
import { BRAND_ASSETS_QUERY } from "studio/lib/queries/brandAssets";
import { DEFAULT_SEO_QUERY } from "studio/lib/queries/seo";
import {
BRAND_ASSETS_QUERY,
DEFAULT_SEO_QUERY,
} from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

type SeoData = {
Expand Down
2 changes: 1 addition & 1 deletion studio/components/CustomCallToActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "sanity";

import { fetchWithToken } from "studio/lib/fetchWithToken";
import { LANDING_PAGE_REF_QUERY } from "studio/lib/queries/navigation";
import { LANDING_PAGE_REF_QUERY } from "studio/lib/queries/siteSettings";
import { buildPublishedId } from "studio/utils/documentUtils";

type CustomCallToActionsProps = ArrayOfObjectsInputProps<
Expand Down
7 changes: 0 additions & 7 deletions studio/lib/queries/brandAssets.ts

This file was deleted.

3 changes: 0 additions & 3 deletions studio/lib/queries/languages.ts

This file was deleted.

47 changes: 0 additions & 47 deletions studio/lib/queries/navigation.ts

This file was deleted.

10 changes: 0 additions & 10 deletions studio/lib/queries/redirects.ts

This file was deleted.

10 changes: 0 additions & 10 deletions studio/lib/queries/seo.ts

This file was deleted.

83 changes: 83 additions & 0 deletions studio/lib/queries/siteSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { groq } from "next-sanity";

import { brandAssetsID } from "studio/schemas/documents/siteSettings/brandAssets";

//Brand Assets
export const BRAND_ASSETS_QUERY = groq`
*[_type == "${brandAssetsID}" && _id == "${brandAssetsID}"][0]
`;

//Navigation Manager
export const NAV_QUERY = groq`
*[_type == "navigationManager"][0]{
"main": main[] {
...,
linkType == "internal" => {
...,
"internalLink": internalLink->{
"_ref": slug.current
}
}
},
"footer": footer[] {
...,
linksAndContent[] {
...,
linkType == "internal" => {
...,
"internalLink": internalLink->{
"_ref": slug.current
}
}
},
socialMediaLinks->{
"_ref": slug.current
}
},
"sidebar": sidebar[] {
...,
linkType == "internal" => {
...,
"internalLink": internalLink->{
"_ref": slug.current
}
}
}
}
`;

export const LANDING_PAGE_REF_QUERY = groq`
*[_type == "navigationManager"][0].setLanding._ref
`;

export const LANDING_PAGE_QUERY = groq`
*[_type == "navigationManager"][0].setLanding ->
`;

//Social Media Profiles
export const SOME_PROFILES_QUERY = groq`
*[_type == "soMeLinksID" && _id == "soMeLinksID"][0]
`;

//Languages
export const DEFAULT_LANGUAGE_QUERY = groq`*[_type == "languageSettings" && _id == "languageSettings"][0].languages[default][0]`;

//Default SEO
export const DEFAULT_SEO_QUERY = groq`*[_type == "seoFallback"]{
seo {
seoTitle,
seoDescription,
seoKeywords,
"seoImageUrl": seoImage.asset->url
}
}[0]`;

//Broken Links
export const REDIRECT_BY_SOURCE_SLUG_QUERY = groq`
*[_type == "redirect" && source.current == $slug][0]{
"destination": select(
destination.type == "reference" => destination.reference->slug.current,
destination.type == "external" => destination.external
)
}
`;
5 changes: 0 additions & 5 deletions studio/lib/queries/socialMediaProfiles.ts

This file was deleted.

4 changes: 2 additions & 2 deletions studio/schemas/objects/footerSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { StringInputProps, defineType } from "sanity";

import { StringInputWithCharacterCount } from "studio/components/stringInputWithCharacterCount/StringInputWithCharacterCount";
import { client } from "studio/lib/client";
import { SOMEPROFILES_QUERY } from "studio/lib/queries/socialMediaProfiles";
import { SOME_PROFILES_QUERY } from "studio/lib/queries/siteSettings";
import { soMeLinksID } from "studio/schemas/documents/siteSettings/socialMediaProfiles";
import { richText } from "studio/schemas/fields/text";

Expand Down Expand Up @@ -90,7 +90,7 @@ export const footerSection = defineType({
hidden: ({ parent }) => parent?.sectionType !== SectionType.SocialMedia,
initialValue: async () => {
// use Social Media Profiles singleton document if it exists
return (await client.fetch(SOMEPROFILES_QUERY)) !== null
return (await client.fetch(SOME_PROFILES_QUERY)) !== null
? {
_type: "reference",
_ref: soMeLinksID,
Expand Down

0 comments on commit 96f7a3c

Please sign in to comment.