Skip to content

Commit

Permalink
feat: add UsesPage query and type; add data to page
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc committed Sep 26, 2023
1 parent 857bc4e commit df8de7e
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
32 changes: 32 additions & 0 deletions src/app/(public)/uses/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
import * as React from 'react';
import ReactMarkdown from 'react-markdown';

import Heading from '@/components/atoms/headings/Heading';

import { queryUsesPage } from '@/queries/uses-page';

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

const queryData = async () => {
const usesPage = await queryUsesPage();

return {
usesPage,
};
};

const UsesPage = async () => {
const { usesPage } = await queryData();

const sections = [
usesPage.hardware,
usesPage.programmingTools,
usesPage.productivity,
usesPage.security,
usesPage.media,
];

return (
<main className='min-h-main'>
<section>
<div className='layout relative flex flex-col py-12'>
<Heading title='uses.title' />

{sections.map((section) => (
<div
className='mb-2'
aria-label={section.title}
key={section.title}
>
<h2 className='my-4'>{section.title}</h2>
<ReactMarkdown>{section.content}</ReactMarkdown>
</div>
))}
</div>
</section>
</main>
Expand Down
45 changes: 45 additions & 0 deletions src/queries/uses-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { gql } from '@apollo/client';

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

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

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

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

return flattenToObject<UsesPage>(data.usesPage);
}

export const UsesPageQuery = gql`
{
usesPage {
data {
id
attributes {
hardware {
title
content
}
programmingTools {
title
content
}
productivity {
title
content
}
media {
title
content
}
security {
title
content
}
}
}
}
}
`;
7 changes: 2 additions & 5 deletions src/types/RecruitersPage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TitledParagraph } from '@/types/Shared';

export interface RecruitersPage {
intro: string;
salary: TitledParagraph;
Expand All @@ -7,8 +9,3 @@ export interface RecruitersPage {
tldr: TitledParagraph;
outro: string;
}

interface TitledParagraph {
title: string;
content: string;
}
4 changes: 4 additions & 0 deletions src/types/Shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface TitledParagraph {
title: string;
content: string;
}
9 changes: 9 additions & 0 deletions src/types/UsesPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { TitledParagraph } from '@/types/Shared';

export interface UsesPage {
hardware: TitledParagraph;
media: TitledParagraph;
productivity: TitledParagraph;
programmingTools: TitledParagraph;
security: TitledParagraph;
}

0 comments on commit df8de7e

Please sign in to comment.