Skip to content

Commit

Permalink
feat: move type CodeSnippet
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc committed Aug 24, 2023
1 parent f376fe2 commit 7b3a838
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apollo/apollo-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApolloClient, InMemoryCache } from '@apollo/client';

const apolloClient = new ApolloClient({
uri: 'https://martacodes-it-strapi.up.railway.app/graphql',
uri: process.env.GRAPHQL_URL,
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
Expand Down
25 changes: 15 additions & 10 deletions src/app/(public)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import * as React from 'react';

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

import Intro from '@/components/organisms/home/Intro';
import Summary from '@/components/organisms/home/Summary';
import Seo from '@/components/Seo';

import { codeSnippetsQuery } from '@/queries/codeSnippets';
import { CodeSnippet } from '@/sanityTypes/CodeSnippet';
import { codeSnippetsQueryQL } from '@/queries/codeSnippets';

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

const getData = async () => {
// const homeData: HomeContent[] = await sanityClient.fetch(homeContentQuery);
const codeSnippets: CodeSnippet[] = await sanityClient.fetch(
codeSnippetsQuery
);
import { CodeSnippet } from '@/types/CodeSnippet';

async function queryCodeSnippets() {
const { data } = await apolloClient.query({ query: codeSnippetsQueryQL });

return flattenToArray<CodeSnippet>(data.codeSnippets);
}

const queryData = async () => {
const codeSnippets: CodeSnippet[] = await queryCodeSnippets();

return {
codeSnippets,
// homeContent: homeData[0],
};
};

const HomePage = async () => {
const { codeSnippets } = await getData();
const { codeSnippets } = await queryData();

return (
<main className='min-h-main'>
Expand Down
4 changes: 2 additions & 2 deletions src/components/organisms/home/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'react-syntax-highlighter/dist/cjs/styles/hljs';
import Typed, { TypedOptions } from 'typed.js';

import { CodeSnippet } from '@/sanityTypes/CodeSnippet';
import { CodeSnippet } from '@/types/CodeSnippet';

export interface CodeSnippetsProps {
codeSnippets: CodeSnippet[];
Expand Down Expand Up @@ -64,7 +64,7 @@ const Code = ({ codeSnippets }: CodeSnippetsProps) => {
codeSnippets.map((snippet) => (
<SyntaxHighlighter
className='text-xs md:text-base'
key={snippet._id}
key={snippet.id}
language={snippet.language}
style={ideStyle}
wrapLongLines={true}
Expand Down
5 changes: 5 additions & 0 deletions src/types/CodeSnippet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface CodeSnippet {
id: string;
code: string;
language: string;
}

0 comments on commit 7b3a838

Please sign in to comment.