Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
CaliCastle committed Mar 13, 2024
1 parent bb2f151 commit ff9d377
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
10 changes: 5 additions & 5 deletions app/(main)/Headline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ function Developer() {

function Designer() {
return (
<span className="group relative rounded-2xl bg-black/5 p-1 dark:bg-white/5">
<span className="group relative bg-black/5 p-1 dark:bg-white/5">
<span className="pointer-events-none absolute inset-0 border border-lime-700/90 opacity-70 group-hover:border-dashed group-hover:opacity-100 dark:border-lime-400/90">
<span className="absolute -left-0.5 -top-0.5 h-1.5 w-1.5 border border-lime-700 bg-zinc-50 dark:border-lime-400" />
<span className="absolute -bottom-0.5 -right-0.5 h-1.5 w-1.5 border border-lime-700 bg-zinc-50 dark:border-lime-400" />
<span className="absolute -bottom-0.5 -left-0.5 h-1.5 w-1.5 border border-lime-700 bg-zinc-50 dark:border-lime-400" />
<span className="absolute -right-0.5 -top-0.5 h-1.5 w-1.5 border border-lime-700 bg-zinc-50 dark:border-lime-400" />
<span className="absolute -left-[3.5px] -top-[3.5px] size-1.5 border border-lime-700 bg-zinc-50 dark:border-lime-400" />
<span className="absolute -bottom-[3.5px] -right-[3.5px] size-1.5 border border-lime-700 bg-zinc-50 dark:border-lime-400" />
<span className="absolute -bottom-[3.5px] -left-[3.5px] size-1.5 border border-lime-700 bg-zinc-50 dark:border-lime-400" />
<span className="absolute -right-[3.5px] -top-[3.5px] size-1.5 border border-lime-700 bg-zinc-50 dark:border-lime-400" />
</span>
设计师
</span>
Expand Down
15 changes: 8 additions & 7 deletions app/admin/comments/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { db } from '~/db'
import { comments } from '~/db/schema'
import { url } from '~/lib'
import { truncate } from '~/lib/string'
import { clientFetch } from '~/sanity/lib/client'
import { client } from '~/sanity/lib/client'

export default async function AdminCommentsPage() {
const {
Expand All @@ -42,12 +42,13 @@ export default async function AdminCommentsPage() {
.limit(15)
// get unique post IDs from comments
const postIds = [...new Set(latestComments.map((comment) => comment.postId))]
const posts: { _id: string; title: string; slug: string }[] =
await clientFetch(
`*[_type == "post" && (_id in [${postIds
.map((v) => `"${v}"`)
.join(',')}])]{ _id, title, "slug":slug.current }`
)
const posts = await client.fetch<
{ _id: string; title: string; slug: string }[]
>(
`*[_type == "post" && (_id in [${postIds
.map((v) => `"${v}"`)
.join(',')}])]{ _id, title, "slug":slug.current }`
)
// define a map with key of post IDs to posts
const postMap = new Map(posts.map((post) => [post._id, post]))

Expand Down
6 changes: 1 addition & 5 deletions sanity/lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createClient } from 'next-sanity'
import { cache } from 'react'

import { apiVersion, dataset, projectId, useCdn } from '../env'

Expand All @@ -8,8 +7,5 @@ export const client = createClient({
dataset,
projectId,
useCdn,
perspective: 'published',
// perspective: 'published',
})

// Wrap the cache function in a way that reuses the TypeScript definitions
export const clientFetch = cache(client.fetch.bind(client))
44 changes: 23 additions & 21 deletions sanity/queries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { groq } from 'next-sanity'

import { getDate } from '~/lib/date'
import { clientFetch } from '~/sanity/lib/client'
import { client } from '~/sanity/lib/client'
import { type Post, type PostDetail } from '~/sanity/schemas/post'
import { type Project } from '~/sanity/schemas/project'

Expand All @@ -12,8 +12,8 @@ export const getAllLatestBlogPostSlugsQuery = () =>
&& defined(slug.current)] | order(publishedAt desc).slug.current
`

export const getAllLatestBlogPostSlugs = (): Promise<string[]> => {
return clientFetch(getAllLatestBlogPostSlugsQuery())
export const getAllLatestBlogPostSlugs = () => {
return client.fetch<string[]>(getAllLatestBlogPostSlugsQuery())
}

type GetBlogPostsOptions = {
Expand Down Expand Up @@ -47,9 +47,8 @@ export const getLatestBlogPostsQuery = ({
}
}
}`
export const getLatestBlogPosts = (
options: GetBlogPostsOptions
): Promise<Post[] | null> => clientFetch(getLatestBlogPostsQuery(options))
export const getLatestBlogPosts = (options: GetBlogPostsOptions) =>
client.fetch<Post[] | null>(getLatestBlogPostsQuery(options))

export const getBlogPostQuery = groq`
*[_type == "post" && slug.current == $slug && !(_id in path("drafts.**"))][0] {
Expand Down Expand Up @@ -95,8 +94,10 @@ export const getBlogPostQuery = groq`
},
}
}`
export const getBlogPost = (slug: string): Promise<PostDetail | undefined> =>
clientFetch(getBlogPostQuery, { slug })
export const getBlogPost = (slug: string) =>
client.fetch<PostDetail | undefined, { slug: string }>(getBlogPostQuery, {
slug,
})

export const getSettingsQuery = () =>
groq`
Expand All @@ -117,16 +118,17 @@ export const getSettingsQuery = () =>
"logo": logo.asset->url
}
}`
export const getSettings = (): Promise<{
projects: Project[] | null
heroPhotos?: string[] | null
resume?:
| {
company: string
title: string
logo: string
start: string
end?: string
}[]
| null
}> => clientFetch(getSettingsQuery())
export const getSettings = () =>
client.fetch<{
projects: Project[] | null
heroPhotos?: string[] | null
resume?:
| {
company: string
title: string
logo: string
start: string
end?: string
}[]
| null
}>(getSettingsQuery())

0 comments on commit ff9d377

Please sign in to comment.