generated from theodorusclarence/ts-nextjs-tailwind-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add publication type, schema and query
- Loading branch information
1 parent
81223c5
commit f6918e0
Showing
8 changed files
with
160 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }], | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |