Skip to content

Commit

Permalink
feat: add TvSeries type, schema and query
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc-resourcify committed Jul 24, 2023
1 parent ffbf797 commit 5b716f6
Show file tree
Hide file tree
Showing 8 changed files with 117 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', 'podcast', 'videoGame'];
const freeTimeSection = ['book', 'podcast', 'tvSeries', 'videoGame'];
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 @@ -9,6 +9,7 @@ import school from '../src/schemas/school';
import shortText from '../src/schemas/shortText';
import skill from '../src/schemas/skill';
import skillIcon from '../src/schemas/skillIcon';
import tvSeries from '../src/schemas/tvSeries';
import videoGame from '../src/schemas/videoGame';

export const schema: { types: SchemaTypeDefinition[] } = {
Expand All @@ -22,6 +23,7 @@ export const schema: { types: SchemaTypeDefinition[] } = {
shortText,
skill,
skillIcon,
tvSeries,
videoGame,
],
};
10 changes: 9 additions & 1 deletion src/app/(public)/about/free-time/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import * as React from 'react';

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

import { booksQuery } from '@/queries/books';
import { podcastsQuery } from '@/queries/podcasts';
import { tvSeriesQuery } from '@/queries/tv-series';
import { videoGamesQuery } from '@/queries/video-games';

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

import { Book } from '@/types/Book';
import { Podcast } from '@/types/Podcast';
import { TvShow } from '@/types/TvSeries';
import { VideoGame } from '@/types/VideoGame';

export const metadata = {
Expand All @@ -24,17 +27,20 @@ const getData = async () => {

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

const tvSeries: TvShow[] = await sanityClient.fetch(tvSeriesQuery);

const videoGames: VideoGame[] = await sanityClient.fetch(videoGamesQuery);

return {
books,
podcasts,
tvSeries,
videoGames,
};
};

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

return (
<main className='min-h-main'>
Expand All @@ -56,6 +62,8 @@ const AboutFreeTimePage = async () => {
<Podcasts podcasts={podcasts} />

<VideoGames videoGames={videoGames} />

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

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

import { TvShow } from '@/types/TvSeries';

export interface TvSeriesProps {
tvSeries: TvShow[];
}

const TvSeries = ({ tvSeries }: TvSeriesProps) => {
return (
<div className='mb-6'>
<div className='m-2 flex'>
<h2>Favourite TV Series</h2>
</div>

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

export default TvSeries;
5 changes: 5 additions & 0 deletions src/pages/api/hobbies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@ import { NextApiRequest, NextApiResponse } from 'next';

import { booksQuery } from '@/queries/books';
import { podcastsQuery } from '@/queries/podcasts';
import { tvSeriesQuery } from '@/queries/tv-series';
import { videoGamesQuery } from '@/queries/video-games';

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

import { Book } from '@/types/Book';
import { Podcast } from '@/types/Podcast';
import { TvShow } from '@/types/TvSeries';
import { VideoGame } from '@/types/VideoGame';

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

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

const tvSeries: TvShow[] = await sanityClient.fetch(tvSeriesQuery);

const videoGames: VideoGame[] = await sanityClient.fetch(videoGamesQuery);

res.status(200).json({
books,
podcasts,
tvSeries,
videoGames,
});
};
Expand Down
10 changes: 10 additions & 0 deletions src/queries/tv-series.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { groq } from 'next-sanity';

export const tvSeriesQuery = groq`
*[_type == "tvSeries"] | order(year desc) {
_id,
title,
year,
"poster": poster.asset->url,
mediaLink,
}`;
36 changes: 36 additions & 0 deletions src/schemas/tvSeries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { defineField, defineType } from 'sanity';

export default defineType({
name: 'tvSeries',
title: 'TV Series',
type: 'document',
fields: [
defineField({
name: 'title',
title: 'Title',
type: 'string',
}),
defineField({
name: 'year',
title: 'Year',
type: 'number',
}),
defineField({
name: 'poster',
title: 'Poster',
type: 'image',
}),
defineField({
name: 'mediaLink',
title: 'Media Link',
type: 'string',
}),
],
orderings: [
{
title: 'Year',
name: 'yearDesc',
by: [{ field: 'year', direction: 'desc' }],
},
],
});
7 changes: 7 additions & 0 deletions src/types/TvSeries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface TvShow {
_id: string;
title: string;
year: number;
poster: string;
mediaLink: string;
}

0 comments on commit 5b716f6

Please sign in to comment.