Skip to content

Commit

Permalink
feat: add Podcast type, schema and query
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc-resourcify committed Jul 23, 2023
1 parent da76c4e commit 56d8771
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sanity/deskStructure.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const workSection = ['job', 'language', 'publication', 'school', 'skill'];
const freeTimeSection = ['book'];
const freeTimeSection = ['book', 'podcast'];
const sharedSection = ['shortText', 'skillIcon'];

export const customStructure = (S) =>
Expand Down
2 changes: 2 additions & 0 deletions sanity/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type SchemaTypeDefinition } from 'sanity';
import book from '../src/schemas/book';
import job from '../src/schemas/job';
import language from '../src/schemas/language';
import podcast from '../src/schemas/podcast';
import publication from '../src/schemas/publication';
import school from '../src/schemas/school';
import shortText from '../src/schemas/shortText';
Expand All @@ -14,6 +15,7 @@ export const schema: { types: SchemaTypeDefinition[] } = {
book,
job,
language,
podcast,
publication,
school,
shortText,
Expand Down
10 changes: 9 additions & 1 deletion src/app/(public)/about/free-time/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import * as React from 'react';

import Books from '@/components/organisms/about-free-time/Books';
import Podcasts from '@/components/organisms/about-free-time/Podcasts';

import { booksQuery } from '@/queries/books';
import { podcastsQuery } from '@/queries/podcasts';

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

import { Book } from '@/types/Book';
import { Podcast } from '@/types/Podcast';

export const metadata = {
title: 'About my Free Time | MartaCodes.it',
Expand All @@ -16,13 +19,16 @@ export const metadata = {
const getData = async () => {
const books: Book[] = await sanityClient.fetch(booksQuery);

const podcasts: Podcast[] = await sanityClient.fetch(podcastsQuery);

return {
books,
podcasts,
};
};

const AboutFreeTimePage = async () => {
const { books } = await getData();
const { books, podcasts } = await getData();

return (
<main className='min-h-main'>
Expand All @@ -40,6 +46,8 @@ const AboutFreeTimePage = async () => {
</div>

<Books books={books} />

<Podcasts podcasts={podcasts} />
</div>
</section>
</main>
Expand Down
44 changes: 44 additions & 0 deletions src/components/organisms/about-free-time/Podcasts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use client';

import Image from 'next/image';
import * as React from 'react';

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

export interface PodcastProps {
podcasts: Podcast[];
}

const Podcasts = ({ podcasts }: PodcastProps) => {
return (
<div className=''>
<div className='m-2 flex'>
<h2>Podcasts I follow</h2>
</div>

<ul className='scroll-mandatory relative -mx-4 flex w-[100vw] snap-x gap-3 overflow-x-auto px-4 pb-14 md:mx-0 md:w-full md:px-0'>
{podcasts.map((podcast) => (
<li
key={podcast._id}
className='h-[136px] w-[136px] shrink-0 snap-center overflow-hidden rounded-lg bg-transparent p-1 transition-all hover:bg-gradient-to-r hover:from-orange-400 hover:to-orange-700'
>
<a
href={podcast.mediaLink}
target='_blank'
rel='noopener noreferrer'
>
<Image
alt={podcast.name}
src={podcast.cover}
width={130}
height={130}
/>
</a>
</li>
))}
</ul>
</div>
);
};

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

import { booksQuery } from '@/queries/books';
import { podcastsQuery } from '@/queries/podcasts';

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

import { Book } from '@/types/Book';
import { Podcast } from '@/types/Podcast';

const hobbiesApi = async (req: NextApiRequest, res: NextApiResponse) => {
const books: Book[] = await sanityClient.fetch(booksQuery);

const podcasts: Podcast[] = await sanityClient.fetch(podcastsQuery);

res.status(200).json({
books,
podcasts,
});
};

Expand Down
11 changes: 11 additions & 0 deletions src/queries/podcasts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { groq } from 'next-sanity';

export const podcastsQuery = groq`
*[_type == "podcast"] | order(author asc) {
_id,
name,
author,
language,
"cover": cover.asset->url,
mediaLink,
}`;
47 changes: 47 additions & 0 deletions src/schemas/podcast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { defineField, defineType } from 'sanity';

export default defineType({
name: 'podcast',
title: 'Podcast',
type: 'document',
fields: [
defineField({
name: 'name',
title: 'Name',
type: 'string',
}),
defineField({
name: 'author',
title: 'Author',
type: 'string',
}),
defineField({
name: 'language',
title: 'language',
type: 'string',
options: {
list: [
{ title: 'En', value: 'en' },
{ title: 'It', value: 'it' },
],
},
}),
defineField({
name: 'cover',
title: 'Cover',
type: 'image',
}),
defineField({
name: 'mediaLink',
title: 'Media Link',
type: 'string',
}),
],
orderings: [
{
title: 'Author',
name: 'authorAsc',
by: [{ field: 'author', direction: 'asc' }],
},
],
});
8 changes: 8 additions & 0 deletions src/types/Podcast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Podcast {
_id: string;
name: string;
author: string;
language: string;
cover: string;
mediaLink: string;
}

0 comments on commit 56d8771

Please sign in to comment.