Skip to content

Commit

Permalink
feat: add publication type, schema and query
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc-resourcify committed Jul 22, 2023
1 parent 81223c5 commit f6918e0
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 5 deletions.
3 changes: 2 additions & 1 deletion sanity/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { type SchemaTypeDefinition } from 'sanity';

import job from '../src/schemas/job';
import language from '../src/schemas/language';
import publication from '../src/schemas/publication';
import school from '../src/schemas/school';
import shortText from '../src/schemas/shortText';
import skill from '../src/schemas/skill';
import skillIcon from '../src/schemas/skillIcon';

export const schema: { types: SchemaTypeDefinition[] } = {
types: [job, language, school, shortText, skill, skillIcon],
types: [job, language, publication, school, shortText, skill, skillIcon],
};
13 changes: 12 additions & 1 deletion src/app/(public)/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import * as React from 'react';

import Education from '@/components/organisms/Education/Education';
import Languages from '@/components/organisms/Languages/Languages';
import Publications from '@/components/organisms/Publications/Publications';
import WorkExperience from '@/components/organisms/WorkExperience/WorkExperience';

import { jobsQuery } from '@/queries/jobs';
import { languageQuery } from '@/queries/languages';
import { publicationQuery } from '@/queries/publications';
import { schoolsQuery } from '@/queries/schools';
import { shortTextQuery } from '@/queries/short-texts';
import { skillQuery } from '@/queries/skills';
Expand All @@ -16,6 +18,7 @@ import { sanityClient } from '../../../../sanity/lib/client';

import { Job } from '@/types/Job';
import { Language } from '@/types/Language';
import { Publication } from '@/types/Publication';
import { School } from '@/types/School';
import { ShortText } from '@/types/ShortText';
import { Skill } from '@/types/Skill';
Expand All @@ -31,6 +34,10 @@ const getData = async () => {

const languages: Language[] = await sanityClient.fetch(languageQuery);

const publications: Publication[] = await sanityClient.fetch(
publicationQuery
);

const schools: School[] = await sanityClient.fetch(schoolsQuery);

const skills: Skill[] = await sanityClient.fetch(skillQuery);
Expand All @@ -40,14 +47,16 @@ const getData = async () => {
return {
jobs,
languages,
publications,
schools,
shortTexts,
skills,
};
};

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

const softwareDevelopment: ShortText | undefined = shortTexts.find(
(item) => item.name === 'software-development'
Expand Down Expand Up @@ -123,6 +132,8 @@ const AboutPage = async () => {
<Education schools={schools} />

<Languages languages={languages} />

<Publications publications={publications} />
</div>
</section>
</main>
Expand Down
6 changes: 3 additions & 3 deletions src/components/organisms/Languages/Languages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ export interface LanguageProps {

const Languages = ({ languages }: LanguageProps) => {
return (
<div>
<div className='mb-6'>
<div className='m-2 flex'>
<h2>Languages</h2>
</div>

<div className='flex flex-col md:w-full md:flex-row md:justify-between'>
<div className='grid grid-cols-1 gap-3 md:grid-cols-4 md:gap-6'>
{languages.map((language) => (
<div
key={language.id}
className='mb-4 flex flex-row items-center rounded-md p-4 shadow-md dark:bg-slate-900 md:w-64'
className='flex flex-row items-center rounded-md p-4 shadow-md dark:bg-slate-900 md:w-64'
>
<Image
src={language.flagUrl}
Expand Down
54 changes: 54 additions & 0 deletions src/components/organisms/Publications/Publications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use client';

import * as React from 'react';
import { AiOutlineFilePdf } from 'react-icons/ai';

import UnstyledLink from '@/components/links/UnstyledLink';

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

export interface PublicationProps {
publications: Publication[];
}

const Publications = ({ publications }: PublicationProps) => {
return (
<div className='mb-6'>
<div className='m-2 flex'>
<h2>Publications</h2>
</div>

<div className='grid grid-cols-1 gap-3 md:grid-cols-3 md:gap-8'>
{publications.map((publication) => (
<div
key={publication._id}
className='flex h-32 flex-col justify-between rounded-md p-4 shadow-md dark:bg-slate-900 md:h-40'
>
<span className='font-semibold'>{publication.title}</span>

<div className='flex flex-row justify-between'>
<div className='flex flex-col'>
<span className='font-light'>{publication.description}</span>
<span className='font-light'>
{publication.publisher}, {publication.year}
</span>
</div>

<div className='flex flex-col self-end'>
<UnstyledLink
key={publication._id}
className='focus-visible:ring-primary-300 inline-flex items-center justify-center rounded-sm focus:outline-none focus-visible:ring'
href={publication.link}
>
<AiOutlineFilePdf className='hover:text-primary-500 dark:hover:text-primary-300 my-auto h-6 w-6 align-middle text-blue-900 transition-colors dark:text-gray-300' />
</UnstyledLink>
</div>
</div>
</div>
))}
</div>
</div>
);
};

export default Publications;
17 changes: 17 additions & 0 deletions src/pages/api/publications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NextApiRequest, NextApiResponse } from 'next';

import { publicationQuery } from '@/queries/publications';

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

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

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

res.status(200).json(publications);
};

export default publicationsApi;
12 changes: 12 additions & 0 deletions src/queries/publications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { groq } from 'next-sanity';

export const publicationQuery = groq`
*[_type == "publication"] | order(sortId asc) {
_id,
name,
title,
description,
publisher,
year,
"link": file.asset->url
}`;
51 changes: 51 additions & 0 deletions src/schemas/publication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { defineField, defineType } from 'sanity';

export default defineType({
name: 'publication',
title: 'Publication',
type: 'document',
fields: [
defineField({
name: 'sortId',
title: 'Sort Id',
type: 'number',
}),
defineField({
name: 'name',
title: 'Name',
type: 'string',
}),
defineField({
name: 'title',
title: 'Title',
type: 'string',
}),
defineField({
name: 'description',
title: 'Description',
type: 'string',
}),
defineField({
name: 'publisher',
title: 'Publisher',
type: 'string',
}),
defineField({
name: 'year',
title: 'Year',
type: 'number',
}),
defineField({
name: 'file',
title: 'File',
type: 'file',
}),
],
orderings: [
{
title: 'Most Recent',
name: 'mostRecent',
by: [{ field: 'sortId', direction: 'asc' }],
},
],
});
9 changes: 9 additions & 0 deletions src/types/Publication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface Publication {
_id: string;
name: string;
title: string;
description: string;
publisher: string;
year: number;
link: string;
}

0 comments on commit f6918e0

Please sign in to comment.