Skip to content

Commit

Permalink
feat: add language 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 f2b01f9 commit 81223c5
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 2 deletions.
3 changes: 2 additions & 1 deletion sanity/schema.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { type SchemaTypeDefinition } from 'sanity';

import job from '../src/schemas/job';
import language from '../src/schemas/language';
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, school, shortText, skill, skillIcon],
types: [job, language, school, shortText, skill, skillIcon],
};
10 changes: 9 additions & 1 deletion src/app/(public)/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import Image from 'next/image';
import * as React from 'react';

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

import { jobsQuery } from '@/queries/jobs';
import { languageQuery } from '@/queries/languages';
import { schoolsQuery } from '@/queries/schools';
import { shortTextQuery } from '@/queries/short-texts';
import { skillQuery } from '@/queries/skills';

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

import { Job } from '@/types/Job';
import { Language } from '@/types/Language';
import { School } from '@/types/School';
import { ShortText } from '@/types/ShortText';
import { Skill } from '@/types/Skill';
Expand All @@ -26,6 +29,8 @@ export const metadata = {
const getData = async () => {
const jobs: Job[] = await sanityClient.fetch(jobsQuery);

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

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

const skills: Skill[] = await sanityClient.fetch(skillQuery);
Expand All @@ -34,14 +39,15 @@ const getData = async () => {

return {
jobs,
languages,
schools,
shortTexts,
skills,
};
};

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

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

<Education schools={schools} />

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

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

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

export interface LanguageProps {
languages: Language[];
}

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

<div className='flex flex-col md:w-full md:flex-row md:justify-between'>
{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'
>
<Image
src={language.flagUrl}
alt={language.name}
width={40}
height={40}
/>

<span className='ms-4 font-semibold'>{language.level}</span>
</div>
))}
</div>
</div>
);
};

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

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

export default defineType({
name: 'language',
title: 'Language',
type: 'document',
fields: [
defineField({
name: 'id',
title: 'Id',
type: 'number',
}),
defineField({
name: 'name',
title: 'Name',
type: 'string',
}),
defineField({
name: 'level',
title: 'Level',
type: 'string',
}),
defineField({
name: 'flag',
title: 'Icons',
type: 'image',
}),
],
orderings: [
{
title: 'Custom Order',
name: 'custom',
by: [{ field: 'id', direction: 'asc' }],
},
],
});
6 changes: 6 additions & 0 deletions src/types/Language.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Language {
id: number;
name: string;
level: string;
flagUrl: string;
}

0 comments on commit 81223c5

Please sign in to comment.