Skip to content

Commit

Permalink
feat: add ReactMarkdown; wip strapi GraphQL response tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc committed Aug 17, 2023
1 parent 514e990 commit 8c96162
Show file tree
Hide file tree
Showing 6 changed files with 527 additions and 9 deletions.
10 changes: 10 additions & 0 deletions apollo/apollo-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import { ApolloClient, InMemoryCache } from '@apollo/client';
const apolloClient = new ApolloClient({
uri: 'https://martacodes-it-strapi.up.railway.app/graphql',
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
fetchPolicy: 'network-only',
errorPolicy: 'ignore',
},
query: {
fetchPolicy: 'network-only',
errorPolicy: 'all',
},
},
});

export default apolloClient;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"react-dom": "^18.2.0",
"react-headroom": "^3.2.1",
"react-icons": "^4.10.1",
"react-markdown": "^8.0.7",
"react-syntax-highlighter": "^15.5.0",
"react-tippy": "^1.4.0",
"sanity": "^3.0.0",
Expand Down
16 changes: 12 additions & 4 deletions src/app/(public)/about/work/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { gql } from '@apollo/client';
import { PortableText } from '@portabletext/react';
import Image from 'next/image';
import * as React from 'react';
import { flattenEntityResponseCollection } from 'strapi-flatten-graphql';
import {
FlattenArray,
flattenEntityResponseCollection,
StrapiEntityResponseCollection,
} from 'strapi-flatten-graphql';

import Education from '@/components/organisms/about-work/Education';
import Languages from '@/components/organisms/about-work/Languages';
Expand All @@ -21,6 +25,7 @@ import { sanityClient } from '../../../../../sanity/lib/client';

import { Icon } from '@/types/Icon';
import { Job } from '@/types/Job';
import { Job2 } from '@/types/Job2';
import { Language } from '@/types/Language';
import { Publication } from '@/types/Publication';
import { School } from '@/types/School';
Expand Down Expand Up @@ -89,16 +94,19 @@ const queryData = async () => {
`,
});

const jobs: FlattenArray<StrapiEntityResponseCollection<Job2>> =
flattenEntityResponseCollection(data.jobs);
// const jobs = flattenEntityResponseCollection(data.jobs);
return {
jobs: flattenEntityResponseCollection(data.jobs),
jobs,
};
};

const AboutPage = async () => {
const { jobs, languages, publications, schools, shortTexts, skills } =
await getData();

const js = await queryData();
const js: Job2[] = (await queryData()).jobs;

const softwareDevelopment: ShortText | undefined = shortTexts.find(
(item) => item.name === 'software-development'
Expand All @@ -110,7 +118,7 @@ const AboutPage = async () => {
const titleIconDimension = 42;

// eslint-disable-next-line no-console
console.log(js);
console.log(js[0].Description);

return (
<main className='min-h-main'>
Expand Down
9 changes: 9 additions & 0 deletions src/lib/graphqlUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { flattenEntityResponseCollection } from 'strapi-flatten-graphql';

// type StrapiEntityResponseCollection<T> = {
// data: T[];
// };

function _toCollection<T>(entityResponse: object): T[] {
return flattenEntityResponseCollection(entityResponse);
}
14 changes: 14 additions & 0 deletions src/types/Job2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface Job2 {
id: string;
title: string;
companyName: string;
icon: object;
location: string;
startDate: string;
endDate: string;
isCurrentJob: boolean;
description: string;
mainColor: string;
darkColor: string;
technologies: string[];
}
Loading

0 comments on commit 8c96162

Please sign in to comment.