Skip to content

Commit

Permalink
feat: remove Sanity from Job, Publication, Skill and Intro types
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc committed Aug 26, 2023
1 parent 2e9ac3f commit 5cab6f7
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 127 deletions.
48 changes: 5 additions & 43 deletions src/app/(public)/about/work/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,28 @@ import Image from 'next/image';
import * as React from 'react';
import ReactMarkdown from 'react-markdown';

import { flattenToArray, flattenToObject } from '@/lib/graphqlUtils';

import Heading from '@/components/atoms/Heading';
import Education from '@/components/organisms/about-work/Education';
import Intro from '@/components/organisms/about-work/Intro';
import Languages from '@/components/organisms/about-work/Languages';
import Publications from '@/components/organisms/about-work/Publications';
import WorkExperience from '@/components/organisms/about-work/WorkExperience';

import { jobsQueryQL } from '@/queries/jobs';
import { languagesQueryQL } from '@/queries/languages';
import { publicationQueryQL } from '@/queries/publications';
import { queryJobs } from '@/queries/jobs';
import { queryLanguages } from '@/queries/languages';
import { queryPublications } from '@/queries/publications';
import { querySchools } from '@/queries/schools';
import { softwareDevIntroQuery } from '@/queries/short-texts';
import { skillQueryQL } from '@/queries/skills';

import apolloClient from '../../../../../apollo/apollo-client';
import { queryIntro } from '@/queries/short-texts';
import { querySkills } from '@/queries/skills';

import { Icon } from '@/types/Icon';
import { Job } from '@/types/Job';
import { Language } from '@/types/Language';
import { Publication } from '@/types/Publication';
import { SoftwareDevIntro } from '@/types/ShortText';
import { Skill } from '@/types/Skill';

export const metadata = {
title: 'About my Work | MartaCodes.it',
description: 'About page',
};

async function queryIntro() {
const { data } = await apolloClient.query({ query: softwareDevIntroQuery });

return flattenToObject<SoftwareDevIntro>(data.softwareDevelopmentIntro);
}

async function queryJobs() {
const { data } = await apolloClient.query({ query: jobsQueryQL });

return flattenToArray<Job>(data.jobs);
}

async function queryPublications() {
const { data } = await apolloClient.query({ query: publicationQueryQL });

return flattenToArray<Publication>(data.publications);
}

async function querySkills() {
const { data } = await apolloClient.query({ query: skillQueryQL });

return flattenToArray<Skill>(data.skills);
}

async function queryLanguages() {
const { data } = await apolloClient.query({ query: languagesQueryQL });

return flattenToArray<Language>(data.languages);
}

const queryData = async () => {
const intro = await queryIntro();

Expand Down
6 changes: 2 additions & 4 deletions src/pages/api/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { NextApiRequest, NextApiResponse } from 'next';

import { jobsQuery } from '@/queries/jobs';
import { queryJobs } from '@/queries/jobs';
import { Job } from '@/sanityTypes/Job';

import { sanityClient } from '../../../sanity/lib/client';

const jobsApi = async (req: NextApiRequest, res: NextApiResponse) => {
const jobs: Job[] = await sanityClient.fetch(jobsQuery);
const jobs: Job[] = await queryJobs();

res.status(200).json(jobs);
};
Expand Down
8 changes: 2 additions & 6 deletions src/pages/api/publications.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { NextApiRequest, NextApiResponse } from 'next';

import { publicationQuery } from '@/queries/publications';
import { queryPublications } from '@/queries/publications';
import { Publication } from '@/sanityTypes/Publication';

import { sanityClient } from '../../../sanity/lib/client';

const publicationsApi = async (req: NextApiRequest, res: NextApiResponse) => {
const publications: Publication[] = await sanityClient.fetch(
publicationQuery
);
const publications: Publication[] = await queryPublications();

res.status(200).json(publications);
};
Expand Down
14 changes: 0 additions & 14 deletions src/pages/api/short-texts.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/pages/api/skills.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { NextApiRequest, NextApiResponse } from 'next';

import { skillQuery } from '@/queries/skills';
import { querySkills } from '@/queries/skills';
import { Skill } from '@/sanityTypes/Skill';

import { sanityClient } from '../../../sanity/lib/client';

const skillsApi = async (req: NextApiRequest, res: NextApiResponse) => {
const skills: Skill[] = await sanityClient.fetch(skillQuery);
const skills: Skill[] = await querySkills();

res.status(200).json(skills);
};
Expand Down
27 changes: 11 additions & 16 deletions src/queries/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { gql } from '@apollo/client';
import { groq } from 'next-sanity';

export const jobsQuery = groq`
*[_type == "job"] | order(endDate desc) {
_id,
company,
"iconUrl": icon.asset->url,
location,
jobTitle,
startDate,
endDate,
isCurrentJob,
description,
technologies,
mainColor,
darkColor,
}`;
import { flattenToArray } from '@/lib/graphqlUtils';

import apolloClient from '../../apollo/apollo-client';

import { Job } from '@/types/Job';

export async function queryJobs() {
const { data } = await apolloClient.query({ query: jobsQueryQL });

return flattenToArray<Job>(data.jobs);
}

export const jobsQueryQL = gql`
query {
Expand Down
19 changes: 11 additions & 8 deletions src/queries/languages.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { gql } from '@apollo/client';
import { groq } from 'next-sanity';

export const languageQuery = groq`
*[_type == "language"] | order(id asc) {
_id,
name,
level,
"flagUrl": flag.asset->url
}`;
import { flattenToArray } from '@/lib/graphqlUtils';

import apolloClient from '../../apollo/apollo-client';

import { Language } from '@/types/Language';

export async function queryLanguages() {
const { data } = await apolloClient.query({ query: languagesQueryQL });

return flattenToArray<Language>(data.languages);
}

export const languagesQueryQL = gql`
query {
Expand Down
22 changes: 11 additions & 11 deletions src/queries/publications.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { gql } from '@apollo/client';
import { groq } from 'next-sanity';

export const publicationQuery = groq`
*[_type == "publication"] | order(sortId asc) {
_id,
name,
title,
description,
publisher,
year,
"link": file.asset->url
}`;
import { flattenToArray } from '@/lib/graphqlUtils';

import apolloClient from '../../apollo/apollo-client';

import { Publication } from '@/types/Publication';

export async function queryPublications() {
const { data } = await apolloClient.query({ query: publicationQueryQL });

return flattenToArray<Publication>(data.publications);
}

export const publicationQueryQL = gql`
query {
Expand Down
20 changes: 11 additions & 9 deletions src/queries/short-texts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { gql } from '@apollo/client';
import { groq } from 'next-sanity';

export const shortTextQuery = groq`
*[_type == "shortText"] {
_id,
name,
title,
content,
"iconUrl": icon.asset->url
}`;
import { flattenToObject } from '@/lib/graphqlUtils';

import apolloClient from '../../apollo/apollo-client';

import { SoftwareDevIntro } from '@/types/ShortText';

export async function queryIntro() {
const { data } = await apolloClient.query({ query: softwareDevIntroQuery });

return flattenToObject<SoftwareDevIntro>(data.softwareDevelopmentIntro);
}

export const softwareDevIntroQuery = gql`
query {
Expand Down
23 changes: 11 additions & 12 deletions src/queries/skills.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { gql } from '@apollo/client';
import { groq } from 'next-sanity';

export const skillQuery = groq`
*[_type == "skill"] {
name,
title,
description,
'icons': icons[]-> {
_id,
title,
"url": icon.asset->url
}
}`;
import { flattenToArray } from '@/lib/graphqlUtils';

import apolloClient from '../../apollo/apollo-client';

import { Skill } from '@/types/Skill';

export async function querySkills() {
const { data } = await apolloClient.query({ query: skillQueryQL });

return flattenToArray<Skill>(data.skills);
}

export const skillQueryQL = gql`
query {
Expand Down

0 comments on commit 5cab6f7

Please sign in to comment.