Skip to content

Commit b08a039

Browse files
committed
Fix image rendering
1 parent 7f2ffec commit b08a039

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1.1",
2+
"version": "0.1.3",
33
"license": "MIT",
44
"main": "dist/index.js",
55
"typings": "dist/index.d.ts",
@@ -31,6 +31,7 @@
3131
"pre-commit": "tsdx lint"
3232
}
3333
},
34+
"types": "./dist/types.d.ts",
3435
"prettier": {},
3536
"bugs": {
3637
"url": "https://github.com/splitbee/react-notion/issues"

src/components/asset.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import * as React from "react";
22
import { CSSProperties } from "react";
3-
import { BlockType } from "types";
3+
import { BlockType, ContentValueType } from "../types";
44

5-
const Asset: React.FC<{ block: BlockType }> = ({ block }) => {
6-
const { value } = block;
5+
const types = ["video", "image", "embed"];
76

8-
if (block.value.type === "embed") {
7+
const Asset: React.FC<{ block: BlockType }> = ({ block }) => {
8+
const value = block.value as ContentValueType;
9+
const type = block.value.type;
10+
if (types.includes(type)) {
911
const { id } = value;
10-
const format = block.value.format;
12+
const format = (block.value as any).format;
1113
const {
1214
block_width,
1315
block_height,
1416
display_source,
1517
block_aspect_ratio
1618
} = format;
1719

18-
const isImage = value.type === "image";
20+
const isImage = type === "image";
1921
const Comp = isImage ? "img" : "video";
2022

2123
const useWrapper = block_aspect_ratio && !block_height;
@@ -46,7 +48,7 @@ const Asset: React.FC<{ block: BlockType }> = ({ block }) => {
4648
<Comp
4749
key={!useWrapper ? id : undefined}
4850
src={`https://notion.so/image/${encodeURIComponent(
49-
block.value.properties.source[0][0]
51+
value.properties.source[0][0]
5052
)}`}
5153
controls={!isImage}
5254
alt={`An ${isImage ? "image" : "video"} from Splitbee`}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ export type BlockValueType =
197197
| ColumnListValueType
198198
| ColumnValueType
199199
| QuoteValueType
200-
| ImageValueType
201200
| CodeValueType
201+
| ImageValueType
202202
| VideoValueType
203203
| EmbedValueType;
204204

0 commit comments

Comments
 (0)