Skip to content

Commit

Permalink
Merge branch 'v3' into update-language-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
christinaroise committed Sep 23, 2024
2 parents 96d5e90 + f3b6e47 commit 3c7e498
Show file tree
Hide file tree
Showing 120 changed files with 1,876 additions and 2,380 deletions.
1 change: 0 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = {
},
},
rules: {
"@typescript-eslint/no-explicit-any": "off", // TODO
"unused-imports/no-unused-imports": "error",
"import/no-named-as-default": "off",
"import/no-unresolved": "error",
Expand Down
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ updates:
target-branch: "v3"
schedule:
interval: "daily"
groups:
storybook:
patterns:
- "@storybook/*"
- "storybook"
13 changes: 7 additions & 6 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from "react";
import type { Preview } from "@storybook/react";
import { Darker_Grotesque, Figtree } from "next/font/google";
import { Figtree } from "next/font/google";
import "../src/styles/global.css";
import localFont from "next/font/local";

const darkerGrotesque = Darker_Grotesque({
subsets: ["latin"],
variable: "--font-darkerGrotesque",
const fontRecoleta = localFont({
src: "../../public/recoleta.otf",
variable: "--font-recoleta",
});

const figtree = Figtree({
const fontFigtree = Figtree({
subsets: ["latin"],
weight: "400",
variable: "--font-figtree",
Expand Down Expand Up @@ -41,7 +42,7 @@ const preview: Preview = {
}

return (
<div className={`${figtree.variable} ${darkerGrotesque.variable}`}>
<div className={`${fontFigtree.variable} ${fontRecoleta.variable}`}>
<Story />
</div>
);
Expand Down
52 changes: 28 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,41 +147,45 @@ When building custom components in Sanity Studio that need to fetch data, it's i

**Implementation Example:**

```typescript
```tsx
import React, { useEffect, useState } from "react";
import { fetchWithToken } from "studio/lib/fetchWithToken";

const MyCustomComponent: React.FC = () => {
const [data, setData] = useState<any>(null);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
const fetchData = async () => {
try {
const query = '*[_type == "myType"]'; // Replace with your GROQ query
const result = await fetchWithToken<any>(query);
setData(result);
} catch (err) {
console.error("Error fetching data:", err);
setError(err.message);
}
};

fetchData();
}, []);

if (error) {
return <div>Error: {error}</div>;
}

return <div>{JSON.stringify(data)}</div>; // Render your component's UI
const [data, setData] = useState<any>(null);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
const fetchData = async () => {
try {
const query = '*[_type == "myType"]'; // Replace with your GROQ query
const result = await fetchWithToken<any>(query);
setData(result);
} catch (err) {
console.error("Error fetching data:", err);
setError(err.message);
}
};

fetchData();
}, []);

if (error) {
return <div>Error: {error}</div>;
}

return <div>{JSON.stringify(data)}</div>; // Render your component's UI
};

export default MyCustomComponent;
```

By using fetchWithToken, you ensure that all data fetching happens securely, with the server-side API route handling the sensitive token.

### Steganography in Presentation

To enable preview functionality in the Presentation view, Sanity applies [steganography](https://www.sanity.io/docs/stega) to the string data. This manipulates the data to include invisible HTML entities to store various metadata. If the strings are used in business logic, that logic will likely break in the Presentation view. To fix this, Sanity provides the `stegaClean` utility to remove this extra metadata. An example of this in action can be found in [CompensationsPreview.tsx](src/compensations/CompensationsPreview.tsx), where JSON parsing of salary data fails without stega cleaning.

### OpenGraph image customization

As part of providing the basic metadata for the [OpenGraph Protocol](https://ogp.me), a fallback image is generated if no other is specified. Fonts and background can be customized as shown below.
Expand Down
Loading

0 comments on commit 3c7e498

Please sign in to comment.