Skip to content

Commit

Permalink
feat: add team members functionality schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
0-vortex committed Nov 27, 2023
1 parent ef81bc9 commit 9aa7fbd
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 17 deletions.
2 changes: 1 addition & 1 deletion components/pages/home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function HomePage({ data, encodeDataAttribute }: HomePageProps) {
)}

{showcaseProjects && showcaseProjects.length > 0 && (
<div className="w-full grid grid-cols-2 flex-wrap gap-6 p-6">
<div className="w-full grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 flex-wrap gap-6 p-6">
{showcaseProjects.map((project, key) => {
const href = resolveHref(project._type, project.slug)
if (!href) {
Expand Down
38 changes: 32 additions & 6 deletions components/pages/home/PostListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { PortableTextBlock } from '@portabletext/types'
import clsx from 'clsx'

import { CustomPortableText } from '@/components/shared/CustomPortableText'
import ImageBox from '@/components/shared/ImageBox'
import type { ShowcasePost } from '@/types'

interface PostProps {
Expand All @@ -11,26 +12,51 @@ interface PostProps {

export function PostListItem(props: PostProps) {
const { post, odd } = props
const formattedDate = new Date(post.publishedAt as string).toLocaleDateString('en-US')
const daysAgo = Math.floor((new Date().getTime() - new Date(post.publishedAt as string).getTime()) / (1000 * 3600 * 24))

return (
<div
className={clsx([
'border-b p-6',
'border-b p-12 flex flex-row gap-4',
'border-slate-500 hover:bg-white',
'dark:border-black dark:hover:bg-black',
odd && ''
])}
>
<h2 className={clsx([
'text-xl font-extrabold tracking-tight p-5',
])}>{post.title} {post.publishedAt?.toString()}</h2>
<div className='basis-1/4'>
<ImageBox
image={post.coverImage}
alt={`Cover image from ${post.title}`}
classesWrapper='relative aspect-[16/9]'
/>
</div>

<div className={clsx([
'p-5 text-xl font-sans',
'p-5 basis-1/2'
])}>
<CustomPortableText value={post.body?.slice(0,3) as PortableTextBlock[]} />
<p>{`${formattedDate} (${daysAgo} days ago)`}</p>

<h2 className={clsx([
'text-xl font-extrabold tracking-tight'
])}>{post.title}</h2>

<div className={clsx([
'flex flex-row gap-x-2 font-mono',
])}>
{post.categories?.map((tag, key) => (
<div className='text-md font-medium lowercase md:text-lg' key={key}>
#{tag}
</div>
))}
</div>
</div>

<div className={clsx([
'p-5 text-xl font-sans',
])}>
<CustomPortableText value={post.overview as PortableTextBlock[]} />
</div>
</div>
)
}
2 changes: 1 addition & 1 deletion components/pages/home/ProjectListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function ProjectListItem(props: ProjectProps) {
</div>

<div className={clsx([
'border-t p-5 text-xl font-sans min-h-[97px]',
'border-t p-5 text-lg font-sans min-h-[125px]',
'border-slate-500',
'dark:border-black',
])}>
Expand Down
4 changes: 3 additions & 1 deletion sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { locate } from '@/sanity/plugins/locate'
import { pageStructure, singletonPlugin } from '@/sanity/plugins/settings'
import page from '@/sanity/schemas/documents/page'
import post from '@/sanity/schemas/documents/post'
import member from '@/sanity/schemas/documents/member'
import project from '@/sanity/schemas/documents/project'
import duration from '@/sanity/schemas/objects/duration'
import milestone from '@/sanity/schemas/objects/milestone'
Expand All @@ -38,11 +39,12 @@ export default defineConfig({
home,
settings,
// Documents
duration,
page,
project,
post,
member,
// Objects
duration,
milestone,
timeline,
socialLink,
Expand Down
3 changes: 3 additions & 0 deletions sanity/lib/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ export const homePageQuery = groq`
showcasePosts[]->{
_type,
body,
overview,
coverImage,
"slug": slug.current,
publishedAt,
categories,
title,
},
title,
Expand Down
17 changes: 17 additions & 0 deletions sanity/plugins/locate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const locate: DocumentLocationResolver = (params, context) => {
if (
params.type === 'home' ||
params.type === 'page' ||
params.type === 'post' ||
params.type === 'project'
) {
const doc$ = context.documentStore.listenQuery(
Expand Down Expand Up @@ -87,6 +88,22 @@ export const locate: DocumentLocationResolver = (params, context) => {
? 'This document is used on all pages as it is in the top menu'
: undefined,
} satisfies DocumentLocationsState
case 'post':
return {
locations: docs
?.map((doc) => {
const href = resolveHref(doc._type, doc?.slug?.current)
return {
title: doc?.title || 'Untitled',
href: href!,
}
})
.filter((doc) => doc.href !== undefined),
tone: isReferencedBySettings ? 'caution' : undefined,
message: isReferencedBySettings
? 'This document is used on all pages as it is in the top menu'
: undefined,
} satisfies DocumentLocationsState
default:
return {
message: 'Unable to map document type to locations',
Expand Down
95 changes: 95 additions & 0 deletions sanity/schemas/documents/member.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { RocketIcon } from '@sanity/icons'
import { defineArrayMember, defineField } from 'sanity'

export default {
name: 'member',
title: 'Member',
type: 'document',
icon: RocketIcon,
fields: [
defineField({
name: 'title',
description: 'This field is the name of the team member.',
title: 'Title',
type: 'string',
validation: (rule) => rule.required(),
}),
defineField({
name: 'slug',
title: 'Slug',
type: 'slug',
options: {
source: 'title',
maxLength: 96,
isUnique: (value, context) => context.defaultIsUnique(value, context),
},
validation: (rule) => rule.required(),
}),
defineField({
name: 'shortName',
description: 'This field is the displayed short name of the team member.',
title: 'Displayed name',
type: 'string',
validation: (rule) => rule.required(),
}),
defineField({
name: 'role',
description: 'This field is the role of the team member.',
title: 'Role',
type: 'string',
validation: (rule) => rule.required(),
}),
defineField({
name: 'overview',
description:
'Used both for the <meta> description tag for SEO, and team member header.',
title: 'Overview',
type: 'array',
of: [
// Paragraphs
defineArrayMember({
lists: [],
marks: {
annotations: [],
decorators: [
{
title: 'Italic',
value: 'em',
},
{
title: 'Strong',
value: 'strong',
},
],
},
styles: [],
type: 'block',
}),
],
validation: (rule) => rule.max(155).required(),
}),
defineField({
name: 'coverImage',
title: 'Cover Image',
description:
'This image will be used as the image for the team member.',
type: 'image',
options: {
hotspot: true,
},
validation: (rule) => rule.required(),
}),
],
preview: {
select: {
title: 'title',
role: 'role',
},
prepare({ title, role }) {
return {
subtitle: `Role: ${role}`,
title,
}
},
},
}
60 changes: 54 additions & 6 deletions sanity/schemas/documents/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,60 @@ export default defineType({
icon: ComposeIcon,
fields: [
defineField({
type: 'string',
name: 'title',
description: 'This field is the title of your post.',
title: 'Title',
type: 'string',
validation: (rule) => rule.required(),
}),
defineField({
type: 'slug',
name: 'slug',
title: 'Slug',
type: 'slug',
options: {
source: 'title',
maxLength: 96,
isUnique: (value, context) => context.defaultIsUnique(value, context),
},
validation: (rule) => rule.required(),
}),
defineField({
name: 'overview',
description:
'Used both for the <meta> description tag for SEO, and project subheader.',
title: 'Overview',
type: 'array',
of: [
// Paragraphs
defineArrayMember({
lists: [],
marks: {
annotations: [],
decorators: [
{
title: 'Italic',
value: 'em',
},
{
title: 'Strong',
value: 'strong',
},
],
},
styles: [],
type: 'block',
}),
],
validation: (rule) => rule.max(155).required(),
}),
defineField({
name: 'coverImage',
title: 'Cover Image',
description:
'This image will be used as the cover image for the project. If you choose to add it to the show case projects, this is the image displayed in the list within the homepage.',
type: 'image',
options: {
hotspot: true,
},
validation: (rule) => rule.required(),
}),
Expand All @@ -28,6 +71,15 @@ export default defineType({
title: 'Published at',
validation: (rule) => rule.required(),
}),
defineField({
name: 'categories',
title: 'Categories',
type: 'array',
of: [{ type: 'string' }],
options: {
layout: 'tags',
},
}),
defineField({
type: 'array',
name: 'body',
Expand Down Expand Up @@ -57,10 +109,6 @@ export default defineType({
styles: [],
}),
// Custom blocks
defineArrayMember({
name: 'timeline',
type: 'timeline',
}),
defineField({
type: 'image',
icon: ImageIcon,
Expand Down
16 changes: 14 additions & 2 deletions sanity/schemas/documents/project.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DocumentIcon, ImageIcon } from '@sanity/icons'
import { PresentationIcon, ImageIcon } from '@sanity/icons'
import { defineArrayMember, defineField, defineType } from 'sanity'

export default defineType({
name: 'project',
title: 'Project',
type: 'document',
icon: DocumentIcon,
icon: PresentationIcon,
// Uncomment below to have edits publish automatically as you type
// liveEdit: true,
fields: [
Expand Down Expand Up @@ -153,4 +153,16 @@ export default defineType({
],
}),
],
preview: {
select: {
title: 'title',
client: 'client',
},
prepare({ title, client }) {
return {
subtitle: `Project for ${client}`,
title,
}
},
},
})
3 changes: 3 additions & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ export interface ShowcaseProject {

export interface ShowcasePost {
_type: string
coverImage?: Image
overview?: PortableTextBlock[]
body?: PortableTextBlock[]
slug?: string
publishedAt?: string
categories?: string[]
title?: string
}

Expand Down

0 comments on commit 9aa7fbd

Please sign in to comment.