Skip to content

Commit 7dde249

Browse files
authored
Fix studio and update components (#938)
1 parent 8ac04e3 commit 7dde249

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+999
-951
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/lib/sanity/types.ts

.zed/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Folder-specific settings
2+
//
3+
// For a full list of overridable settings, and general information on folder-specific settings,
4+
// see the documentation: https://zed.dev/docs/configuring-zed#settings-files
5+
{}

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
"@sanity/asset-utils": "^2.2.1",
2424
"@sanity/client": "^6.28.0",
2525
"@sanity/image-url": "^1.1.0",
26-
"@sanity/overlays": "^2.3.59",
2726
"@sanity/preview-url-secret": "^2.1.4",
2827
"@sanity/react-loader": "1.10.45",
2928
"@sanity/types": "^3.75.1",
30-
"@sanity/ui": "^2.13.4",
29+
"@sanity/ui": "^2.15.2",
3130
"@sanity/vision": "^3.75.1",
3231
"@vercel/analytics": "^1.5.0",
3332
"clsx": "^2.1.1",
@@ -43,8 +42,7 @@
4342
"react-icons": "^5.4.0",
4443
"react-is": "^19.0.0",
4544
"react-youtube": "^10.1.0",
46-
"rxjs": "^7.8.1",
47-
"sanity": "^3.75.1",
45+
"sanity": "^3.78.0",
4846
"slugify": "^1.6.6",
4947
"sonner": "^1.7.4",
5048
"styled-components": "^6.1.15",

pnpm-lock.yaml

Lines changed: 515 additions & 358 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Setup following environment variables (as plain text variables)
1313

1414
`NEXT_PUBLIC_SANITY_PROJECT_ID` with value for your prefered dataset
1515
`NEXT_PUBLIC_SANITY_DATASET` with your sanity project id
16+
`SANITY_API_READ_TOKEN` with a read token
1617

1718
### Setup for local development
1819

@@ -22,6 +23,7 @@ Create `.env` file in root path with the environment variables
2223
# For Next Locally
2324
NEXT_PUBLIC_SANITY_PROJECT_ID = "abcd1245"
2425
NEXT_PUBLIC_SANITY_DATASET = "production"
26+
SANITY_API_READ_TOKEN = "abc12345"
2527
```
2628

2729
### Development
@@ -39,8 +41,8 @@ Add http://localhost:3000 in sanity settings -> api - CORS Origins
3941

4042
### Things to know
4143

42-
* Frontend startpage is fetched with slug `frontpage`
43-
* Posts list is fetched with the slug `posts`
44+
- Frontend startpage is fetched with slug `frontpage`
45+
- Posts list is fetched with the slug `posts`
4446

4547
### Tech Stack
4648

sanity.config.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import {defineConfig} from "sanity";
2-
import {deskTool} from "sanity/desk";
3-
42
import {visionTool} from "@sanity/vision";
5-
import {singletonPlugin} from "./src/studio/plugins/singletonPlugin";
6-
import {presentationTool} from "sanity/presentation";
73
import {schemasTypes} from "./src/studio/schemas";
8-
import {structure} from "./src/studio/structure";
9-
import {locate} from "./src/studio/plugins/locate";
4+
import {structure} from "./src/studio/plugins/structure";
5+
import {presentation} from "./src/studio/plugins/presentation";
6+
import {singletonPlugin} from "./src/studio/plugins/singleton";
107

118
export default defineConfig({
129
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID as string,
@@ -16,20 +13,5 @@ export default defineConfig({
1613
schema: {
1714
types: schemasTypes,
1815
},
19-
plugins: [
20-
deskTool({
21-
structure,
22-
}),
23-
presentationTool({
24-
previewUrl: {
25-
origin: process.env.SANITY_STUDIO_PREVIEW_ORIGIN,
26-
preview: "/",
27-
previewMode: {
28-
enable: "/api/draft-mode/enable",
29-
},
30-
},
31-
}),
32-
singletonPlugin({types: ["siteSettings"]}),
33-
visionTool(),
34-
],
16+
plugins: [structure, presentation, singletonPlugin({types: ["siteSettings"]}), visionTool()],
3517
});

schema.json

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -362,47 +362,6 @@
362362
}
363363
}
364364
},
365-
{
366-
"name": "spacer",
367-
"type": "type",
368-
"value": {
369-
"type": "object",
370-
"attributes": {
371-
"_type": {
372-
"type": "objectAttribute",
373-
"value": {
374-
"type": "string",
375-
"value": "spacer"
376-
}
377-
},
378-
"size": {
379-
"type": "objectAttribute",
380-
"value": {
381-
"type": "union",
382-
"of": [
383-
{
384-
"type": "string",
385-
"value": "small"
386-
},
387-
{
388-
"type": "string",
389-
"value": "medium"
390-
},
391-
{
392-
"type": "string",
393-
"value": "large"
394-
},
395-
{
396-
"type": "string",
397-
"value": "xlarge"
398-
}
399-
]
400-
},
401-
"optional": true
402-
}
403-
}
404-
}
405-
},
406365
{
407366
"name": "blockContent",
408367
"type": "type",
@@ -1487,21 +1446,6 @@
14871446
"name": "blockContent"
14881447
}
14891448
},
1490-
{
1491-
"type": "object",
1492-
"attributes": {
1493-
"_key": {
1494-
"type": "objectAttribute",
1495-
"value": {
1496-
"type": "string"
1497-
}
1498-
}
1499-
},
1500-
"rest": {
1501-
"type": "inline",
1502-
"name": "spacer"
1503-
}
1504-
},
15051449
{
15061450
"type": "object",
15071451
"attributes": {
@@ -1855,21 +1799,6 @@
18551799
"name": "blockContent"
18561800
}
18571801
},
1858-
{
1859-
"type": "object",
1860-
"attributes": {
1861-
"_key": {
1862-
"type": "objectAttribute",
1863-
"value": {
1864-
"type": "string"
1865-
}
1866-
}
1867-
},
1868-
"rest": {
1869-
"type": "inline",
1870-
"name": "spacer"
1871-
}
1872-
},
18731802
{
18741803
"type": "object",
18751804
"attributes": {

src/app/(blog)/(category)/[slug]/page.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {Metadata} from "next";
22
import {allPagesSlug, pageQuery} from "~/lib/sanity/queries";
33
import {sanityFetch} from "~/lib/sanity/live";
44
import {urlForOpenGraphImage} from "~/lib/sanity/utils";
5-
import {RenderSection} from "~/components/sections";
5+
import {RenderSection, Sections} from "~/components/sections";
66

77
export const generateStaticParams = async () => {
88
const {data} = await sanityFetch({query: allPagesSlug, perspective: "published", stega: false});
@@ -43,13 +43,14 @@ const Page = async ({params}: {params: Promise<{slug: string}>}) => {
4343

4444
return (
4545
<>
46-
{data?.content?.map((section) => {
47-
if (!section || Object.keys(section).length === 0) {
48-
return null;
49-
}
50-
51-
return <RenderSection key={section._key} section={section} />;
52-
})}
46+
{data?.content
47+
?.filter(
48+
(section): section is Sections =>
49+
section !== null && typeof section === "object" && "_key" in section && Object.keys(section).length > 0,
50+
)
51+
.map((section) => {
52+
return <RenderSection key={section._key} section={section} />;
53+
})}
5354
</>
5455
);
5556
};

src/app/(blog)/page.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type {Metadata} from "next";
2-
import {pageWithPostsQuery} from "~/lib/sanity/queries";
2+
import {pageQuery, pageWithPostsQuery, postsQuery} from "~/lib/sanity/queries";
33
import {sanityFetch} from "~/lib/sanity/live";
44
import {Heading} from "~/components/ui";
55
import {PostList} from "~/components/shared";
6-
import {RenderSection} from "~/components/sections";
6+
import {RenderSection, type Sections} from "~/components/sections";
77

88
import {urlForOpenGraphImage} from "~/lib/sanity/utils";
99

@@ -36,19 +36,22 @@ export const generateMetadata = async (): Promise<Metadata> => {
3636

3737
const IndexRoute = async () => {
3838
const params = {slug: "frontpage", limit: 2};
39-
const {data} = await sanityFetch({query: pageWithPostsQuery, params: params});
40-
41-
const {page, posts} = data ?? {};
39+
const [{data: page}, {data: posts}] = await await Promise.all([
40+
sanityFetch({query: pageQuery, params: params}),
41+
sanityFetch({query: postsQuery, params}),
42+
]);
4243

4344
return (
4445
<>
45-
{page?.content?.map((section) => {
46-
if (!section || Object.keys(section).length === 0) {
47-
return null;
48-
}
46+
{page?.content
47+
?.filter(
48+
(section): section is Sections =>
49+
section !== null && typeof section === "object" && "_key" in section && Object.keys(section).length > 0,
50+
)
51+
.map((section) => {
52+
return <RenderSection key={section._key} section={section} />;
53+
})}
4954

50-
return <RenderSection key={section._key} section={section} />;
51-
})}
5255
<Heading level="h2" weight="semibold" className="py-8">
5356
Recent articles
5457
</Heading>

src/app/(blog)/posts/[slug]/page.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {urlForOpenGraphImage} from "~/lib/sanity/utils";
33
import {sanityFetch} from "~/lib/sanity/live";
44
import {allPostSlugQuery, postQuery} from "~/lib/sanity/queries";
55
import {Date, Heading, Tag} from "~/components/ui";
6-
import {RenderSection} from "~/components/sections";
6+
import {RenderSection, Sections} from "~/components/sections";
77

88
export const generateStaticParams = async () => {
99
const {data} = await sanityFetch({query: allPostSlugQuery, perspective: "published", stega: false});
@@ -54,13 +54,14 @@ const Page = async ({params}: {params: Promise<{slug: string}>}) => {
5454
<div className="flex flex-row">{keywords}</div>
5555
</div>
5656
</div>
57-
{data?.content?.map((section) => {
58-
if (!section || Object.keys(section).length === 0) {
59-
return null;
60-
}
61-
62-
return <RenderSection key={section._key} section={section} />;
63-
})}
57+
{data?.content
58+
?.filter(
59+
(section): section is Sections =>
60+
section !== null && typeof section === "object" && "_key" in section && Object.keys(section).length > 0,
61+
)
62+
.map((section) => {
63+
return <RenderSection key={section._key} section={section} />;
64+
})}
6465
</article>
6566
);
6667
};

0 commit comments

Comments
 (0)